#include <include/EDoc/TextPersistence.h>
Inheritance diagram for EDoc::TextPersistence:
This implementation of PersistenceIFace was created primarily for debugging purposes. The files it generates are orders of magnitude larger than the BinaryPersistence class, however the format it uses provides key name, type and value validation upon reading. It also provides ability to write in a highly verbose mode where whenever an integer index is written to the file it will also write an un-used string that shows which data type that integer indexes. This makes reading .edc files mush easier.
From the persistence_data.h file this will use the macros:
# Comment
$KeyName1: value
$KeyName2: int_value Ignored Debugging Text
This limits the string to be saved to string that only contain text values and NOT CR/LF characters. This isnt a problem for EDoc currently but may in the future be replaced with a format where the value is a string escaped using standard unix like escape sequence conventions (i.e. based on backslash char).
Definition at line 62 of file TextPersistence.h.
Public Member Functions | |
TextPersistence (bool read, std::string filename) | |
Create an instance that represents a text file for reading OR writing (But not both at once). | |
virtual | ~TextPersistence () |
Closes the file upon destruction. | |
virtual void | Open () |
See PersistenceIFace::Open(). | |
virtual void | Close () |
See PersistenceIFace::Close(). | |
virtual std::string | ReadString (const char *key) |
See PersistenceIFace::ReadString(). | |
virtual bool | ReadBoolean (const char *key) |
See PersistenceIFace::ReadBoolean(). | |
virtual uint8_t | ReadUInt8 (const char *key) |
See PersistenceIFace::ReadUInt8(). | |
virtual int32_t | ReadInt32 (const char *key) |
See PersistenceIFace::ReadInt32(). | |
virtual uint32_t | ReadUInt32 (const char *key) |
See PersistenceIFace::ReadUInt32(). | |
virtual uint8_t | ReadRecordType () |
See PersistenceIFace::ReadRecordType(). | |
virtual void | WriteString (const char *key, std::string value) |
See PersistenceIFace::WriteString(). | |
virtual void | WriteBoolean (const char *key, bool value) |
See PersistenceIFace::WriteBoolean(). | |
virtual void | WriteUInt8 (const char *key, uint8_t value) |
See PersistenceIFace::WriteUInt8(). | |
virtual void | WriteInt32 (const char *key, int32_t value) |
See PersistenceIFace::WriteInt32(). | |
virtual void | WriteUInt32 (const char *key, uint32_t value) |
See PersistenceIFace::WriteUInt32(). | |
virtual void | WriteUInt32Debug (const char *key, uint32_t value, std::string debug_text) |
See PersistenceIFace::WriteUInt32Debug(). | |
virtual void | WriteInt32Debug (const char *key, int32_t value, std::string debug_text) |
See PersistenceIFace::WriteInt32Debug(). | |
virtual void | WriteRecordType (uint8_t value) |
See PersistenceIFace::WriteRecordType(). | |
Data Fields | |
int | ref_count |
Is a integer that can be used for reference counting. | |
Private Member Functions | |
std::string | ReadValue (const char *key_in, const char *type_in) |
Reads a line of data extracting the value string for that line. | |
std::string | GetNextLine (const char *key_in="", const char *type_in="") |
Reads the next line of data from the file. | |
Static Private Member Functions | |
static bool | ContainsData (const std::string &data) |
Returns true if the given string contains any characters that are not whitespaces. | |
Private Attributes | |
std::fstream | file |
The file stream used for writing/reading to/from. | |
bool | reading |
True if opened for reading. | |
size_t | line_count |
Current number of lines read from the file. | |
std::string | filename |
Name of file being operated on. |
EDoc::TextPersistence::TextPersistence | ( | bool | read, | |
std::string | filename | |||
) |
Create an instance that represents a text file for reading OR writing (But not both at once).
Note: This does not open the file for reading/writing but just creates an instance of this class that is prepared for reading/writing to the file.
read | If true then the file is considered an input file and can only be used for reading. Otherwise it will be considered an output file and will only be available for writing to. | |
filename | The name of the file to open. |
Definition at line 38 of file TextPersistence.cpp.
EDoc::TextPersistence::~TextPersistence | ( | ) | [virtual] |
Closes the file upon destruction.
Definition at line 45 of file TextPersistence.cpp.
References Close().
EDoc::TextPersistence::Open | ( | ) | [virtual] |
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 50 of file TextPersistence.cpp.
References EDOC_THROW_EXCEPTION, file, filename, GetNextLine(), line_count, and reading.
EDoc::TextPersistence::Close | ( | ) | [virtual] |
See PersistenceIFace::Close().
Implements EDoc::PersistenceIFace.
Definition at line 91 of file TextPersistence.cpp.
References file.
Referenced by ~TextPersistence().
EDoc::TextPersistence::ReadString | ( | const char * | key | ) | [virtual] |
See PersistenceIFace::ReadString().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 300 of file TextPersistence.cpp.
References ReadValue().
EDoc::TextPersistence::ReadBoolean | ( | const char * | key | ) | [virtual] |
See PersistenceIFace::ReadBoolean().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 305 of file TextPersistence.cpp.
References EDOC_THROW_EXCEPTION, line_count, and ReadValue().
EDoc::TextPersistence::ReadUInt8 | ( | const char * | key | ) | [virtual] |
See PersistenceIFace::ReadUInt8().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 323 of file TextPersistence.cpp.
References EDOC_THROW_EXCEPTION, line_count, and ReadValue().
Referenced by ReadRecordType().
EDoc::TextPersistence::ReadInt32 | ( | const char * | key | ) | [virtual] |
See PersistenceIFace::ReadInt32().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 345 of file TextPersistence.cpp.
References EDOC_THROW_EXCEPTION, line_count, and ReadValue().
EDoc::TextPersistence::ReadUInt32 | ( | const char * | key | ) | [virtual] |
See PersistenceIFace::ReadUInt32().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 360 of file TextPersistence.cpp.
References EDOC_THROW_EXCEPTION, line_count, and ReadValue().
EDoc::TextPersistence::ReadRecordType | ( | ) | [virtual] |
See PersistenceIFace::ReadRecordType().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 377 of file TextPersistence.cpp.
References KEY_RECORD_TYPE, and ReadUInt8().
EDoc::TextPersistence::WriteString | ( | const char * | key, | |
std::string | value | |||
) | [virtual] |
See PersistenceIFace::WriteString().
Implements EDoc::PersistenceIFace.
Definition at line 382 of file TextPersistence.cpp.
References BJC_PERSIST_FINISH_KEY_CHAR, BJC_PERSIST_START_KEY_CHAR, EDOC_THROW_EXCEPTION, file, line_count, and reading.
EDoc::TextPersistence::WriteBoolean | ( | const char * | key, | |
bool | value | |||
) | [virtual] |
See PersistenceIFace::WriteBoolean().
Implements EDoc::PersistenceIFace.
Definition at line 399 of file TextPersistence.cpp.
References BJC_PERSIST_FINISH_KEY_CHAR, BJC_PERSIST_START_KEY_CHAR, EDOC_THROW_EXCEPTION, file, line_count, and reading.
EDoc::TextPersistence::WriteUInt8 | ( | const char * | key, | |
uint8_t | value | |||
) | [virtual] |
See PersistenceIFace::WriteUInt8().
Implements EDoc::PersistenceIFace.
Definition at line 422 of file TextPersistence.cpp.
References BJC_PERSIST_FINISH_KEY_CHAR, BJC_PERSIST_START_KEY_CHAR, EDOC_THROW_EXCEPTION, file, line_count, and reading.
Referenced by WriteRecordType().
EDoc::TextPersistence::WriteInt32 | ( | const char * | key, | |
int32_t | value | |||
) | [virtual] |
See PersistenceIFace::WriteInt32().
Implements EDoc::PersistenceIFace.
Definition at line 439 of file TextPersistence.cpp.
References BJC_PERSIST_FINISH_KEY_CHAR, BJC_PERSIST_START_KEY_CHAR, EDOC_THROW_EXCEPTION, file, line_count, and reading.
EDoc::TextPersistence::WriteUInt32 | ( | const char * | key, | |
uint32_t | value | |||
) | [virtual] |
See PersistenceIFace::WriteUInt32().
Implements EDoc::PersistenceIFace.
Definition at line 456 of file TextPersistence.cpp.
References BJC_PERSIST_FINISH_KEY_CHAR, BJC_PERSIST_START_KEY_CHAR, EDOC_THROW_EXCEPTION, file, line_count, and reading.
EDoc::TextPersistence::WriteUInt32Debug | ( | const char * | key, | |
uint32_t | value, | |||
std::string | debug_text | |||
) | [virtual] |
See PersistenceIFace::WriteUInt32Debug().
Implements EDoc::PersistenceIFace.
Definition at line 473 of file TextPersistence.cpp.
References BJC_PERSIST_FINISH_KEY_CHAR, BJC_PERSIST_START_KEY_CHAR, EDOC_THROW_EXCEPTION, file, line_count, and reading.
EDoc::TextPersistence::WriteInt32Debug | ( | const char * | key, | |
int32_t | value, | |||
std::string | debug_text | |||
) | [virtual] |
See PersistenceIFace::WriteInt32Debug().
Implements EDoc::PersistenceIFace.
Definition at line 491 of file TextPersistence.cpp.
References BJC_PERSIST_FINISH_KEY_CHAR, BJC_PERSIST_START_KEY_CHAR, EDOC_THROW_EXCEPTION, file, line_count, and reading.
EDoc::TextPersistence::WriteRecordType | ( | uint8_t | value | ) | [virtual] |
See PersistenceIFace::WriteRecordType().
Implements EDoc::PersistenceIFace.
Definition at line 509 of file TextPersistence.cpp.
References file, KEY_RECORD_TYPE, and WriteUInt8().
EDoc::TextPersistence::ContainsData | ( | const std::string & | data | ) | [static, private] |
Returns true if the given string contains any characters that are not whitespaces.
Definition at line 96 of file TextPersistence.cpp.
Referenced by GetNextLine().
EDoc::TextPersistence::ReadValue | ( | const char * | key_in, | |
const char * | type_in | |||
) | [private] |
Reads a line of data extracting the value string for that line.
This will also validate the type and key throwing an exception if the data is not valid.
Definition at line 139 of file TextPersistence.cpp.
References BJC_PERSIST_COMMENT_CHAR, BJC_PERSIST_FINISH_KEY_CHAR, BJC_PERSIST_START_KEY_CHAR, EDOC_THROW_EXCEPTION, GetNextLine(), and line_count.
Referenced by ReadBoolean(), ReadInt32(), ReadString(), ReadUInt32(), and ReadUInt8().
EDoc::TextPersistence::GetNextLine | ( | const char * | key_in = "" , |
|
const char * | type_in = "" | |||
) | [private] |
Reads the next line of data from the file.
Performs no processing of the data but may use key_in and type_in for debugging purposes if an EOF is encountered.
Definition at line 110 of file TextPersistence.cpp.
References ContainsData(), EDOC_Finer, EDOC_THROW_EXCEPTION, file, line_count, and reading.
Referenced by Open(), and ReadValue().
std::fstream EDoc::TextPersistence::file [private] |
The file stream used for writing/reading to/from.
Definition at line 201 of file TextPersistence.h.
Referenced by Close(), GetNextLine(), Open(), WriteBoolean(), WriteInt32(), WriteInt32Debug(), WriteRecordType(), WriteString(), WriteUInt32(), WriteUInt32Debug(), and WriteUInt8().
bool EDoc::TextPersistence::reading [private] |
True if opened for reading.
Definition at line 206 of file TextPersistence.h.
Referenced by GetNextLine(), Open(), WriteBoolean(), WriteInt32(), WriteInt32Debug(), WriteString(), WriteUInt32(), WriteUInt32Debug(), and WriteUInt8().
size_t EDoc::TextPersistence::line_count [private] |
Current number of lines read from the file.
Used primarily in providing more useful debugging information.
Definition at line 213 of file TextPersistence.h.
Referenced by GetNextLine(), Open(), ReadBoolean(), ReadInt32(), ReadUInt32(), ReadUInt8(), ReadValue(), WriteBoolean(), WriteInt32(), WriteInt32Debug(), WriteString(), WriteUInt32(), WriteUInt32Debug(), and WriteUInt8().
std::string EDoc::TextPersistence::filename [private] |
Name of file being operated on.
Definition at line 218 of file TextPersistence.h.
Referenced by Open().
int EDoc::PersistenceIFace::ref_count [inherited] |
Is a integer that can be used for reference counting.
The Persistence class shares instances of PersistenceIFace implementations. To enable this we use a small "hacked" shared pointer which will allow this class to be reference counted.
Definition at line 161 of file PersistenceIFace.h.
Referenced by EDoc::Persistence::DecRef(), and EDoc::Persistence::IncRef().