00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include <boost/shared_array.hpp>
00017 #include "recoder.hpp"
00018
00019 using namespace boost;
00020 using namespace std;
00021
00022 const char *program_name = PACKAGE;
00023
00024 RECODE_OUTER Recoder::outer = NULL;
00025
00026 Recoder::Recoder( const std::string &_request ) throw (Error):
00027 request(NULL)
00028 {
00029 assert( outer != NULL );
00030 request = recode_new_request( outer );
00031 ERRORMACRO( request, Error, , "Error allocating recoding request." );
00032 #ifndef NDEBUG
00033 request->verbose_flag = true;
00034 #endif
00035 request->ascii_graphics = true;
00036 if ( !recode_scan_request( request, _request.c_str() ) ) {
00037 recode_delete_request( request );
00038 ERRORMACRO( false, Error, ,
00039 "Error requesting " << _request << " recoder." );
00040 };
00041 }
00042
00043 Recoder::~Recoder(void)
00044 {
00045 recode_delete_request (request);
00046 }
00047
00048 void Recoder::translate( std::istream &inputStream,
00049 std::ostream &outputStream ) const
00050 throw (Error)
00051 {
00052 streampos pos = inputStream.tellg();
00053 inputStream.seekg( 0, ios::end );
00054 int filesize = inputStream.tellg() - pos;
00055 inputStream.seekg( pos, ios::beg );
00056
00057 shared_array< char > inputData( new char[filesize] );
00058 inputStream.read( inputData.get(), filesize );
00059
00060 char *outputData = NULL;
00061 size_t
00062 outputLength = 0,
00063 outputAllocated = 0;
00064
00065 bool retVal =
00066 recode_buffer_to_buffer( request, inputData.get(), filesize,
00067 &outputData, &outputLength, &outputAllocated );
00068
00069 inputData.reset();
00070
00071 ERRORMACRO( retVal, Error, , "Error while recoding stream." );
00072 outputStream.write( outputData, outputLength );
00073
00074 if ( outputData != NULL )
00075 free( outputData );
00076 }