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;

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);

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.Existing(key))
{
const maxon::Data value = dataDict.GetData(keyPtr) iferr_return;
DiagnosticOutput("Key: @, Value: @", key, value);
// remove
dataDict.Erase(key) iferr_return;
}
if (!dataDict.Existing(key))
DiagnosticOutput("Key @ deleted.", key);

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);
}

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);

Further Reading