Implementation reading an BIN file. More...
#include <storage/storage.h>
Public Types | |
typedef ptrdiff_t | reference_t |
Type of a reference identifier. | |
Public Member Functions | |
bool | checkNextField (const QString &name) |
Test if there is a field with matching name and type. | |
virtual bool | endCompound () |
End the current compound. | |
virtual bool | endReference () |
Stop the current reference. | |
virtual QString | filename () const |
Name of the file being processed. | |
virtual bool | reader () |
virtual bool | serialize (const QString &filename, Model *model) |
Actually read the file. | |
virtual void | setLastError (int error, const QString &err) |
Change the text of the last error. | |
virtual bool | setOption (int option, int value) |
Change an option. | |
virtual bool | startCompound (const QString &name) |
Start a new compound. | |
virtual int | startReference (const QString &name, const QString &ref_type, reference_t ref) |
Start a reference. | |
virtual bool | writer () |
Protected Member Functions | |
bool | checkFileStatus () |
void | elementUsed () |
const QString & | nextElementName () |
unsigned char | nextElementType () |
template<typename Read , typename Store > | |
bool | readData (QFile *file, Store &value) |
template<typename T > | |
bool | readValue (const QString &name, T &value) |
Protected Attributes | |
QFile * | file |
bool | has_next_element_name |
QString | next_element_name |
int | type_check |
NUMBER_CLASS | type_class [NB_STORAGE_TYPES] |
TYPES | type_conversion [NB_STORAGE_TYPES] |
size_t | type_size [NB_STORAGE_TYPES] |
Implementation reading an BIN file.
Definition at line 439 of file storage_bin.cpp.
typedef ptrdiff_t storage::old::VVEStorage_BINReader::reference_t |
Type of a reference identifier.
Reimplemented from storage::VVEStorage.
Definition at line 443 of file storage_bin.cpp.
bool storage::old::VVEStorage_BINReader::checkNextField | ( | const QString & | name | ) | [virtual] |
Test if there is a field with matching name and type.
For writer, this should always return False.
Implements storage::VVEStorage.
Definition at line 771 of file storage_bin.cpp.
00772 { 00773 const QString& next_name = nextElementName(); 00774 return next_name == name; 00775 }
bool storage::old::VVEStorage_BINReader::endCompound | ( | ) | [virtual] |
End the current compound.
Implements storage::VVEStorage.
Definition at line 612 of file storage_bin.cpp.
bool storage::old::VVEStorage_BINReader::endReference | ( | ) | [virtual] |
Stop the current reference.
Implements storage::VVEStorage.
Definition at line 651 of file storage_bin.cpp.
virtual QString storage::old::VVEStorage_BINReader::filename | ( | ) | const [inline, virtual] |
Name of the file being processed.
Implements storage::VVEStorage.
Definition at line 474 of file storage_bin.cpp.
References QFile::fileName().
00475 { 00476 if(file) 00477 return file->fileName(); 00478 else 00479 return ""; 00480 }
virtual bool storage::old::VVEStorage_BINReader::reader | ( | ) | [inline, virtual] |
Implements storage::VVEStorage.
Definition at line 461 of file storage_bin.cpp.
bool storage::old::VVEStorage_BINReader::serialize | ( | const QString & | filename, | |
Model * | model | |||
) | [virtual] |
Actually read the file.
Implements storage::VVEStorage.
Definition at line 535 of file storage_bin.cpp.
References QString::arg(), storage::BAD_CONTENT, QFile::close(), storage::find_type(), storage::IO_ERROR, storage::NO__ERROR, QFile::open(), Model::serialize(), setLastError(), and Model::versionNumber().
Referenced by storage::VVEStorage_BINReader::serialize().
00536 { 00537 last_error = NO__ERROR; 00538 last_error_string = QString(); 00539 00540 QFile _file(filename); 00541 file = &_file; 00542 has_next_element_name = false; 00543 references.clear(); 00544 if(!file->open(QIODevice::ReadOnly)) 00545 { 00546 setLastError(IO_ERROR, QString("Could not open file '%1' for reading").arg(filename)); 00547 return false; 00548 } 00549 QByteArray first_line = file->readLine(); 00550 if(first_line != "VVE BIN\n") 00551 { 00552 setLastError(BAD_CONTENT, QString("File '%1' is not a VVE BIN file").arg(filename)); 00553 return false; 00554 } 00555 00556 read(file, file_version); 00557 file_version = QString("%1 BIN").arg(file_version); 00558 version_number = model->versionNumber(file_version); 00559 00560 if(!checkFileStatus()) return false; 00561 00562 // Read type conversion 00563 TYPES type; 00564 while((type = read_type(file)) != T_INVALID) 00565 { 00566 unsigned char t; 00567 unsigned char s; 00568 read(file, t); 00569 read(file, s); 00570 NUMBER_CLASS k = (NUMBER_CLASS)t; 00571 size_t size = (size_t)s; 00572 type_conversion[type] = find_type(k, size); 00573 type_size[type] = size; 00574 type_class[type] = k; 00575 } 00576 00577 type_conversion[T_STRING] = T_STRING; 00578 type_conversion[T_BOOL] = T_BOOL; 00579 00580 bool result = model->serialize(*this); 00581 file->close(); 00582 file = 0; 00583 return result; 00584 }
void storage::old::VVEStorage_BINReader::setLastError | ( | int | error, | |
const QString & | error_str | |||
) | [virtual] |
Change the text of the last error.
Any specific implementation might alter the text.
Reimplemented from storage::VVEStorage.
Definition at line 777 of file storage_bin.cpp.
References QString::arg(), and QFile::pos().
Referenced by serialize(), startCompound(), and startReference().
bool storage::old::VVEStorage_BINReader::setOption | ( | int | , | |
int | ||||
) | [virtual] |
Change an option.
The options are implementation-dependent. If the option is not supported, the function returns 0.
Reimplemented from storage::VVEStorage.
Definition at line 511 of file storage_bin.cpp.
References storage::TCO_Exact, storage::TCO_NoCheck, storage::TCO_Permissive, storage::TCO_PermissiveNoWarning, storage::TCO_Strict, and storage::TypeChecking.
00512 { 00513 switch(option) 00514 { 00515 case TypeChecking: 00516 switch(value) 00517 { 00518 case TCO_Exact: 00519 case TCO_Strict: 00520 case TCO_Permissive: 00521 case TCO_PermissiveNoWarning: 00522 case TCO_NoCheck: 00523 type_check = value; 00524 return true; 00525 default: 00526 return false; 00527 } 00528 break; 00529 default: 00530 return false; 00531 } 00532 }
bool storage::old::VVEStorage_BINReader::startCompound | ( | const QString & | name | ) | [virtual] |
Start a new compound.
Useful to organize complicated data structure
When writing, always returns true. When reading, returns true only if the compound exists.
Implements storage::VVEStorage.
Definition at line 598 of file storage_bin.cpp.
References storage::BAD_CONTENT, QString::isEmpty(), and setLastError().
00599 { 00600 if(name.isEmpty()) 00601 return true; 00602 const QString& next_name = nextElementName(); 00603 if(next_name != name) 00604 { 00605 setLastError(BAD_CONTENT, QString("Next compound has name '%1' instead of the expected '%2'").arg(next_name, name)); 00606 return false; 00607 } 00608 elementUsed(); 00609 return true; 00610 }
int storage::old::VVEStorage_BINReader::startReference | ( | const QString & | name, | |
const QString & | ref_type, | |||
reference_t | ref | |||
) | [virtual] |
Start a reference.
All operations preceding the call to stopReference should be stored in a section reserved for references.
References should be loaded only on need.
When writing, always returns true. When reading, returns true only if the reference exists. If the reference does not exist, it will create it, so the reader has to set the fields.
Implements storage::VVEStorage.
Definition at line 627 of file storage_bin.cpp.
References storage::BAD_CONTENT, QString::isEmpty(), setLastError(), and storage::TYPE_CHECK_ERROR.
00628 { 00629 if(!name.isEmpty()) 00630 { 00631 const QString& next_name = nextElementName(); 00632 if(next_name != name) 00633 { 00634 setLastError(BAD_CONTENT, QString("Error, expected reference named '%1' but found element named '%2'").arg(name, next_name)); 00635 return -1; 00636 } 00637 } 00638 unsigned char type = nextElementType(); 00639 if(type != BT_START_REFERENCE) 00640 { 00641 setLastError(TYPE_CHECK_ERROR, QString("Element '%1' is not a reference").arg(name)); 00642 return -1; 00643 } 00644 qint32 id; 00645 read(file, id); 00646 if(!checkFileStatus()) return false; 00647 elementUsed(); 00648 return id; 00649 }
virtual bool storage::old::VVEStorage_BINReader::writer | ( | ) | [inline, virtual] |
Implements storage::VVEStorage.
Definition at line 462 of file storage_bin.cpp.