DataDictionary Manual

内容表

关于

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

注意
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 ).

注意
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.Contains(key)) { const maxon::ConstDataPtr keyPtr = maxon::ConstDataPtr (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);

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

延伸阅读

maxon::DataType
定义: datatypebase.h:726
maxon::String
定义: string.h:1197
maxon::Data
定义: datatypebase.h:1143
iferr_return
#define iferr_return
定义: resultbase.h:1434
maxon::ConstDataPtr
定义: datatypebase.h:1730
maxon::Data::GetCopy
Result< Data > GetCopy() const
Returns a copy of the data.
定义: datatype.h:1139
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::Int32
int32_t Int32
32 bit signed integer datatype.
定义: apibase.h:172
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
定义: apibase.h:184
maxon::Data::GetType
const DataType & GetType() const
定义: datatypebase.h:1220
maxon::UInt
UInt64 UInt
unsigned 32/64 bit int, size depends on the platform
定义: apibase.h:185

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1