EDoc::BinaryPersistence Class Reference

#include <include/EDoc/BinaryPersistence.h>

Inheritance diagram for EDoc::BinaryPersistence:

EDoc::PersistenceIFace

Detailed Description

An implementation of PersistenceIFace for writing to binary files.

This implementation of PersistenceIFace is much more efficient than its text counterpart in both size of the data file and speed of reading/writing. However it does not lend itself easily to debugging problems.

Definition at line 38 of file BinaryPersistence.h.

Public Member Functions

 BinaryPersistence (bool read, std::string filename)
 Create an instance that represents a binary file for reading OR writing (But not both at once).
virtual ~BinaryPersistence ()
 Closes the file upon destruction.
virtual void Open ()
 Opens the file.
virtual void Close ()
 Closes the file.
virtual std::string ReadString (const char *key)
 See PersistenceIFace.
virtual bool ReadBoolean (const char *key)
 See PersistenceIFace.
virtual uint8_t ReadUInt8 (const char *key)
 See PersistenceIFace.
virtual int32_t ReadInt32 (const char *key)
 See PersistenceIFace.
virtual uint32_t ReadUInt32 (const char *key)
 See PersistenceIFace.
virtual uint8_t ReadRecordType ()
 See PersistenceIFace.
virtual void WriteString (const char *key, std::string value)
 See PersistenceIFace.
virtual void WriteBoolean (const char *key, bool value)
 See PersistenceIFace.
virtual void WriteUInt8 (const char *key, uint8_t value)
 See PersistenceIFace.
virtual void WriteInt32 (const char *key, int32_t value)
 See PersistenceIFace.
virtual void WriteUInt32 (const char *key, uint32_t value)
 See PersistenceIFace.
virtual void WriteUInt32Debug (const char *key, uint32_t value, std::string debug_text)
 See PersistenceIFace.
virtual void WriteInt32Debug (const char *key, int32_t value, std::string debug_text)
 See PersistenceIFace.
virtual void WriteRecordType (uint8_t value)
 See PersistenceIFace.

Data Fields

int ref_count
 Is a integer that can be used for reference counting.

Private Member Functions

void ReadData (char *buffer, size_t amount, const char *key)
 Used internally to read some data into a buffer.

Private Attributes

std::fstream file
 The file stream object that will be manipulated.
bool reading
 True if reading from the file or false if writing to it.
std::string filename
 The name of the file being operated on.


Constructor & Destructor Documentation

EDoc::BinaryPersistence::BinaryPersistence ( bool  read,
std::string  filename 
)

Create an instance that represents a binary 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.

Parameters:
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 42 of file BinaryPersistence.cpp.

EDoc::BinaryPersistence::~BinaryPersistence (  )  [virtual]

Closes the file upon destruction.

Note:
EDoc++ data included.

Definition at line 50 of file BinaryPersistence.cpp.

References Close().


Member Function Documentation

EDoc::BinaryPersistence::Open (  )  [virtual]

Opens the file.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 55 of file BinaryPersistence.cpp.

References EDOC_Debug, EDOC_THROW_EXCEPTION, file, filename, and reading.

EDoc::BinaryPersistence::Close (  )  [virtual]

Closes the file.

Note:
EDoc++ data included.

Implements EDoc::PersistenceIFace.

Definition at line 89 of file BinaryPersistence.cpp.

References file.

Referenced by ~BinaryPersistence().

