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 definition, 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 | |
StructTypePtr | getStructType () const |
Gets the Struct's type. More... | |
ListPtr< IString > | getFieldNames () const |
Gets a list of all Struct field names. More... | |
ListPtr< IBaseObject > | getFieldValues () const |
Gets a list of all Struct field values. More... | |
BaseObjectPtr | get (const StringPtr &name) const |
Gets the value of a field with the given name. More... | |
DictPtr< IString, IBaseObject > | getAsDictionary () const |
Gets the field names and values of the Struct as a Dictionary. More... | |
Bool | hasField (const StringPtr &name) const |
Checks whether a field with the given name exists in the Struct. More... | |
![]() | |
ObjectPtr () | |
Creates a smart pointer with no wrapped interface. | |
ObjectPtr (std::nullptr_t) | |
Creates a smart pointer with no wrapped interface. | |
ObjectPtr (const ObjectPtr< InterfaceType > &objPtr) | |
Creates a smart pointer from another smart pointer. More... | |
ObjectPtr (ObjectPtr< InterfaceType > &&objPtr) noexcept | |
Creates a smart pointer from another smart pointer with move semantics. More... | |
ObjectPtr (const ObjectPtr< U > &objPtr) | |
Creates a smart pointer from another smart pointer of a different interface type. More... | |
ObjectPtr (ObjectPtr< U > &&objPtr) | |
Creates a smart pointer from another smart pointer of a different interface type with move semantics. More... | |
ObjectPtr (InterfaceType *&obj) | |
Creates a smart pointer from an interface pointer. More... | |
ObjectPtr (InterfaceType *&&obj) | |
Creates a smart pointer from an interface pointer with move semantics. More... | |
ObjectPtr (IWeakRef *obj) | |
Creates a smart pointer from a weak reference interface pointer. More... | |
ObjectPtr (const wchar_t *value) | |
Creates a string object smart pointer from UTF16 null terminated sequence. More... | |
ObjectPtr (ConstCharPtr value) | |
Creates a string object smart pointer from UTF8 null terminated sequence. More... | |
ObjectPtr (const U &value) | |
Creates a smart pointer wrapper from value type. More... | |
virtual | ~ObjectPtr () |
Destructor. More... | |
bool | equals (ObjectPtr< IBaseObject > other) const |
Compares object to another object for equality. More... | |
InterfaceType * | detach () |
Disassociates this smart pointer object from the interface that it represents. More... | |
void | dispose () const |
Disposes all references held by the object. More... | |
void | release () |
Resets the wrapped interface to nullptr. More... | |
InterfaceType * | addRefAndReturn () const |
Increments the reference count and returns the interface. More... | |
operator InterfaceType * () const | |
Casts the pointer to the wrapped interface. More... | |
bool | assigned () const |
Checks if the smart pointer is not empty. | |
InterfaceType * | getObject () const |
Gets the pointer to the wrapped interface. More... | |
InterfaceType ** | addressOf () |
Gets the address of the pointer to the wrapped interface. More... | |
InterfaceType ** | operator& () |
Gets the address of the pointer to the wrapped interface. More... | |
U * | as (bool borrow=false) const |
Casts the wrapped interface to another interface. More... | |
U * | asOrNull (bool borrow=false) const |
Casts the wrapped interface to another interface. More... | |
Ptr | asPtr (bool borrow=false) const |
Casts the wrapped interface to another interface and wraps in a smart pointer. More... | |
Ptr | asPtrOrNull (bool borrow=false) const |
Casts the wrapped interface to another interface and wraps in a smart pointer. More... | |
bool | supportsInterface () const |
Checks if the wrapped interface supports another interface. More... | |
bool | supportsInterface (const IntfID &id) const |
Checks if the wrapped interface supports another interface using the interface ID. More... | |
CoreType | getCoreType () const |
Gets the object's CoreType . More... | |
ObjectPtr< IBaseObject > | convertTo (CoreType ct) const |
Converts the object to the specified CoreType . More... | |
SizeT | getHashCode () const |
Returns hash code of the object. More... | |
ObjectPtr< IString > | toString () const |
Converts the object to the string object. More... | |
void | freeze () const |
Freezes the object. More... | |
Bool | isFrozen () const |
Checks if the object is frozen. More... | |
void | dispatch (const ObjectPtr< IBaseObject > ¶ms) const |
Calls the stored callback. More... | |
void | dispatch () const |
Calls the stored callback without any parameters. More... | |
void | execute () const |
Calls the stored callback without any parameters. More... | |
void | execute (Params... params) const |
Calls the stored callback. More... | |
ObjectPtr< IBaseObject > | call (Params... params) const |
Calls the stored callback and returns the result. More... | |
bool | isBorrowed () const |
Checks if the reference is borrowed. More... | |
Additional Inherited Members | |
![]() | |
static InterfaceToSmartPtr< U >::SmartPtr | Borrow (InterfaceType *&obj) |
Borrows an interface. More... | |
static InterfaceToSmartPtr< V >::SmartPtr | Borrow (U *&obj) |
Borrows an interface from the interface of another type. More... | |
static InterfaceToSmartPtr< U >::SmartPtr | Adopt (InterfaceType *obj) |
Adopts an interface. More... | |
static Bool | Equals (const ObjectPtr< IBaseObject > &a, const ObjectPtr< IBaseObject > &b) |
Value based comparison of two objects. If both objects are nullptr, they are considered to be equal. More... | |
|
inline |
Gets the value of a field with the given name.
name | The name of the queried field. |
|
inline |
Gets the field names and values of the Struct as a Dictionary.
Gets a list of all Struct 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.
|
inline |
Gets a list of all Struct 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.
|
inline |
Gets the Struct's type.
|
inline |
Checks whether a field with the given name exists in the Struct.
name | The name of the checked field. |
name
exists in the Struct; false otherwise.