Dawn Framework 1.0
Universal data acquisition framework for embedded systems
objectid.hxx
1// dawn/include/dawn/common/objectid.hxx
2//
3// SPDX-License-Identifier: Apache-2.0
4//
5
6#pragma once
7
8#include <cstdint>
9#include <cstdlib>
10
11#include "dawn/debug.hxx"
12#include "dawn/porting/config.hxx"
13
14namespace dawn
15{
23{
26 constexpr static size_t PRIV_MAX = 0b11111111111111;
27 constexpr static size_t PRIV_SHIFT = 0;
28 constexpr static size_t FLAGS_MAX = 0b11;
29 constexpr static size_t FLAGS_SHIFT = 14;
30 constexpr static size_t DTYPE_MAX = 0b1111;
31 constexpr static size_t DTYPE_SHIFT = 16;
32 constexpr static size_t EXT_MAX = 0b1;
33 constexpr static size_t EXT_SHIFT = 20;
34 constexpr static size_t CLS_MAX = 0b111111111;
35 constexpr static size_t CLS_SHIFT = 21;
36 constexpr static size_t CLS_MASK = (CLS_MAX << CLS_SHIFT);
37 constexpr static size_t TYPE_MAX = 0b11;
38 constexpr static size_t TYPE_SHIFT = 30;
39 constexpr static size_t TYPE_MASK = (TYPE_MAX << TYPE_SHIFT);
40 constexpr static size_t fCLS_ANY = 0;
41
44 typedef uint32_t ObjectId;
45
52 typedef uint64_t ObjectIdExt;
53
60 enum
61 {
69
73
77
81
85
89
93
97
101
105
113
121
129
133
145
154
158 } typedef EObjectDataType;
159
160 static_assert(DTYPE_LAST - 1 <= DTYPE_MAX);
161
168 enum
169 {
177
185
194
203
207 } typedef EObjectIdType;
208
209 static_assert(OBJTYPE_LAST - 1 <= TYPE_MAX);
210
217 union
218 {
222
225 struct
226 {
233 uint32_t priv : 14;
234
241 uint32_t flags : 2;
242
249 uint32_t dtype : 4;
250
257 uint32_t ext : 1;
258
265 uint32_t cls : 9;
266
273 uint32_t type : 2;
274 } s;
275 } typedef UObjectId;
276
290 constexpr static ObjectId objectId(uint8_t type,
291 uint16_t cls,
292 uint8_t dtype,
293 uint8_t flags,
294 uint16_t priv)
295 {
296 DEBUGASSERT(type <= TYPE_MAX);
297 DEBUGASSERT(cls <= CLS_MAX);
298 DEBUGASSERT(dtype <= DTYPE_MAX);
299 DEBUGASSERT(priv <= PRIV_MAX);
300
301 return (((type & TYPE_MAX) << TYPE_SHIFT) | ((cls & CLS_MAX) << CLS_SHIFT) |
302 ((dtype & DTYPE_MAX) << DTYPE_SHIFT) | ((flags & FLAGS_MAX) << FLAGS_SHIFT) |
303 ((priv & PRIV_MAX) << PRIV_SHIFT));
304 }
305
313 constexpr static uint16_t objectIdGetId(const ObjectId objid)
314 {
315 return ((objid >> PRIV_SHIFT) & PRIV_MAX);
316 };
317
325 constexpr static uint8_t objectIdGetFlags(const ObjectId objid)
326 {
327 return ((objid >> FLAGS_SHIFT) & FLAGS_MAX);
328 };
329
337 constexpr static uint8_t objectIdGetDtype(const ObjectId objid)
338 {
339 return ((objid >> DTYPE_SHIFT) & DTYPE_MAX);
340 };
341
349 constexpr static uint16_t objectIdGetCls(const ObjectId objid)
350 {
351 return ((objid >> CLS_SHIFT) & CLS_MAX);
352 };
353
361 constexpr static uint8_t objectIdGetType(const ObjectId objid)
362 {
363 return ((objid >> TYPE_SHIFT) & TYPE_MAX);
364 };
365
375 constexpr static uint32_t objectIdGetNoId(const ObjectId objid)
376 {
377 return objid & (~PRIV_MAX);
378 };
379
387 constexpr static bool objectIsIO(const UObjectId &objid)
388 {
389 return (objid.s.type == OBJTYPE_IO);
390 };
391
399 constexpr static bool objectIsProto(const UObjectId &objid)
400 {
401 return (objid.s.type == OBJTYPE_PROTO);
402 };
403
411 constexpr static bool objectIsProg(const UObjectId &objid)
412 {
413 return (objid.s.type == OBJTYPE_PROG);
414 };
415
423 constexpr static bool objectIsIO(const ObjectId objid)
424 {
425 return objectIdGetType(objid) == OBJTYPE_IO;
426 };
427
435 constexpr static bool objectIsProto(const ObjectId objid)
436 {
437 return objectIdGetType(objid) == OBJTYPE_PROTO;
438 };
439
447 constexpr static bool objectIsProg(const ObjectId objid)
448 {
449 return objectIdGetType(objid) == OBJTYPE_PROG;
450 };
451
461 constexpr static ObjectId objectMask(const ObjectId objid)
462 {
463 return (objid & TYPE_MASK) | (objid & CLS_MASK);
464 };
465
475 static int getDtypeSize_(const EObjectDataType dtype);
476
486 static bool isDtypeSupported(uint8_t dtype);
487
498 static const char *dtypeToString(uint8_t dtype);
499};
500} // Namespace dawn
Out-of-tree user-extension hooks for Dawn.
Definition bindable.hxx:13
32-bit encoded Object ID with type, class, data type, and instance.
Definition objectid.hxx:23
static bool objectIsProto(const ObjectId objid)
Check if object is Protocol type (raw 32-bit version).
Definition objectid.hxx:435
static uint16_t objectIdGetCls(const ObjectId objid)
Extract object class from ObjectID.
Definition objectid.hxx:349
EObjectIdType
Object types in the Dawn framework.
Definition objectid.hxx:169
@ OBJTYPE_PROTO
Protocol object type.
Definition objectid.hxx:193
@ OBJTYPE_LAST
Sentinel value (last valid type + 1).
Definition objectid.hxx:206
@ OBJTYPE_IO
Input/Output object type.
Definition objectid.hxx:184
@ OBJTYPE_PROG
Program/algorithm object type.
Definition objectid.hxx:202
@ OBJTYPE_ANY
Wildcard/metadata object type.
Definition objectid.hxx:176
static const char * dtypeToString(uint8_t dtype)
Convert data type to human-readable string.
Definition objectid.cxx:167
static bool objectIsIO(const UObjectId &objid)
Check if object is I/O type (union structure version).
Definition objectid.hxx:387
static ObjectId objectMask(const ObjectId objid)
Extract type and class mask from ObjectID.
Definition objectid.hxx:461
static uint8_t objectIdGetType(const ObjectId objid)
Extract object type from ObjectID.
Definition objectid.hxx:361
static bool objectIsProto(const UObjectId &objid)
Check if object is Protocol type (raw 32-bit version).
Definition objectid.hxx:399
static uint16_t objectIdGetId(const ObjectId objid)
Extract instance/private field from ObjectID.
Definition objectid.hxx:313
EObjectDataType
Data types supported by Dawn framework.
Definition objectid.hxx:61
@ DTYPE_FLOAT
IEEE 754 single-precision floating point (32-bit).
Definition objectid.hxx:112
@ DTYPE_INT32
Signed 32-bit integer (-2147483648 to 2147483647).
Definition objectid.hxx:92
@ DTYPE_UINT8
Unsigned 8-bit integer (0 to 255).
Definition objectid.hxx:80
@ DTYPE_INT16
Signed 16-bit integer (-32768 to 32767).
Definition objectid.hxx:84
@ DTYPE_INT8
Signed 8-bit integer (-128 to 127).
Definition objectid.hxx:76
@ DTYPE_ANY
Wildcard data type (matches any actual type).
Definition objectid.hxx:68
@ DTYPE_BLOCK
Opaque block/byte-stream data type.
Definition objectid.hxx:153
@ DTYPE_UINT64
Unsigned 64-bit integer.
Definition objectid.hxx:104
@ DTYPE_UINT16
Unsigned 16-bit integer (0 to 65535).
Definition objectid.hxx:88
@ DTYPE_UB16
Unsigned 16.16 fixed-point (32-bit).
Definition objectid.hxx:132
@ DTYPE_DOUBLE
IEEE 754 double-precision floating point (64-bit).
Definition objectid.hxx:120
@ DTYPE_CHAR
Character/string type (null-terminated, 4-byte aligned).
Definition objectid.hxx:144
@ DTYPE_INT64
Signed 64-bit integer.
Definition objectid.hxx:100
@ DTYPE_UINT32
Unsigned 32-bit integer (0 to 4294967295).
Definition objectid.hxx:96
@ DTYPE_BOOL
Boolean data type (stored in 32-bit container).
Definition objectid.hxx:72
@ DTYPE_LAST
Sentinel value (last valid type + 1).
Definition objectid.hxx:157
@ DTYPE_B16
Signed 16.16 fixed-point (32-bit).
Definition objectid.hxx:128
static uint32_t objectIdGetNoId(const ObjectId objid)
Extract "type-agnostic" ObjectID (zero instance field).
Definition objectid.hxx:375
static uint8_t objectIdGetDtype(const ObjectId objid)
Extract data type field from ObjectID.
Definition objectid.hxx:337
static size_t PRIV_MAX
Bit field constants and shift positions for ObjectID extraction.
Definition objectid.hxx:26
static bool objectIsProg(const ObjectId objid)
Check if object is Program type (raw 32-bit version).
Definition objectid.hxx:447
uint64_t ObjectIdExt
Extended ObjectID type - future 64-bit support.
Definition objectid.hxx:52
static bool isDtypeSupported(uint8_t dtype)
Check if a data type is enabled in build configuration.
Definition objectid.cxx:95
uint32_t ObjectId
ObjectID type - single 32-bit value.
Definition objectid.hxx:44
static ObjectId objectId(uint8_t type, uint16_t cls, uint8_t dtype, uint8_t flags, uint16_t priv)
Construct 32-bit ObjectID from component fields.
Definition objectid.hxx:290
static bool objectIsProg(const UObjectId &objid)
Check if object is Program type (raw 32-bit version).
Definition objectid.hxx:411
static bool objectIsIO(const ObjectId objid)
Check if object is I/O type (union structure version).
Definition objectid.hxx:423
static int getDtypeSize_(const EObjectDataType dtype)
Get byte size for a specific data type.
Definition objectid.cxx:12
static uint8_t objectIdGetFlags(const ObjectId objid)
Extract type-specific flags from ObjectID.
Definition objectid.hxx:325
32-bit encoded object identifier (union with bit field).
Definition objectid.hxx:218
uint32_t priv
Instance/private data field (bits 0-13, max 16383).
Definition objectid.hxx:233
ObjectId v
Raw 32-bit ObjectID value (for comparison, hashing, storage).
Definition objectid.hxx:221
uint32_t dtype
Data type field (bits 16-19, see EObjectDataType).
Definition objectid.hxx:249
uint32_t type
Object type field (bits 30-31, see EObjectIdType).
Definition objectid.hxx:273
uint32_t cls
Object class field (bits 21-29, max 511).
Definition objectid.hxx:265
uint32_t flags
Type-specific flags (bits 14-15, max 3).
Definition objectid.hxx:241
uint32_t ext
Extension flag (bit 20).
Definition objectid.hxx:257
struct dawn::SObjectId::UObjectId::@14 s
Bit-field structure for named member access.