00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00023
00031
00032
00033 #ifndef _CTTL_FILEIO_H_INCLUDED_
00034 #define _CTTL_FILEIO_H_INCLUDED_
00035
00036 #include "../cttl/coreutils.h"
00037 #include <fstream>
00038
00044 namespace cttl {
00045
00047 void file2string( const CTTL_STD_STRING& filename_, CTTL_STD_STRING& str_ )
00048 {
00049
00050 std::basic_ifstream< CTTL_STD_CHAR > fs( reinterpret_cast< char const* >( filename_.c_str() ) );
00051 str_.erase();
00052 str_.reserve( fs.rdbuf()->in_avail() );
00053 CTTL_STD_CHAR ch;
00054 while( fs.get( ch ) ) {
00055 if( str_.capacity() == str_.size() )
00056 str_.reserve( str_.capacity() * 3 );
00057 str_.append( 1, ch );
00058 }
00059 }
00060
00062 CTTL_STD_STRING file2string( const CTTL_STD_STRING& filename_ )
00063 {
00064 CTTL_STD_STRING str_temp;
00065 file2string( filename_, str_temp );
00066 return str_temp;
00067 }
00068
00070 void string2file( const CTTL_STD_STRING& filename_, const CTTL_STD_STRING& str_ )
00071 {
00072
00073 std::basic_ofstream< CTTL_STD_CHAR > file;
00074 file.open( reinterpret_cast< char const* >( filename_.c_str() ), std::ios_base::trunc );
00075 file << str_;
00076 file.close();
00077 }
00078
00079 }
00080
00081
00106 #endif // _CTTL_FILEIO_H_INCLUDED_