A generic container for passing any kind of data around. DataObject makes use of the boost::any class and templated constructors to allow for any type of data to be stored in it. The data is stored in a std::vector of boost::any objects. When an accessor wants to retrieve the data out of the DataObject, it must use the read<> function and supply an index into the std::vector. If the requested type does not match the type of the object stored at that location, a boost::bad_any_cast exception is thrown.
DataObject is used to pass information from the UI to an IRule without the type of the information being explicit, which would require a new type of Execute function for every kind of data that could be passed. The strategy at work here allows the data type to be “hidden” while being passed around, but retrieved later. It is somewhat slower, but allows for great flexibility.
DataObject.h
A generic container for passing any kind of data around. | |
The default DataObject constructor. | |
The one-parameter DataObject constructor. | |
The two-parameter DataObject constructror. | |
The three-parameter DataObject constructror. | |
Returns how many items are in the DataObject. | |
Reads data out of the data store. | |
Reads a DataObject from an input stream. | |
Writes a DataObject to an output stream. | |
The data store. |
The default DataObject constructor. | |
The one-parameter DataObject constructor. | |
The two-parameter DataObject constructror. | |
The three-parameter DataObject constructror. | |
Returns how many items are in the DataObject. | |
Reads data out of the data store. | |
Reads a DataObject from an input stream. | |
Writes a DataObject to an output stream. |
|
The three-parameter DataObject constructror. Takes the data and appends it to the std::vector.
| data1 | The first piece of data to store. |
| data2 | The second piece of data to store. |
| data3 | The third piece of data to store. |
|
Reads data out of the data store. Uses the boost::any_cast function to attempt to cast the data at the given index in the data store to the requested type. If the any_cast fails, a boost::bad_any_cast exception is thrown, which signals to the developer that the kind of data they were expecting in that DataObject was not what they actually got. Otherwise, returns a read-only reference to the data object.
A const reference to the data at the given index.
A boost::bad_any_cast when the requested data type does not match the data at the given index in the data store.
|
Writes a DataObject to an output stream. Uses the IAnySerializer for each boost::any object to handle writing the data.
| output | The output stream. |
| DataObject() |
| size_t numItems() const |
|
|
|
| AnyArray mData |