|
Rapicorn - Experimental UI Toolkit - Source Code
13.07.0
|
By using a DataKey, DataListContainer objects allow storage and retrieval of custom data members in a typesafe fashion. More...
#include <objects.hh>
Inherited by Rapicorn::AdjustmentSimpleImpl [virtual], Rapicorn::WidgetImpl [virtual], and Rapicorn::XmlNode [virtual].
Public Member Functions | |
Accessing custom data members | |
| template<typename Type > | |
| void | set_data (DataKey< Type > *key, Type data) |
| Assign data to the custom keyed data member, deletes any previously set data. | |
| template<typename Type > | |
| Type | get_data (DataKey< Type > *key) const |
| Retrieve contents of the custom keyed data member, returns DataKey::fallback if nothing was set. | |
| template<typename Type > | |
| Type | swap_data (DataKey< Type > *key, Type data) |
| Swap data with the current contents of the custom keyed data member, returns the current contents. | |
| template<typename Type > | |
| Type | swap_data (DataKey< Type > *key) |
| Removes and returns the current contents of the custom keyed data member without deleting it. | |
| template<typename Type > | |
| void | delete_data (DataKey< Type > *key) |
| Delete the current contents of the custom keyed data member, invokes DataKey::destroy. | |
By using a DataKey, DataListContainer objects allow storage and retrieval of custom data members in a typesafe fashion.
The custom data members will initially default to DataKey::fallback and are deleted by the DataListContainer destructor. Example:
// Declare a global key for custom floating point data members static DataKey<double> float_data_key; static void // Access data on any object derived from DataListContainer data_member_access (DataListContainer &some_object) { // Set the custom float member identified by float_data_key to 21.7 some_object.set_data (&float_data_key, 21.7); // Read out the custom member double number = some_object.get_data (&float_data_key); assert (number > 21.5 && number < 22); // Swap custom member for 1.0 const double old_float = some_object.swap_data (&float_data_key, 1.0); assert (old_float > 21 && old_float < 22); // Verify swapped member number = some_object.get_data (&float_data_key); assert (number == 1.0); // Delete custom member some_object.delete_data (&float_data_key); assert (some_object.get_data (&float_data_key) == 0.0); }
1.7.6.1