Changeset 9415 in orxonox.OLD for branches/terrain/src/lib/util/filesys/binary_file.cc
- Timestamp:
- Jul 24, 2006, 12:59:44 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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() );
Note: See TracChangeset
for help on using the changeset viewer.