Enumerations | |
| enum | Endianness { LITTLE, BIG } |
Functions | |
| bool | fileExists (const char *const name) |
| int | fileSize (const char *const filename) |
| void | fileLoad (const char *const filename, std::vector< unsigned char > &data) |
| int | ReadByte (FILE *fp, unsigned char &value) |
| int | ReadShort (Endianness fileByteOrdering, FILE *fp, unsigned short &value) |
| int | ReadLong (Endianness fileByteOrdering, FILE *fp, unsigned long &value) |
| int | WriteByte (FILE *fp, const unsigned char &value) |
| int | WriteShort (Endianness fileByteOrdering, FILE *fp, const unsigned short &value) |
| int | WriteLong (Endianness fileByteOrdering, FILE *fp, const unsigned long &value) |
| void | getLine (std::ifstream &f, std::string &text) |
| void | getAll (std::ifstream &f, std::string &buffer) |
| template<class typeT> int | ReadData (Endianness fileByteOrdering, FILE *fp, typeT &data) |
| template<class typeT> int | WriteData (Endianness fileByteOrdering, FILE *fp, const typeT &data) |
|
|
Definition at line 93 of file FileIO.h.
|
|
|
Definition at line 52 of file FileIO.cpp.
00053 {
00054 if (name == NULL) return false;
00055
00056 FILE* file = ::fopen( name, "r" );
00057 if (file == NULL)
00058 {
00059 return false;
00060 }
00061 else
00062 {
00063 ::fclose( file );
00064 return true;
00065 }
00066 }
|
|
|
Definition at line 68 of file FileIO.cpp.
00069 {
00070 if (filename == NULL) return 0;
00071
00072 if (!fileExists( filename ))
00073 return 0;
00074
00075 FILE* fh = fopen( filename, "rb" );
00076 assert( fh != NULL );
00077
00078 if ( fseek(fh, 0, SEEK_END) == 0 )
00079 {
00080 return ftell(fh);
00081 }
00082 else
00083 {
00084 return 0;
00085 }
00086 }
|
|
||||||||||||
|
Definition at line 88 of file FileIO.cpp.
00089 {
00090 if (filename == NULL) return;
00091
00092 if (!fileExists( filename ))
00093 return;
00094
00095 int size = fileSize( filename );
00096 data.resize( size );
00097
00098 FILE* fh = fopen( filename, "rb" );
00099 unsigned int file_length = fread( &data[0], 1, data.size(), fh );
00100 assert( file_length == data.size() );
00101 fclose( fh );
00102 }
|
|
||||||||||||
|
Definition at line 105 of file FileIO.cpp.
00106 {
00107 return ::fread( &value, 1, sizeof(unsigned char), fp );
00108 }
|
|
||||||||||||||||
|
Definition at line 112 of file FileIO.cpp.
00113 {
00114 return ReadData( fileByteOrdering, fp, value );
00115 }
|
|
||||||||||||||||
|
Definition at line 119 of file FileIO.cpp.
00120 {
00121 return ReadData( fileByteOrdering, fp, value );
00122 }
|
|
||||||||||||
|
Definition at line 125 of file FileIO.cpp.
00126 {
00127 return ::fwrite( &value, 1, sizeof(unsigned char), fp );
00128 }
|
|
||||||||||||||||
|
Definition at line 132 of file FileIO.cpp.
00133 {
00134 return WriteData( fileByteOrdering, fp, value );
00135 }
|
|
||||||||||||||||
|
Definition at line 139 of file FileIO.cpp.
00140 {
00141 return WriteData( fileByteOrdering, fp, value );
00142 }
|
|
||||||||||||
|
Definition at line 144 of file FileIO.cpp.
00145 {
00146 char buffer[2049];
00147 f.getline( buffer, 2048, '\n' );
00148 buffer[2048] = '\0';
00149 if (f.gcount() < 2048)
00150 {
00151 buffer[f.gcount()] = '\0';
00152 }
00153 text = buffer;
00154 }
|
|
||||||||||||
|
Definition at line 156 of file FileIO.cpp.
00157 {
00158 //cout<<"Reading:["<<flush;
00159 while ((f.eof() == false) && (f.fail() == 0) )
00160 //while (f.gcount() >= 2048)
00161 {
00162 //cout<<"."<<flush;
00163 char buf[2049];
00164 f.read( buf, 2048 );
00165 buf[2048] = '\0';
00166 if (f.gcount() < 2048)
00167 {
00168 buf[f.gcount()] = '\0';
00169 }
00170 buffer += buf;
00171 }
00172 //cout<<"]\n"<<flush;
00173 //cout << "Gcount == " << f.gcount() << "\n"<<flush;
00174 }
|
|
||||||||||||||||||||
|
Definition at line 106 of file FileIO.h.
00107 {
00108 int size = ::fread( &data, sizeof(typeT), 1, fp );
00109
00110 // if we're not on a little endian machine (intel is little endian) then reverse the bytes.
00111 if (fileByteOrdering == snxFileIO::LITTLE && vpr::System::isBigEndian() ||
00112 fileByteOrdering == snxFileIO::BIG && vpr::System::isLittleEndian())
00113 {
00114 snxEndian::byteReverse( data );
00115 }
00116
00117 return size;
00118 }
|
|
||||||||||||||||||||
|
Definition at line 123 of file FileIO.h.
00124 {
00125 typeT tempData = data;
00126
00127 // if we're not on a little endian machine (i.e. intel is little endian, mips is big)
00128 // then reverse the bytes.
00129 if (fileByteOrdering == LITTLE && vpr::System::isBigEndian() ||
00130 fileByteOrdering == BIG && vpr::System::isLittleEndian())
00131 {
00132 snxEndian::byteReverse( tempData );
00133 }
00134
00135 int size = ::fwrite( &tempData, 1, sizeof(typeT), fp );
00136
00137 return size;
00138 }
|
1.2.14 written by Dimitri van Heesch,
© 1997-2002