X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=lib%2FcpPlugins%2FUtilities.h;fp=lib%2FcpPlugins%2FUtilities.h;h=ff033b4b62277e674a8c85cded12860f8f6e19af;hb=e5916bd329611f11ff2f31ff42e853bac21b825a;hp=b919c202adbc4f15fc38696a0161a800fdd2d82e;hpb=a99c26946ea3a858847b76368bbf312019de9c2a;p=cpPlugins.git diff --git a/lib/cpPlugins/Utilities.h b/lib/cpPlugins/Utilities.h index b919c20..ff033b4 100644 --- a/lib/cpPlugins/Utilities.h +++ b/lib/cpPlugins/Utilities.h @@ -87,26 +87,6 @@ namespace cpPlugins return( res ); } - // ----------------------------------------------------------------------- - inline bool ReadFileIntoBuffer( - std::string& buffer, const std::string& fname - ) - { - buffer = ""; - std::ifstream file_stream( fname.c_str( ) ); - if( !file_stream ) - return( false ); - file_stream.seekg( 0, std::ios::end ); - buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) ); - file_stream.seekg( 0, std::ios::beg ); - buffer.assign( - ( std::istreambuf_iterator< char >( file_stream ) ), - std::istreambuf_iterator< char >( ) - ); - file_stream.close( ); - return( true ); - } - // ----------------------------------------------------------------------- inline std::string CanonicalPath( const std::string& path ) { @@ -128,6 +108,42 @@ namespace cpPlugins return( ret ); } + // ----------------------------------------------------------------------- + inline bool WriteBufferToFile( + const std::string& buffer, const std::string& fname + ) + { + std::ofstream file_stream( + CanonicalPath( fname ).c_str( ), std::ofstream::binary + ); + if( !file_stream ) + return( false ); + file_stream.write( buffer.c_str( ), buffer.size( ) ); + return( true ); + } + + // ----------------------------------------------------------------------- + inline bool ReadFileIntoBuffer( + std::string& buffer, const std::string& fname + ) + { + buffer = ""; + std::ifstream file_stream( + CanonicalPath( fname ).c_str( ), std::ifstream::binary + ); + if( !file_stream ) + return( false ); + file_stream.seekg( 0, std::ios::end ); + buffer.reserve( ( unsigned int )( file_stream.tellg( ) ) ); + file_stream.seekg( 0, std::ios::beg ); + buffer.assign( + ( std::istreambuf_iterator< char >( file_stream ) ), + std::istreambuf_iterator< char >( ) + ); + file_stream.close( ); + return( true ); + } + } // ecapseman #endif // __CPPLUGINS__UTILITY__H__