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.
// store maxon::String
// store maxon::Int
// 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); }
A given maxon::Data object can be inspected and reset with:
// clear data data. 重置 ();
// check if data has been cleared if (data. IsEmpty ()) DiagnosticOutput ( "Data is now empty." );
The key function of maxon::Data is to store and access data stored in the object:
// 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 maxon::Int number = data. Get < maxon::Int32 >() iferr_return ; number++; data. Set (number) iferr_return ; DiagnosticOutput ( "Data: @" , data); }
// This example constructs a complex data type and sets its values.
// construct tuple data type maxon::BaseArray<maxon::DataType> structTypes; 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 maxon::Data 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);
The data stored within a maxon::Data object can also be converted into another data type:
The data stored in a maxon::Data object can easily be copied to another maxon::Data 对象。
// 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);
There are multiple ways to compare two given maxon::Data objects:
Further utility functions are: