Sleipnir
src/filei.h
00001 /*****************************************************************************
00002 * This file is provided under the Creative Commons Attribution 3.0 license.
00003 *
00004 * You are free to share, copy, distribute, transmit, or adapt this work
00005 * PROVIDED THAT you attribute the work to the authors listed below.
00006 * For more information, please see the following web page:
00007 * http://creativecommons.org/licenses/by/3.0/
00008 *
00009 * This file is a component of the Sleipnir library for functional genomics,
00010 * authored by:
00011 * Curtis Huttenhower (chuttenh@princeton.edu)
00012 * Mark Schroeder
00013 * Maria D. Chikina
00014 * Olga G. Troyanskaya (ogt@princeton.edu, primary contact)
00015 *
00016 * If you use this library, the included executable tools, or any related
00017 * code in your work, please cite the following publication:
00018 * Curtis Huttenhower, Mark Schroeder, Maria D. Chikina, and
00019 * Olga G. Troyanskaya.
00020 * "The Sleipnir library for computational functional genomics"
00021 *****************************************************************************/
00022 #ifndef FILEI_H
00023 #define FILEI_H
00024 
00025 #undef int64_t
00026 #include <stdint.h>
00027 
00028 namespace Sleipnir {
00029 
00030 class CFileImpl {
00031 protected:
00032     static const size_t c_iBufferSize   = 2097152;
00033 
00034     static void SaveString( std::ostream& ostm, const std::string& str ) {
00035         uint32_t    iLength;
00036 
00037         iLength = (uint32_t)str.length( );
00038         ostm.write( (const char*)&iLength, sizeof(iLength) );
00039         ostm.write( str.c_str( ), iLength ); }
00040 
00041     static void OpenString( std::istream& istm, std::string& str ) {
00042         uint32_t    iLength;
00043 
00044         istm.read( (char*)&iLength, sizeof(iLength) );
00045         str.resize( iLength );
00046         istm.read( &str[ 0 ], iLength ); }
00047 };
00048 
00049 }
00050 
00051 #endif // FILEI_H