DataDictionary Manual

About

A maxon::DataDictionary is a data container that stores arbitrary MAXON API data filed under a given key. The base interface is maxon::DataDictionaryInterface.

Note
For custom interfaces inheriting maxon::DataDictionary functionality use maxon::DataDictionaryObjectInterface.

Creation

A new maxon::DataDictionary object can be created on the stack:

// This example creates a new DataDictionary object and stores some values.
maxon::DataDictionary dataDict;
dataDict.Set(0, maxon::Int32(100)) iferr_return;
dataDict.Set(1, maxon::Int32(200)) iferr_return;
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:190
#define iferr_return
Definition: resultbase.h:1524

Keys and Values

A DataDictionary stores data for one or many keys. Both the stored data and the key must be a registered MAXON API data type (see MAXON Data Type).

Note
To access data with a defined type one can use resource IDs, see Resource IDs.
// This example stores and reads values from the given DataDictionary object.
// simple set
dataDict.Set(0, maxon::Int32(100)) iferr_return;
// set maxon::Data
const maxon::Data number(maxon::Int32(123));
dataDict.SetData(maxon::ConstDataPtr(1), std::move(number)) iferr_return;
// simple get
const maxon::Int32 value = dataDict.Get<maxon::Int32>(0) iferr_return;
DiagnosticOutput("Value: @", value);
// get maxon::Data
const maxon::Data data = dataDict.GetData(maxon::ConstDataPtr(1)) iferr_return;
DiagnosticOutput("Data: @", data);
PyObject * value
Definition: abstract.h:715
Definition: datatypebase.h:1740
Definition: datatypebase.h:1229
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:170

The data stored in the DataDictionary can be inspected and deleted with:

// This example checks if a certain key is defined in the given DataDictionary.
// If so the value stored at the key is printed to the debug console and then deleted.
const maxon::Int key = 0;
if (dataDict.Contains(key))
{
const maxon::Data value = dataDict.GetData(keyPtr) iferr_return;
DiagnosticOutput("Key: @, Value: @", key, value);
// remove
dataDict.Erase(key) iferr_return;
}
if (!dataDict.Contains(key))
DiagnosticOutput("Key @ deleted.", key);
PyObject * key
Definition: abstract.h:289
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:202

Iterator

Using an iterator it is simple to loop through all elements stored in the DataDictionary.

// This example loops through all values stored in the given DataDictionary.
for (const auto& data : dataDict)
{
const maxon::Data key = data.first.GetCopy() iferr_return;
const maxon::Data value = data.second.GetCopy() iferr_return;
const maxon::DataType type = value.GetType();
DiagnosticOutput("Key: @, Value: @ (@)", key, value, type);
}
Definition: datatypebase.h:770
Result< Data > GetCopy() const
Returns a copy of the data.
Definition: datatype.h:1234
PyObject ** type
Definition: pycore_pyerrors.h:34

Utility

Further utility functions are:

// This example get the maxon::String representation and a hash value
// for the given DataDictionary and prints it to the debug console.
const maxon::String str = dataDict.ToString(nullptr);
const maxon::UInt hash = dataDict.GetHashCode();
DiagnosticOutput("Hash: @, String: @", hash, str);
Definition: string.h:1237
void * str
Definition: bytesobject.h:77
PyObject Py_hash_t hash
Definition: dictobject.h:35
UInt64 UInt
unsigned 32/64 bit int, size depends on the platform
Definition: apibase.h:203

Further Reading