Changeset 9415 in orxonox.OLD for branches/terrain/src/lib/util
- Timestamp:
- Jul 24, 2006, 12:59:44 PM (19 years ago)
- Location:
- branches/terrain/src/lib/util
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/terrain/src/lib/util/byte_order.h
r9414 r9415 15 15 #else 16 16 #define NATIVE_BYTEORDER BigEndian 17 #endif 17 #endif 18 18 19 19 -
branches/terrain/src/lib/util/filesys/binary_file.cc
r9414 r9415 46 46 delete chunk; 47 47 return NULL; 48 } 48 } 49 49 break; 50 50 default: … … 64 64 case 's': 65 65 chunk->chunks[currChunk] = new DataSemantics(); 66 chunk->chunks[currChunk]->isTerminal = true; 66 chunk->chunks[currChunk]->isTerminal = true; 67 67 chunk->chunks[currChunk]->type = bytesize( *curr ); 68 chunk->chunks[currChunk]->totalSize = bytesize( *curr ); 68 chunk->chunks[currChunk]->totalSize = bytesize( *curr ); 69 69 currChunk++; 70 70 break; … … 89 89 *cp = '\0'; 90 90 chunk->chunks[currChunk] = compileSemantics( tmp ); 91 currChunk++; 91 currChunk++; 92 92 break; 93 93 case ')': … … 111 111 delete[] tmp; delete chunk; 112 112 return NULL; 113 } 113 } 114 114 if ( currChunk ) { 115 115 chunk->chunks[currChunk-1]->quantifier = quantifier; 116 chunk->chunks[currChunk-1]->totalSize*= quantifier; 117 } 116 chunk->chunks[currChunk-1]->totalSize*= quantifier; 117 } 118 118 else { 119 119 printf( "Syntax error: Quantifier without a preceding type\n" ); … … 141 141 switch( _comp->type ) { 142 142 case TT_INT: 143 iptr = (int*)ptr; 143 iptr = (int*)ptr; 144 144 for ( int i = 0; i < _comp->quantifier; ++i ) { 145 145 swap32( iptr ); … … 152 152 swap16( sptr ); 153 153 sptr++; 154 } 154 } 155 155 break; 156 156 case TT_BYTE: … … 163 163 convert_data( _comp->chunks[i], ptr ); 164 164 ptr+= _comp->chunks[i]->totalSize; 165 } 166 } 167 168 } 169 } 170 void BinaryFile::read( const char *_semantics, int _chunks, 165 } 166 } 167 168 } 169 } 170 void BinaryFile::read( const char *_semantics, int _chunks, 171 171 void* _buf, size_t& _bytesRead ) 172 172 { 173 pDataSemantics comp = compileSemantics( _semantics ); 173 pDataSemantics comp = compileSemantics( _semantics ); 174 174 fread( _buf, comp->totalSize, _chunks, this->handle() ); 175 175 if ( byteorder != NATIVE_BYTEORDER ) { 176 176 for ( int i = 0; i < _chunks; ++i ) { 177 177 convert_data( comp, (char*)_buf+i*comp->totalSize ); 178 } 179 } 178 } 179 } 180 180 _bytesRead = comp->totalSize*_chunks; 181 delete comp; 182 } 183 void BinaryFile::read( const char *_semantics, 181 delete comp; 182 } 183 void BinaryFile::read( const char *_semantics, 184 184 void* _buf, size_t& _bytesRead ) 185 185 { 186 pDataSemantics comp = compileSemantics( _semantics ); 186 pDataSemantics comp = compileSemantics( _semantics ); 187 187 fread( _buf, comp->totalSize, 1, this->handle() ); 188 188 189 189 if ( byteorder != NATIVE_BYTEORDER ) { 190 190 convert_data( comp, _buf ); 191 } 192 delete comp; 193 } 194 195 void BinaryFile::write( const char *_semantics, 191 } 192 delete comp; 193 } 194 195 void BinaryFile::write( const char *_semantics, 196 196 void* _buf, size_t& _bytesWritten ) 197 197 { … … 199 199 if ( byteorder != NATIVE_BYTEORDER ) { 200 200 convert_data( comp, _buf ); 201 } 201 } 202 202 _bytesWritten = comp->totalSize; 203 203 fwrite( _buf, comp->totalSize, 1, this->handle() ); -
branches/terrain/src/lib/util/filesys/binary_file.h
r9414 r9415 22 22 } 23 23 24 ~DataSemantics() 24 ~DataSemantics() 25 25 { 26 26 delete[] chunks; 27 27 } 28 28 29 29 int totalSize; 30 30 int quantifier; … … 33 33 union { 34 34 int type; 35 DataSemantics **chunks; 36 }; 35 DataSemantics **chunks; 36 }; 37 37 }; 38 38 … … 40 40 41 41 class BinaryFile : public File { 42 public: 42 public: 43 43 BinaryFile() 44 44 : File( "" ), 45 45 byteorder( NATIVE_BYTEORDER ) 46 46 { /* nothing to be done */ } 47 47 48 48 BinaryFile( const std::string& _file ) 49 : File( _file ), 49 : File( _file ), 50 50 byteorder( NATIVE_BYTEORDER ) 51 51 { /* nothing to be done */ } 52 52 53 53 BinaryFile( const BinaryFile& _file ) 54 : File( _file.name() ), 54 : File( _file.name() ), 55 55 byteorder( _file.getByteorder() ) 56 56 { /* nothing to be done */ } 57 57 58 58 /** 59 59 * Reads a chunk of data based on the _semantics string. The string contains … … 70 70 */ 71 71 void read( const char *_semantics, void* _buf, size_t& _bytesRead ); 72 72 73 73 /** 74 74 * The same as the read above, but with the ability to read multiple 75 * chunks once. Very useful if you don't know how many chunks you're 75 * chunks once. Very useful if you don't know how many chunks you're 76 76 * going to read at compile time. 77 77 */ 78 void read( const char *_semantics, int _chunks, 78 void read( const char *_semantics, int _chunks, 79 79 void* _buf, size_t& _bytesRead ); 80 80 /** … … 93 93 * in the middle of reading a file. You're totally on your own. 94 94 */ 95 inline void setByteorder( ByteOrder _order ) 95 inline void setByteorder( ByteOrder _order ) 96 96 { byteorder = _order; } 97 97 98 98 /** 99 99 * Returns the file's byte-order. … … 101 101 inline ByteOrder getByteorder() const 102 102 { return byteorder; } 103 103 104 104 private: 105 pDataSemantics compileSemantics( const char *_semantics ); 105 pDataSemantics compileSemantics( const char *_semantics ); 106 106 ByteOrder byteorder; 107 107 };
Note: See TracChangeset
for help on using the changeset viewer.