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 .

Creation

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

maxon::Data data; 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); }

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 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:

// 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 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:

// This example converts the stored value into a maxon::Float value. const maxon::Float floatData = data. 转换 < maxon::Float >() iferr_return ; DiagnosticOutput ( "Float value: @" , floatData);

拷贝

The data stored in a maxon::Data object can easily be copied to another maxon::Data 对象。

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

比较

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. 比较 (dataB); if (res == maxon::COMPARERESULT::EQUAL ) DiagnosticOutput ( "Data containers are equal." ); if (dataA.IsEqual(dataB)) DiagnosticOutput ( "Data containers are equal." ); if (dataA == dataB) DiagnosticOutput ( "Data containers are equal." );

Utility

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

延伸阅读

maxon::Data::CopyFrom
Result< void > CopyFrom(const Data &src)
定义: datatypebase.h:1289
maxon::Data::Convert
Result< T > Convert() const
定义: datatypebase.h:1394
maxon::DataType
定义: datatypebase.h:726
maxon::Data::IsPopulated
Bool IsPopulated() const
定义: datatypebase.h:1211
maxon::Data::Init
Result< void > Init(const DataType &type)
定义: datatypebase.h:1161
maxon::COMPARERESULT::EQUAL
@ EQUAL
result is equal
maxon::String
定义: string.h:1197
maxon::Data
定义: datatypebase.h:1143
maxon::TupleValue::Get
const T & Get(Int index, const TupleDataType &type) const
定义: datatype.h:1027
iferr_return
#define iferr_return
定义: resultbase.h:1434
MAXON_SOURCE_LOCATION
#define MAXON_SOURCE_LOCATION
定义: memoryallocationbase.h:66
maxon::Data::Get
Result< typename std::conditional< GetCollectionKind< T >::value==COLLECTION_KIND::ARRAY, T, typename ByValueParam< T >::type >::type > Get() const
定义: datatypebase.h:1352
maxon::Float
Float64 Float
定义: apibase.h:193
maxon::Data::Set
Result< void > Set(T &&data)
定义: datatypebase.h:1341
maxon::Data::GetCopy
Result< Data > GetCopy() const
Returns a copy of the data.
定义: datatype.h:1139
maxon::BaseArray
定义: basearray.h:366
maxon::TupleValue
定义: datatype.h:1017
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
maxon::BaseArray::Append
MAXON_ATTRIBUTE_FORCE_INLINE ResultRef< T > Append()
定义: basearray.h:569
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::TupleDataType
定义: datatypelib.h:657
maxon::Data::Compare
COMPARERESULT Compare(const Data &c) const
定义: datatypebase.h:1543
maxon::Data::GetType
const DataType & GetType() const
定义: datatypebase.h:1220
maxon::Data::GetTuple
TupleValue * GetTuple()
定义: datatypebase.h:1517
maxon::Data::ToString
String ToString(const FormatStatement *formatStatement=nullptr) const
maxon::Data::Reset
void Reset()
Frees the wrapped data and resetd the Data object to its initial state.
定义: datatypebase.h:1225
maxon::Data::IsEmpty
Bool IsEmpty() const
定义: datatypebase.h:1202
maxon::COMPARERESULT
COMPARERESULT
Data type for comparison results.
定义: compare.h:20

Copyright  © 2014-2025 乐数软件    

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