Main | License | Installation | FAQ | Screenshots | Contact | Links | Sf.net | Freshmeat.net | KDE-Apps.org
Requirements | Design | Modules | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

recoder.cpp

Go to the documentation of this file.
00001 /* Copyright (C) 2006 Jan Wedekind.
00002    This file is part of the recipe database application AnyMeal.
00003 
00004    AnyMeal is free software; you can redistribute it and/or modify it under
00005    the terms of the GNU GENERAL PUBLIC LICENSE as published by the Free
00006    Software Foundation; either version 3 of the License, or (at your option)
00007    any later version.
00008 
00009    AnyMeal is distributed in the hope that it will be useful, but WITHOUT ANY
00010    WARRANTY; without even the implied warranty of MERCHANTIBILITY or FITNESS
00011    FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
00012    details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program.  If not, see <http://www.gnu.org/licenses/>. */
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 }


anymeal 0.31 - recipe management software - Make the most of your food! - © Jan Wedekind Sun Dec 19 19:36:02 2010 - GNU Free Documentation License