deCONZ C++ API v2.6.1
Loading...
Searching...
No Matches
Zigbee Strong Types

Strong typed Zigbee types like cluster and attribute identifiers. More...

Classes

class  deCONZ::ZclDataTypeId_t
 A strong typed ZCL data type identifier. More...
 
class  deCONZ::ZclCommandId_t
 A strong typed ZCL command identifier. More...
 
class  deCONZ::ZclAttributeId_t
 A strong typed ZCL attribute identifier. More...
 
class  deCONZ::ManufacturerCode_t
 A strong typed Zigbee manufacturer code. More...
 
class  deCONZ::ZclClusterId_t
 A strong typed ZCL cluster identifier. More...
 

Detailed Description

Strong typed Zigbee types like cluster and attribute identifiers.

See also
C++11 Literals

These types should be used instead plain C++ types like quint8, quint16, quint32, etc. They prevent a common class of errors and provide safety at compile time.

Problems with using basic C++ types for function arguments

Consider the following function:

void example1(quint16 clusterId, quint16 attrId, quint8 dataType, quint16 mfcode)
{
}

The function can be called in various ways without the compiler complaining if something is wrong.

example1(0x0006, 0x0000, 0x10, 0x0000); // ok, but can you tell which parameter is what?
example1(0x0000, 0x0006, 0x0000, 0x01); // compiles fine, but now the parameter order is wrong

Better solution with strong types

Here is the same function but using strong types arguments.

{
}
example1(0x0006, 0x0000, 0x10, 0x0000); // compile time error, this style doesn't work anymore
example1(0x0006_clid, 0x0000_atid, 0x10_dtid, 0x0000_mfcode); // ok, using C++11 literals
example1(0x0000_atid, 0x0006_clid, 0x10_dtid, 0x0000_mfcode); // compile time error, wrong order of arguments 1 and 2
A strong typed Zigbee manufacturer code.
Definition zcl.h:615
A strong typed ZCL attribute identifier.
Definition zcl.h:533
A strong typed ZCL cluster identifier.
Definition zcl.h:1106
A strong typed ZCL data type identifier.
Definition zcl.h:224

Using strong typed values improves the readability and guards against common bugs at compile time.

Performance

Albeit the declaration of these classes looks rather complex, the compiled code is equal to the weakly typed version. Therefore there is zero runtime overhead by using these types.