#include <include/EDoc/Persistence.h>
Inheritance diagram for EDoc::Persistence:
EDocPersistence is a class that derives from persistence IFace that constructs appropiate text/binary persistence layer and also manages the lifetime of temporary files as necessary.
When compiled with GPL lisensing enabled this will also extract a number of temporary files from a BFD file object if there are multiple .edc files embedded into it.
Definition at line 45 of file Persistence.h.
Public Types | |
enum | EncodingType { UNKNOWN = 0, TEXT, BINARY } |
Type representing what format (Text/Binary) the .edc file is encoded in. More... | |
Public Member Functions | |
std::string | GetFilenameRep () const |
Returns a representation of the name of the file being used. | |
virtual | ~Persistence () |
Destructor. | |
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(). | |
Persistence (const Persistence &right) | |
Copy constructor. | |
Persistence & | operator= (const Persistence &right) |
Assignment operator. | |
Static Public Member Functions | |
static void | AddTempFile (std::string filename) |
Adds a new temporary file to the temp_files list. | |
static void | RemoveTempFile (std::string filename) |
Adds a temporary file from the temp_files list after it has been deleted. | |
static void | AddArchiveFactory (ArchiveIFace *factory) |
Adds new archive format that can be used for reading/writing. | |
static std::list< ManagedFile > | ReadExtract (ManagedFile filename) |
Will extract a list of managed files from a given file if it is a known archive type. | |
static std::list< Persistence > | ReadOpen (std::string filename) |
Opens the given file for reading from. | |
static Persistence | WriteOpen (std::string filename, EncodingType format=TEXT, std::string item_name="default.edc") |
Opens the given file for writing to. | |
Data Fields | |
int | ref_count |
Is a integer that can be used for reference counting. | |
Static Public Attributes | |
static std::list< std::string > | temp_files |
List of all currently open temporary files. | |
Private Member Functions | |
Persistence (bool read, ManagedFile file_in, EncodingType format_in) | |
Private constructor. | |
void | IncRef () |
Increases the reference count of impl. | |
void | DecRef () |
Decreases the reference count of impl andwill delete it if reference count reaches 0. | |
Private Attributes | |
ManagedFile | file |
A reference to the managed file that is the source for this persistence. | |
EncodingType | format |
The format declared to use for encoding/decoding the file. | |
PersistenceIFace * | impl |
A pointer to the particular persistence layer to use. | |
Static Private Attributes | |
static std::list< ArchiveIFace * > | archive_formats |
A list of "factories" for all archive formats that can be understood. |
Type representing what format (Text/Binary) the .edc file is encoded in.
Definition at line 53 of file Persistence.h.
EDoc::Persistence::~Persistence | ( | ) | [virtual] |
Destructor.
Will delete any open temporary files.
Definition at line 274 of file Persistence.cpp.
References DecRef().
EDoc::Persistence::Persistence | ( | const Persistence & | right | ) |
Copy constructor.
Definition at line 168 of file Persistence.cpp.
References IncRef().
Referenced by WriteOpen().
EDoc::Persistence::Persistence | ( | bool | read, | |
ManagedFile | file_in, | |||
EncodingType | format_in | |||
) | [private] |
Private constructor.
Users interface with the Open() and OpenSingle() calls which call this.
Definition at line 178 of file Persistence.cpp.
References BINARY, EDOC_ASSERT, EDOC_THROW_EXCEPTION, file, format, EDoc::ManagedFile::GetWorkFileName(), impl, IncRef(), TEXT, and UNKNOWN.
EDoc::Persistence::AddTempFile | ( | std::string | filename | ) | [static] |
Adds a new temporary file to the temp_files list.
Definition at line 60 of file Persistence.cpp.
References EDOC_Warning, and temp_files.
Referenced by EDocBFD::ExtractedBFDFile::ExtractedBFDFile().
EDoc::Persistence::RemoveTempFile | ( | std::string | filename | ) | [static] |
Adds a temporary file from the temp_files list after it has been deleted.
For atomicity you should only call this AFTER the temp file has been unlinked.
Definition at line 72 of file Persistence.cpp.
References EDOC_Warning, and temp_files.
Referenced by EDocBFD::ExtractedBFDFile::~ExtractedBFDFile().
EDoc::Persistence::AddArchiveFactory | ( | EDoc::ArchiveIFace * | factory | ) | [static] |
Adds new archive format that can be used for reading/writing.
Definition at line 84 of file Persistence.cpp.
References archive_formats.
EDoc::Persistence::ReadExtract | ( | ManagedFile | filename | ) | [static] |
Will extract a list of managed files from a given file if it is a known archive type.
If it is not a known archive type then will return an empty list.
Definition at line 89 of file Persistence.cpp.
References EDoc::Append(), archive_formats, EDOC_Fine, EDOC_FOREACH, and EDoc::ManagedFile::GetName().
Referenced by ReadOpen().
EDoc::Persistence::ReadOpen | ( | std::string | filename | ) | [static] |
Opens the given file for reading from.
If filename is an archive file, then this may extract more than one .edc file from it. This will automatically determine if the file being read is an archive, and when opening the .edc files will automatically determine if it is opening a binary or text edc file.
Definition at line 118 of file Persistence.cpp.
References EDOC_Debug, EDOC_Fine, EDOC_FOREACH, ReadExtract(), UNKNOWN, and EDoc::Throwable::what().
EDoc::Persistence::WriteOpen | ( | std::string | filename, | |
EncodingType | format = TEXT , |
|||
std::string | item_name = "default.edc" | |||
) | [static] |
Opens the given file for writing to.
If filename references a file that already exists this will first check to see if it is a known archive type, in which case it will insert a new edc file into that archive. Otherwise if the file exists but is not a valid known archive type, then this will overwrite the existing file.
filename | The name of the file or archive to write to. | |
format | The .edc file format type to use for writing the edc file. One of TEXT or BINARY. | |
item_name | If filename is an archive this can optionally be a name to give the .edc file within that archive. By default EDoc will use the name default.edc |
Definition at line 147 of file Persistence.cpp.
References archive_formats, EDOC_FOREACH, and Persistence().
EDoc::Persistence::GetFilenameRep | ( | ) | const |
Returns a representation of the name of the file being used.
This is a string to will indicate the source AND work files if they differ.
Definition at line 300 of file Persistence.cpp.
References file, and EDoc::ManagedFile::GetFileNameRep().
EDoc::Persistence::Open | ( | ) | [inline, virtual] |
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 153 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::Open().
EDoc::Persistence::Close | ( | ) | [inline, virtual] |
See PersistenceIFace::Close().
Implements EDoc::PersistenceIFace.
Definition at line 159 of file Persistence.h.
References EDoc::PersistenceIFace::Close(), and impl.
EDoc::Persistence::ReadString | ( | const char * | key | ) | [inline, virtual] |
See PersistenceIFace::ReadString().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 165 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::ReadString().
EDoc::Persistence::ReadBoolean | ( | const char * | key | ) | [inline, virtual] |
See PersistenceIFace::ReadBoolean().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 171 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::ReadBoolean().
EDoc::Persistence::ReadUInt8 | ( | const char * | key | ) | [inline, virtual] |
See PersistenceIFace::ReadUInt8().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 177 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::ReadUInt8().
EDoc::Persistence::ReadInt32 | ( | const char * | key | ) | [inline, virtual] |
See PersistenceIFace::ReadInt32().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 183 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::ReadInt32().
EDoc::Persistence::ReadUInt32 | ( | const char * | key | ) | [inline, virtual] |
See PersistenceIFace::ReadUInt32().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 189 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::ReadUInt32().
EDoc::Persistence::ReadRecordType | ( | ) | [inline, virtual] |
See PersistenceIFace::ReadRecordType().
EDoc::EOFException |
| |
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 195 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::ReadRecordType().
EDoc::Persistence::WriteString | ( | const char * | key, | |
std::string | value | |||
) | [inline, virtual] |
See PersistenceIFace::WriteString().
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 201 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::WriteString().
EDoc::Persistence::WriteBoolean | ( | const char * | key, | |
bool | value | |||
) | [inline, virtual] |
See PersistenceIFace::WriteBoolean().
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 207 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::WriteBoolean().
EDoc::Persistence::WriteUInt8 | ( | const char * | key, | |
uint8_t | value | |||
) | [inline, virtual] |
See PersistenceIFace::WriteUInt8().
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 213 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::WriteUInt8().
EDoc::Persistence::WriteInt32 | ( | const char * | key, | |
int32_t | value | |||
) | [inline, virtual] |
See PersistenceIFace::WriteInt32().
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 219 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::WriteInt32().
EDoc::Persistence::WriteUInt32 | ( | const char * | key, | |
uint32_t | value | |||
) | [inline, virtual] |
See PersistenceIFace::WriteUInt32().
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 225 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::WriteUInt32().
EDoc::Persistence::WriteUInt32Debug | ( | const char * | key, | |
uint32_t | value, | |||
std::string | debug_text | |||
) | [inline, virtual] |
See PersistenceIFace::WriteUInt32Debug().
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 231 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::WriteUInt32Debug().
EDoc::Persistence::WriteInt32Debug | ( | const char * | key, | |
int32_t | value, | |||
std::string | debug_text | |||
) | [inline, virtual] |
See PersistenceIFace::WriteInt32Debug().
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 238 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::WriteInt32Debug().
EDoc::Persistence::WriteRecordType | ( | uint8_t | value | ) | [inline, virtual] |
See PersistenceIFace::WriteRecordType().
EDoc::FileIOException |
|
Implements EDoc::PersistenceIFace.
Definition at line 245 of file Persistence.h.
References impl, and EDoc::PersistenceIFace::WriteRecordType().
EDoc::Persistence::operator= | ( | const Persistence & | right | ) |
EDoc::Persistence::IncRef | ( | ) | [private] |
Increases the reference count of impl.
Definition at line 279 of file Persistence.cpp.
References impl, and EDoc::PersistenceIFace::ref_count.
Referenced by operator=(), and Persistence().
EDoc::Persistence::DecRef | ( | ) | [private] |
Decreases the reference count of impl andwill delete it if reference count reaches 0.
Definition at line 287 of file Persistence.cpp.
References impl, and EDoc::PersistenceIFace::ref_count.
Referenced by operator=(), and ~Persistence().
std::list< std::string > EDoc::Persistence::temp_files [static] |
List of all currently open temporary files.
This static list is used for claning up temporary files at program exit regardless of exiting due to signal interruption or for normal exit.
Definition at line 66 of file Persistence.h.
Referenced by AddTempFile(), and RemoveTempFile().
ManagedFile EDoc::Persistence::file [private] |
A reference to the managed file that is the source for this persistence.
This may represent a file inside an archive or a standard file.
Definition at line 289 of file Persistence.h.
Referenced by GetFilenameRep(), operator=(), and Persistence().
EncodingType EDoc::Persistence::format [private] |
The format declared to use for encoding/decoding the file.
This is one of text or binary.
Definition at line 296 of file Persistence.h.
Referenced by operator=(), and Persistence().
PersistenceIFace* EDoc::Persistence::impl [private] |
A pointer to the particular persistence layer to use.
This is eithre an instance of TextPersistence or BinaryPersistence depending on wether the .edc file is a text or binary format edc file.
Definition at line 304 of file Persistence.h.
Referenced by Close(), DecRef(), IncRef(), Open(), operator=(), Persistence(), ReadBoolean(), ReadInt32(), ReadRecordType(), ReadString(), ReadUInt32(), ReadUInt8(), WriteBoolean(), WriteInt32(), WriteInt32Debug(), WriteRecordType(), WriteString(), WriteUInt32(), WriteUInt32Debug(), and WriteUInt8().
std::list< ArchiveIFace * > EDoc::Persistence::archive_formats [static, private] |
A list of "factories" for all archive formats that can be understood.
Definition at line 310 of file Persistence.h.
Referenced by AddArchiveFactory(), ReadExtract(), and WriteOpen().
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.