#include <DataTable.h>
Description
A container meant to share values across program invocations.
Often with programs, there is a need to preserve data beyond the execution of the program. Sometimes, it is enough to simply write to a text file, but this isn't always flexible, and has little resistance against device errors, forms of corruption, and user tampering. DataTable provides a non-sequential, corruption-resistant way to store data. Using the Write functions, you can store named variables , data, and even other DataTables in a safe manner. Then WriteState() can be used to retrieve a data buffer that represents the DataTable's exact state, which can then be used later in another instance.
Supported component events:
- on-read: after reading a piece of data. (args: name);
- on-write: before writing a piece of data. The default handler actually performs the write, so stopping propogation will prevent writing.(args: name);
- on-remove: before removing a piece of data. The default handler actually performs the removal, so stopping propogation will prevent removal. (args: name);
- on-read-state: after successfully reading a state
Functions | |||||
void | Remove (const std::string &) | ||||
bool | Query (const std::string &) const | ||||
std::vector< uint8_t > | WriteState () | ||||
bool | ReadState (const std::vector< uint8_t > &) | ||||
void | Clear () | ||||
Writing | |||||
Associates a datum with a name.
| |||||
DataTable & | Write (const std::string &name, int i) | ||||
DataTable & | Write (const std::string &name, uint32_t i) | ||||
DataTable & | Write (const std::string &name, uint64_t i) | ||||
DataTable & | Write (const std::string &name, float i) | ||||
DataTable & | Write (const std::string &name, double i) | ||||
DataTable & | Write (const std::string &name, const std::string &i) | ||||
DataTable & | Write (const std::string &name, const std::vector< uint8_t > &i) | ||||
DataTable & | Write (const std::string &name, DataTable &i) | ||||
Reading | |||||
Retrieves a datum associated with a name. If there is no such association, the input reference is left untouched.
| |||||
DataTable & | Read (const std::string &name, int &i) | ||||
DataTable & | Read (const std::string &name, uint32_t &i) | ||||
DataTable & | Read (const std::string &name, uint64_t &i) | ||||
DataTable & | Read (const std::string &name, float &i) | ||||
DataTable & | Read (const std::string &name, double &i) | ||||
DataTable & | Read (const std::string &name, std::string &i) | ||||
DataTable & | Read (const std::string &name, std::vector< uint8_t > &i) | ||||
DataTable & | Read (const std::string &name, DataTable &i) | ||||
![]() | |||||
std::string | GetTag () | ||||
Entity * | GetHost () const | ||||
template<typename T > | |||||
T * | GetHostAs () const | ||||
Entity::ID | GetHostID () const | ||||
virtual std::string | GetInfo () | ||||
bool | EmitEvent (const std::string &eventName, Entity::ID source=Entity::ID(), const std::vector< std::string > &args={}) | ||||
bool | CanHandleEvent (const std::string &eventName) | ||||
void | InstallHook (const std::string &eventName, EventHandler, void *data=nullptr) | ||||
void | UninstallHook (const std::string &eventName, EventHandler) | ||||
void | InstallHandler (const std::string &eventName, EventHandler, void *data=nullptr) | ||||
void | UninstallHandler (const std::string &eventName, EventHandler) | ||||
std::vector< std::string > | GetKnownEvents () const | ||||
Additional Inherited Members | |
![]() | |
using | EventHandler = bool(*)(void *, Component *component, Entity::ID self, Entity::ID source, const std::vector< std::string > &args) |
![]() | |
virtual void | OnStep () |
virtual void | OnDraw () |
virtual void | OnAttach () |
void | InstallEvent (const std::string &eventName, EventHandler mainHandler=nullptr, void *data=nullptr) |
void | UninstallEvent (const std::string &) |
Member Function Documentation
void Remove | ( | const std::string & | ) |
Removes any datum-name association.
bool Query | ( | const std::string & | ) | const |
Returns whether there is a datum-name association with the given name.
std::vector<uint8_t> WriteState | ( | ) |
Writes a pure data-form of the table's contents. This can then be passed into ReadState() turn the calling object into an exact copy of this one.
WriteState() / ReadState() were intended to be used in tandem to preserve data contents of the DataTable across program invocations. Along with writing the exact state of the DataTable, the data includes header and checksum data to improve parity across execution states.
bool ReadState | ( | const std::vector< uint8_t > & | ) |
Sets the DataTable state to reflect the state defined by the input buffer.
The buffer is implied to have been produced from a WriteState call. If not, or corruption on some device has occurred, there is a good chance that this function will detect it before applying the data. In the case that an error does occur, false will be returned and no action taken.
void Clear | ( | ) |
Removes all stored associations and data entries, restoring the container back to a default state.
The documentation for this class was generated from the following file:
- /home/jc/git/Dynacoe/DynacoeSrc/includes/Dynacoe/Components/DataTable.h