Structs are immutable objects that contain a set of key-value pairs. The key, as well as the types of each associated value for each struct are defined in advance within a Struct type that has the same name as the Struct. More...
Structs are immutable objects that contain a set of key-value pairs. The key, as well as the types of each associated value for each struct are defined in advance within a Struct type that has the same name as the Struct.
The Struct types are stored within a Type manager. In any given instance of openDAQ, a single Type manager should exist that is part of its Context.
When creating a Struct, the Type manager is used to validate the given dictionary of keys and values against the Struct type stored within the manager. If no type with the given Struct name is currently stored, a default type is created using the Struct field names and values as its parameters. When creating a Struct, fields that are part of the Struct type can be omitted. If so, they will be replaced by either null
or, if provided by the Struct type, the default value of the field.
In the case that a field name is present that is not part of the struct type, or if the value type of the field does not match, construction of the Struct will fail.
NOTE: Field values of fields with the Core type ctUndefined
can hold any value, regardless of its type.
Structs are an openDAQ core type (ctStruct). Several objects in openDAQ such as an Unit, or DataDescriptor are Structs, allowing for access to their fields through Struct methods. Such objects are, by definiton, immutable - their fields cannot be modified. In order to change the value of a Struct-type object, a new Struct must be created.
A Struct can only have fields of Core type: ctBool
, ctInt
, ctFloat
, ctString
, ctList
, ctDict
, ctRatio
, ctComplexNumber
, ctStruct
, or ctUndefined
. Additionally, all Container types (ctList
, ctDict
) should only have values of the aforementioned types.
Public Member Functions | |
virtual ErrCode INTERFACE_FUNC | getStructType (IStructType **type)=0 |
Gets the Struct's type. More... | |
virtual ErrCode INTERFACE_FUNC | getFieldNames (IList **names)=0 |
Gets a list of all Struct field names. More... | |
virtual ErrCode INTERFACE_FUNC | getFieldValues (IList **values)=0 |
Gets a list of all Struct field values. More... | |
virtual ErrCode INTERFACE_FUNC | get (IString *name, IBaseObject **field)=0 |
Gets the value of a field with the given name. More... | |
virtual ErrCode INTERFACE_FUNC | getAsDictionary (IDict **dictionary)=0 |
Gets the field names and values of the Struct as a Dictionary. More... | |
virtual ErrCode INTERFACE_FUNC | hasField (IString *name, Bool *contains)=0 |
Checks whether a field with the given name exists in the Struct. More... | |
![]() | |
virtual ErrCode INTERFACE_FUNC | borrowInterface (const IntfID &intfID, void **obj) const =0 |
Returns another interface which is supported by the object without incrementing the reference count. More... | |
virtual ErrCode INTERFACE_FUNC | dispose ()=0 |
Disposes all references held by the object. More... | |
virtual ErrCode INTERFACE_FUNC | getHashCode (SizeT *hashCode)=0 |
Returns hash code of the object. More... | |
virtual ErrCode INTERFACE_FUNC | equals (IBaseObject *other, Bool *equal) const =0 |
Compares object to another object for equality. More... | |
virtual ErrCode INTERFACE_FUNC | toString (CharPtr *str)=0 |
Returns a string representation of the object. More... | |
![]() | |
virtual ErrCode INTERFACE_FUNC | queryInterface (const IntfID &intfID, void **obj)=0 |
Returns another interface which is supported by the object and increments the reference count. More... | |
virtual int INTERFACE_FUNC | addRef ()=0 |
Increments the reference count for an interface on an object. More... | |
virtual int INTERFACE_FUNC | releaseRef ()=0 |
Decrements the reference count for an interface on an object. More... | |
|
pure virtual |
Gets the value of a field with the given name.
name | The name of the queried field. | |
[out] | field | The value of the field. |
Gets the field names and values of the Struct as a Dictionary.
[out] | dictionary | The Dictionary object with field names as keys, and field values as its values. |
Gets a list of all Struct field names.
[out] | names | The list of field names. |
The list of names will be of equal length to the list of values. Additionally, the name of a field at any given index corresponds to the value stored in the list of values.
Gets a list of all Struct field values.
[out] | values | The list of field values. |
The list of names will be of equal length to the list of values. Additionally, the name of a field at any given index corresponds to the value stored in the list of values.
|
pure virtual |
Gets the Struct's type.
[out] | type | The Struct type |