libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_bit_struct.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblBitStructClass and API for managing bitfields
3 * \ingroup meta
4 *
5 * This file contains the type definition for GblBitStructClass,
6 * which enables a 32 to 64-bit integer to be accessed via a
7 * GblVariant as though it were a regular structure type with
8 * string-type keys and values of arbitrary type.
9 *
10 * \author 2023 Falco Girgis
11 * \copyright MIT License
12 */
13#ifndef GIMBAL_BIT_STRUCT_H
14#define GIMBAL_BIT_STRUCT_H
15
17#include "../ifaces/gimbal_itable_variant.h"
18
19#define GBL_BIT_STRUCT_TYPE (GBL_TYPEID(GblBitStruct))
20#define GBL_BIT_STRUCT_CLASS(klass) (GBL_CLASS_CAST(GblBitStruct, klass))
21
22#define GBL_BIT_STRUCT_ENTRY(name, mask, type) { name, mask, type }
23#define GBL_BIT_STRUCT_LAST() { 0, 0x00, GBL_INVALID_TYPE }
24
25#define GBL_SELF_TYPE GblBitStructClass
26
28
29typedef uint64_t GblBitStruct;
30
31//! Contains meta data for a single field of a GblBitStruct
32typedef struct GblBitStructField {
33 const char* pName; //!< Field name
34 GblBitmask mask; //!< Field mask
35 GblType valueType; //!< Field value
36} GblBitStructField;
37
38// Should we just give them properties?!
39GBL_CLASS_DERIVE(GblBitStruct, GblPrimitive, GblITableVariant)
40 GBL_RESULT (*pFnCheckFieldValue)(GBL_CSELF, size_t fieldIndex, const GblVariant* pValue);
41 GblBitmask valueMask;
42 size_t fieldCount;
44
45GBL_EXPORT GBL_DECLARE_TYPE(GblBitStruct);
46
47/*! \name Field Name
48 * \brief Methods for retrieving field name
49 * \relatesalso GblBitStructClass
50 * @{
51 */
52GBL_EXPORT const char* GblBitStructClass_nameFromIndex (GBL_CSELF, size_t index) GBL_NOEXCEPT;
53GBL_EXPORT const char* GblBitStructClass_nameFromBitmask (GBL_CSELF, GblBitmask msk) GBL_NOEXCEPT;
54GBL_EXPORT GblQuark GblBitStructClass_nameQuarkFromIndex (GBL_CSELF, size_t index) GBL_NOEXCEPT;
55GBL_EXPORT GblQuark GblBitStructClass_nameQuarkFromBitmask (GBL_CSELF, GblBitmask msk) GBL_NOEXCEPT;
56//! @}
57
58/*! \name Field Mask
59 * \brief Methods for retrieving field mask
60 * \relatesalso GblBitStructClass
61 * @{
62 */
63GBL_EXPORT GblBitmask GblBitStructClass_maskFromIndex (GBL_CSELF, size_t index) GBL_NOEXCEPT;
64GBL_EXPORT GblBitmask GblBitStructClass_maskFromName (GBL_CSELF, const char* pName) GBL_NOEXCEPT;
65GBL_EXPORT GblBitmask GblBitStructClass_maskFromNameQuark (GBL_CSELF, GblQuark quark) GBL_NOEXCEPT;
66//! @}
67
68/*! \name Field Type
69 * \brief Methods for retrieving field type
70 * \relatesalso GblBitStructClass
71 * @{
72 */
73GBL_EXPORT GblType GblBitStructClass_typeFromIndex (GBL_CSELF, size_t index) GBL_NOEXCEPT;
74GBL_EXPORT GblType GblBitStructClass_typeFromName (GBL_CSELF, const char* pName) GBL_NOEXCEPT;
75GBL_EXPORT GblType GblBitStructClass_typeFromNameQuark (GBL_CSELF, GblQuark quark) GBL_NOEXCEPT;
76GBL_EXPORT GblType GblBitStructClass_typeFromBitmask (GBL_CSELF, GblBitmask msk) GBL_NOEXCEPT;
77//! @}
78
79#if 0
80
81GBL_EXPORT GblBool GblBitStructClass_checkValueForIndex (GBL_CSELF, size_t index, GblVariant* pValue) GBL_NOEXCEPT;
82GBL_EXPORT GblBool GblBitStructClass_checkValueForName (GBL_CSELF, const char* pName, GblVariant* pValue) GBL_NOEXCEPT;
83GBL_EXPORT GblBool GblBitStructClass_checkValueForNameQuark (GBL_CSELF, GblQuark quark, GblVariant* pValue) GBL_NOEXCEPT;
84GBL_EXPORT GblBool GblBitStructClass_checkValueForBitmask (GBL_CSELF, GblBitmask msk, GblVariant* pValue) GBL_NOEXCEPT;
85
86GBL_EXPORT GblBool GblBitStructClass_checkValue (GBL_CSELF, uint64_t value) GBL_NOEXCEPT;
87
88GBL_EXPORT GblBool GblBitStruct_checkValue(GblBitStruct value, GblType type);
89
90GBL_EXPORT GBL_RESULT GblBitStruct_field(GblBitStruct value, GblType type, const char* pName, ...);
91GBL_EXPORT GBL_RESULT GblBitStruct_mask(GblBitStruct value, GblType type, GblBitmask mask, ...);
92GBL_EXPORT GBL_RESULT GblBitStruct_index(GblBitStruct value, GblType type, size_t index, ...);
93
94GBL_EXPORT GBL_RESULT GblBitStruct_fields(GblBitStruct value, GblType type, ...);
95GBL_EXPORT GBL_RESULT GblBitStruct_masks(GblBitStruct value, GblType type, ...);
96GBL_EXPORT GBL_RESULT GblBitStruct_indices(GblBitStruct value, GblType type, ...);
97
98GBL_EXPORT GBL_RESULT GblBitStruct_setField(GblBitStruct* pValue, GblType type, const char* pName, ...);
99GBL_EXPORT GBL_RESULT GblBitStruct_setMask(GblBitStruct* pValue, GblType type, GblBitmask mask, ...);
100GBL_EXPORT GBL_RESULT GblBitStruct_setIndex(GblBitStruct* pValue, GblType type, size_t index, ...);
101
102GBL_EXPORT GBL_RESULT GblBitStruct_setFields(GblBitStruct* pValue, GblType type, const char* pName, ...);
103GBL_EXPORT GBL_RESULT GblBitStruct_setMasks(GblBitStruct* pValue, GblType type, GblBitmask mask, ...);
104GBL_EXPORT GBL_RESULT GblBitStruct_setIndices(GblBitStruct* pValue, GblType type, size_t index, ...);
105
106// Returns key type based on type of empty value first passed in?
107GBL_EXPORT GBL_RESULT GblBitStruct_next(GblBitStruct value, GblType type, GblVariant* pkey, GblVariant* pValue);
108
109#endif
110GBL_EXPORT GblType GblBitStruct_register(const char* pName, const GblBitStructField* pFields) GBL_NOEXCEPT;
111
113
114#undef GBL_SELF_TYPE
115
116#endif // GIMBAL_BIT_STRUCT_H
#define GBL_CLASS_CAST(cType, klass)
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_TYPEID(instanceStruct)
#define GBL_CLASS_DERIVE(...)
#define GBL_DECLARE_TYPE(instanceStruct)
#define GBL_EXPORT
#define GBL_CLASS_END
#define GBL_INVALID_TYPE
GblType UUID of the invalid type.
Definition gimbal_type.h:31
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51
uintptr_t GblQuark
Uniquely identifiable interned string type.
Contains meta data for a single field of a GblBitStruct.
GblType valueType
Field value.
const char * pName
Field name.
GblBitmask mask
Field mask.