EDoc::BinaryPersistence::ReadString ( const char *  key  )  [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::EOFException 
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 114 of file BinaryPersistence.cpp.

References EDOC_Fine, EDOC_Finer, EDOC_THROW_EXCEPTION, ReadData(), reading, and ReadUInt32().

EDoc::BinaryPersistence::ReadBoolean ( const char *  key  )  [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 141 of file BinaryPersistence.cpp.

References EDOC_Fine, EDOC_Finer, EDOC_THROW_EXCEPTION, file, filename, and reading.

EDoc::BinaryPersistence::ReadUInt8 ( const char *  key  )  [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::EOFException 
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 180 of file BinaryPersistence.cpp.

References EDOC_Fine, EDOC_Finer, EDOC_THROW_EXCEPTION, ReadData(), and reading.

Referenced by ReadRecordType().

EDoc::BinaryPersistence::ReadInt32 ( const char *  key  )  [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::EOFException 
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 196 of file BinaryPersistence.cpp.

References EDOC_Finer, and ReadUInt32().

EDoc::BinaryPersistence::ReadUInt32 ( const char *  key  )  [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::EOFException 
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 202 of file BinaryPersistence.cpp.

References EDOC_Fine, EDOC_Finer, EDOC_THROW_EXCEPTION, ReadData(), and reading.

Referenced by ReadInt32(), and ReadString().

EDoc::BinaryPersistence::ReadRecordType (  )  [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::EOFException 
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 223 of file BinaryPersistence.cpp.

References EDOC_Finer, KEY_RECORD_TYPE, and ReadUInt8().

EDoc::BinaryPersistence::WriteString ( const char *  key,
std::string  value 
) [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 229 of file BinaryPersistence.cpp.

References EDOC_Fine, EDOC_THROW_EXCEPTION, file, filename, reading, and WriteUInt32().

EDoc::BinaryPersistence::WriteBoolean ( const char *  key,
bool  value 
) [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 251 of file BinaryPersistence.cpp.

References EDOC_Fine, EDOC_THROW_EXCEPTION, file, filename, and reading.

EDoc::BinaryPersistence::WriteUInt8 ( const char *  key,
uint8_t  value 
) [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 277 of file BinaryPersistence.cpp.

References EDOC_Fine, EDOC_THROW_EXCEPTION, file, filename, and reading.

Referenced by WriteRecordType().

EDoc::BinaryPersistence::WriteInt32 ( const char *  key,
int32_t  value 
) [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 297 of file BinaryPersistence.cpp.

References EDOC_Fine, and WriteUInt32().

Referenced by WriteInt32Debug().

EDoc::BinaryPersistence::WriteUInt32 ( const char *  key,
uint32_t  value 
) [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 303 of file BinaryPersistence.cpp.

References EDOC_Fine, EDOC_THROW_EXCEPTION, file, filename, and reading.

Referenced by WriteInt32(), WriteString(), and WriteUInt32Debug().

EDoc::BinaryPersistence::WriteUInt32Debug ( const char *  key,
uint32_t  value,
std::string  debug_text 
) [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 330 of file BinaryPersistence.cpp.

References WriteUInt32().

EDoc::BinaryPersistence::WriteInt32Debug ( const char *  key,
int32_t  value,
std::string  debug_text 
) [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 336 of file BinaryPersistence.cpp.

References WriteInt32().

EDoc::BinaryPersistence::WriteRecordType ( uint8_t  value  )  [virtual]

See PersistenceIFace.

Note:
EDoc++ data included.
Exceptions:
EDoc::FileIOException 

Implements EDoc::PersistenceIFace.

Definition at line 342 of file BinaryPersistence.cpp.

References EDOC_Fine, EDOC_THROW_EXCEPTION, KEY_RECORD_TYPE, reading, and WriteUInt8().

EDoc::BinaryPersistence::ReadData ( char *  buffer,
size_t  amount,
const char *  key 
) [private]

Used internally to read some data into a buffer.

Note:
EDoc++ data included.
Exceptions:
EDoc::EOFException 
EDoc::FileIOException 

Definition at line 94 of file BinaryPersistence.cpp.

References EDOC_Finest, EDOC_THROW_EXCEPTION, file, and filename.

Referenced by ReadString(), ReadUInt32(), and ReadUInt8().


Field Documentation

std::fstream EDoc::BinaryPersistence::file [private]

The file stream object that will be manipulated.

Definition at line 158 of file BinaryPersistence.h.

Referenced by Close(), Open(), ReadBoolean(), ReadData(), WriteBoolean(), WriteString(), WriteUInt32(), and WriteUInt8().

bool EDoc::BinaryPersistence::reading [private]

True if reading from the file or false if writing to it.

Definition at line 163 of file BinaryPersistence.h.

Referenced by Open(), ReadBoolean(), ReadString(), ReadUInt32(), ReadUInt8(), WriteBoolean(), WriteRecordType(), WriteString(), WriteUInt32(), and WriteUInt8().

std::string EDoc::BinaryPersistence::filename [private]

The name of the file being operated on.

Definition at line 168 of file BinaryPersistence.h.

Referenced by Open(), ReadBoolean(), ReadData(), WriteBoolean(), WriteString(), WriteUInt32(), and WriteUInt8().

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().


The documentation for this class was generated from the following files:
Generated on Tue Jan 20 18:26:08 2009 for EDoc-0.2.1 by  doxygen 1.5.1