libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_flags.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblFlagsClass and API for managing flag types
3 * \ingroup meta
4 *
5 * \author 2023 Falco Girgis
6 * \copyright MIT License
7 */
8#ifndef GIMBAL_FLAGS_H
9#define GIMBAL_FLAGS_H
10
12#include "../../strings/gimbal_quark.h"
13
14/*! \name Type System
15 * \brief Type UUID and cast operators
16 * @{
17 */
18#define GBL_FLAGS_TYPE (GblFlags_type()) //!< GblType UUID for flags
19#define GBL_FLAGS_CLASS(klass) (GBL_CLASS_CAST(GblFlags, klass)) //!< Cast a GblClass to GblFlagsClass
20//! @}
21
22/*! \name Helper Macros
23 * \brief Utility macros to aid in representing GblFlagEntry lists
24 * @{
25 */
26#define GBL_FLAGS_ENTRY(flagsValue, nick) { flagsValue, #flagsValue, nick }
27#define GBL_FLAGS_ENTRY_LAST() { 0, NULL, NULL }
28//! @}
29
30#define GBL_SELF_TYPE GblFlagsClass
31
33
34//! Attributes for a single bit flag value within a group of GblFlag values
35typedef struct GblFlagEntry {
36 GblFlags value; //!< Value of the flag
37 const char* pName; //!< String name of the flag value
38 const char* pNick; //!< Alternat ename of the flag value
39} GblFlagEntry;
40
41/*! \struct GblFlagsClass
42 * \extends GblPrimitiveClass
43 * \brief Static GblClass for storing type data for flags
44 *
45 * GblFlagsClass is a static/persistent class which is created
46 * from a list of GblFlagEntry structures, representing all of
47 * the valid bits for the flag type.
48 */
49GBL_CLASS_DERIVE(GblFlags, GblPrimitive)
50 GblFlags valueMask; //!< Mask of all bits which can be set within the value
51 uint16_t entryCount; //!< Cached number of values in the entry table
53
54// ========== GblFlagsClass ==========
55/*! \name Name Queries
56 * \brief Methods for querying name of flag values
57 * \relatesalso GblFlagsClass
58 * @{
59 */
60GBL_EXPORT const char* GblFlagsClass_nameFromIndex (GBL_CSELF, uint16_t index) GBL_NOEXCEPT;
61GBL_EXPORT const char* GblFlagsClass_nameFromValue (GBL_CSELF, GblFlags value) GBL_NOEXCEPT;
62GBL_EXPORT GblQuark GblFlagsClass_nameQuarkFromIndex (GBL_CSELF, uint16_t index) GBL_NOEXCEPT;
63GBL_EXPORT GblQuark GblFlagsClass_nameQuarkFromValue (GBL_CSELF, GblFlags value) GBL_NOEXCEPT;
64//! @}
65
66/*! \name Nick Queries
67 * \brief Methods for querying nick of flag values
68 * \relatesalso GblFlagsClass
69 * @{
70 */
71GBL_EXPORT const char* GblFlagsClass_nickFromIndex (GBL_CSELF, uint16_t index) GBL_NOEXCEPT;
72GBL_EXPORT const char* GblFlagsClass_nickFromValue (GBL_CSELF, GblFlags value) GBL_NOEXCEPT;
73GBL_EXPORT GblQuark GblFlagsClass_nickQuarkFromIndex (GBL_CSELF, uint16_t index) GBL_NOEXCEPT;
74GBL_EXPORT GblQuark GblFlagsClass_nickQuarkFromValue (GBL_CSELF, GblFlags value) GBL_NOEXCEPT;
75//! @}
76
77/*! \name Value Queries
78 * \brief Methods for querying value of flag values
79 * \relatesalso GblFlagsClass
80 * @{
81 */
82GBL_EXPORT GblFlags GblFlagsClass_valueFromIndex (GBL_CSELF, uint16_t index) GBL_NOEXCEPT;
83GBL_EXPORT GblFlags GblFlagsClass_valueFromName (GBL_CSELF, const char* pName) GBL_NOEXCEPT;
84GBL_EXPORT GblFlags GblFlagsClass_valueFromNick (GBL_CSELF, const char* pNick) GBL_NOEXCEPT;
85GBL_EXPORT GblFlags GblFlagsClass_valueFromNameQuark (GBL_CSELF, GblQuark name) GBL_NOEXCEPT;
86GBL_EXPORT GblFlags GblFlagsClass_valueFromNickQuark (GBL_CSELF, GblQuark nick) GBL_NOEXCEPT;
87GBL_EXPORT GblFlags GblFlagsClass_valueFromString (GBL_CSELF, const char* pString) GBL_NOEXCEPT;
88
89GBL_EXPORT GblBool GblFlagsClass_valueCheck (GBL_CSELF, GblFlags value) GBL_NOEXCEPT;
90
91GBL_EXPORT GBL_RESULT GblFlagsClass_valueAppendString (GBL_CSELF,
92 GblFlags value,
93 GblStringBuffer* pStr) GBL_NOEXCEPT;
94//! @}
95
96// ========== GblFlags ==========
97GBL_EXPORT GblType GblFlags_type (void) GBL_NOEXCEPT;
98
99GBL_EXPORT GblType GblFlags_register (const char* pName,
100 const GblFlagEntry* pEntries) GBL_NOEXCEPT;
101/*! \name Flags from Strings
102 * \brief Methods for getting a flags value from string
103 * @{
104 */
105GBL_EXPORT GblFlags GblFlags_fromName (const char* pName, GblType type) GBL_NOEXCEPT;
106GBL_EXPORT GblFlags GblFlags_fromNameQuark (GblQuark name, GblType type) GBL_NOEXCEPT;
107GBL_EXPORT GblFlags GblFlags_fromNick (const char* pNick, GblType type) GBL_NOEXCEPT;
108GBL_EXPORT GblFlags GblFlags_fromNickQuark (GblQuark nick, GblType type) GBL_NOEXCEPT;
109GBL_EXPORT GblFlags GblFlags_fromString (const char* pName, GblType type) GBL_NOEXCEPT;
110//! @}
111
112/*! \name Enums to Strings
113 * \brief Methods for getting a string from a flags value
114 * @{
115 */
116GBL_EXPORT const char* GblFlags_name (GblFlags value, GblType type) GBL_NOEXCEPT;
117GBL_EXPORT GblQuark GblFlags_nameQuark (GblFlags value, GblType type) GBL_NOEXCEPT;
118GBL_EXPORT const char* GblFlags_nick (GblFlags value, GblType type) GBL_NOEXCEPT;
119GBL_EXPORT GblQuark GblFlags_nickQuark (GblFlags value, GblType type) GBL_NOEXCEPT;
120//! @}
121
122GBL_EXPORT GblBool GblFlags_check (GblFlags value, GblType type) GBL_NOEXCEPT;
123GBL_EXPORT GBL_RESULT GblFlags_appendString (GblFlags value,
124 GblType type,
125 GblStringBuffer* pBuffer) GBL_NOEXCEPT;
126
128
129#undef GBL_SELF_TYPE
130
131#endif // GIMBAL_FLAGS_H
#define GBL_CLASS_CAST(cType, klass)
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_CLASS_DERIVE(...)
#define GBL_EXPORT
#define GBL_CLASS_END
uint32_t GblFlags
Standard-sized flags type, 32-bits across platforms.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51
uintptr_t GblQuark
Uniquely identifiable interned string type.
Attributes for a single bit flag value within a group of GblFlag values.
const char * pName
String name of the flag value.
GblFlags value
Value of the flag.
const char * pNick
Alternat ename of the flag value.
GblFlags valueMask
Mask of all bits which can be set within the value.
uint16_t entryCount
Cached number of values in the entry table.