Data Manual


maxon::Data is a generic container that can store any MAXON API data type (MAXON Data Type). It is typically used together with a maxon::DataDictionary which stores such maxon::Data elements, see DataDictionary Manual.


A new maxon::Data object can simply be created on the stack.

// This example creates new maxon::Data objects with various data.
// store maxon::String
data.Set("Hello World"_s) iferr_return;
// store maxon::Int
const maxon::Data integerData(123);
const maxon::DataType dataType = integerData.GetType();
if (dataType)
DiagnosticOutput("Type: @", dataType);
// store maxon::Float
const maxon::DataType floatDataType = maxon::GetDataType<maxon::Float>();
if (floatDataType)
maxon::Data floatData;
floatData.Init(floatDataType) iferr_return;
DiagnosticOutput("Float Data: @", floatData);
Definition: datatypebase.h:1199
Result< void > Set(T &&data)
Definition: datatypebase.h:1393
Result< void > Init(const DataType &type)
Definition: datatypebase.h:1213
Definition: datatypebase.h:772
#define DiagnosticOutput(formatString,...)
Definition: debugdiagnostics.h:176
#define iferr_return
Definition: resultbase.h:1465

A given maxon::Data object can be inspected and reset with:

// This example checks if the given maxon::Data object is empty.
// If not the type of the stored data is printed to the debug console.
// After that, it is emptied.
if (data.IsPopulated())
// check type of the stored data
const maxon::DataType type = data.GetType();
if (type)
DiagnosticOutput("Type: @", type);
// clear data
// check if data has been cleared
if (data.IsEmpty())
DiagnosticOutput("Data is now empty.");
void Reset()
Frees the wrapped data and resetd the Data object to its initial state.
Definition: datatypebase.h:1277
Bool IsEmpty() const
Definition: datatypebase.h:1254
Bool IsPopulated() const
Definition: datatypebase.h:1263
const DataType & GetType() const
Definition: datatypebase.h:1272
PyObject ** type
Definition: pycore_pyerrors.h:34


The key function of maxon::Data is to store and access data stored in the object:

// This example checks if the given maxon::Data object stores an maxon::Int32 value.
// If so, the stored value is increased.
// get maxon::Int32 type
const maxon::DataType integerType = maxon::GetDataType<maxon::Int32>();
if (!integerType)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// check if data stores maxon::Int32 data
const maxon::DataType type = data.GetType();
if (type == integerType)
// increment data
data.Set(number) iferr_return;
DiagnosticOutput("Data: @", data);
Result< typename std::conditional< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, T, typename ByValueParam< T >::type >::type > Get() const
Definition: datatypebase.h:1404
Int64 Int
signed 32/64 bit int, size depends on the platform
Definition: apibase.h:188
int32_t Int32
32 bit signed integer datatype.
Definition: apibase.h:176
Definition: memoryallocationbase.h:67
// This example constructs a complex data type and sets its values.
// construct tuple data type
structTypes.Append(maxon::GetDataType<maxon::Int>()) iferr_return;
structTypes.Append(maxon::GetDataType<maxon::Float>()) iferr_return;
const maxon::TupleDataType tupleDataType = maxon::ParametricTypes::Tuple().Instantiate(structTypes) iferr_return;
// create data
data.Init(tupleDataType) iferr_return;
// access tuple
maxon::TupleValue* const tuple = data.GetTuple();
if (!tuple)
return maxon::UnexpectedError(MAXON_SOURCE_LOCATION);
// fill data
tuple->Get<maxon::Int>(0, tupleDataType) = 100;
tuple->Get<maxon::Float>(1, tupleDataType) = 100.0_f;
// check data
DiagnosticOutput("Data: @", data);
#define Tuple(a0, a1, a2, a3, a4, a5, a6)
Definition: Python-ast.h:652
Definition: basearray.h:412
Definition: basearray.h:677
TupleValue * GetTuple()
Definition: datatypebase.h:1569
Definition: datatypelib.h:751
Definition: datatype.h:1073
PyObject * tuple
Definition: abstract.h:150
Float64 Float
Definition: apibase.h:197

The data stored within a maxon::Data object can also be converted into another data type:

// This example converts the stored value into a maxon::Float value.
const maxon::Float floatData = data.Convert<maxon::Float>() iferr_return;
DiagnosticOutput("Float value: @", floatData);
Result< T > Convert() const
Definition: datatypebase.h:1446


The data stored in a maxon::Data object can easily be copied to another maxon::Data object.

// This example copies the data stored in the given maxon::Data object to two new objects.
// use CopyFrom()
maxon::Data copy1;
copy1.CopyFrom(data) iferr_return;
DiagnosticOutput("Copy: @", copy1);
// use GetCopy()
const maxon::Data copy2 = data.GetCopy() iferr_return;
DiagnosticOutput("Copy: @", copy2);
Result< void > CopyFrom(const Data &src)
Definition: datatypebase.h:1341
Result< Data > GetCopy() const
Returns a copy of the data.
Definition: datatype.h:1194


There are multiple ways to compare two given maxon::Data objects:

// This example compares the two given maxon::Data objects in multiple ways.
const maxon::COMPARERESULT res = dataA.Compare(dataB);
DiagnosticOutput("Data containers are equal.");
if (dataA.IsEqual(dataB))
DiagnosticOutput("Data containers are equal.");
if (dataA == dataB)
DiagnosticOutput("Data containers are equal.");
Py_UCS4 * res
Definition: unicodeobject.h:1113
Data type for comparison results.
Definition: compare.h:21
result is equal


Further utility functions are:

// This example gets the maxon::String representation of the
// stored data and prints it to the console.
const maxon::String str = data.ToString(nullptr);
DiagnosticOutput("String: @", str);
String ToString(const FormatStatement *formatStatement=nullptr) const
Definition: string.h:1235
void * str
Definition: bytesobject.h:77

Further Reading