libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_settings.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblSettings user configuration management and persistence
3 * \ingroup utils
4 * \todo
5 * - marshal values to signals
6 * - array handling
7 * - swap GblHashSet out for GblTreeSet
8 * - rig up properties
9 *
10 * \author 2023 Falco Girgis
11 * \copyright MIT License
12 */
13#ifndef GIMBAL_SETTINGS_H
14#define GIMBAL_SETTINGS_H
15
16#include "../meta/instances/gimbal_object.h"
17#include "../meta/signals/gimbal_signal.h"
18
19/*! \name Type System
20 * \brief Type UUID and cast operators
21 * @{
22 */
23#define GBL_SETTINGS_TYPE (GBL_TYPEID(GblSettings))
24#define GBL_SETTINGS(self) (GBL_CAST(GblSettings, self))
25#define GBL_SETTINGS_CLASS(klass) (GBL_CLASS_CAST(GblSettings, klass))
26#define GBL_SETTINGS_GET_CLASS(self) (GBL_CLASSOF(GblSettings, self))
27//! @}
28
29#define GBL_SELF_TYPE GblSettings
30
32
33/*! \enum GBL_SETTINGS_STATUS
34 * \brief Status code for GblSettings state (\ref GblSettings::status)
35 */
39 GBL_SETTINGS_STATUS_ERROR_FORMAT //!< Format Error
40};
41
42/*! \struct GblSettingsClass
43 * \extends GblObjectClass
44 * \brief GblClass VTable structure for GblSettings
45 *
46 * Provides a polymorphic virtual table allowing the
47 * top-level save and load routines to be reimplemented,
48 * as well as reading and writing values from and to the
49 * internal data structure.
50 *
51 * \sa GblSettings
52 */
53GBL_CLASS_DERIVE(GblSettings, GblObject)
54 GBL_RESULT (*pFnSave) (GBL_SELF);
55 GBL_RESULT (*pFnLoad) (GBL_SELF);
56 GBL_RESULT (*pFnWrite)(GBL_SELF, const char* pKey, GblVariant* pValue);
57 GBL_RESULT (*pFnRead) (GBL_SELF, const char* pKey, GblVariant* pValue);
59
60/*! \struct GblSettings
61 * \extends GblObject
62 * \ingroup utils
63 * \brief User-settings data management and persistence
64 *
65 * GblSettings provides a mechanism through which user
66 * and application settings can be accessed uniformly
67 * and serialized and deserialized from some common
68 * format.
69 *
70 * \sa GblSettingsClass
71 */
73 GblStringRef* pPath;
74 GblStringRef* pAppName;
75 GblStringRef* pOrgName;
77 GblBool dirty;
79
80//! \cond
81GBL_PROPERTIES(GblSettings,
82 (appName, GBL_GENERIC, (READ, WRITE), GBL_STRING_TYPE),
83 (orgName, GBL_GENERIC, (READ, WRITE), GBL_STRING_TYPE),
84 (path, GBL_GENERIC, (READ, WRITE), GBL_STRING_TYPE),
85 (scope, GBL_GENERIC, (READ, WRITE), GBL_STRING_TYPE),
86 (status, GBL_GENERIC, (READ), GBL_ENUM_TYPE),
87 (dirty, GBL_GENERIC, (READ), GBL_BOOL_TYPE)
88)
89
90GBL_SIGNALS(GblSettings,
91 (added, (receiver, GBL_INSTANCE_TYPE), (key, GBL_STRING_TYPE)),
92 (removed, (receiver, GBL_INSTANCE_TYPE), (key, GBL_STRING_TYPE)),
93 (changed, (receiver, GBL_INSTANCE_TYPE), (key, GBL_STRING_TYPE)),
94 (saved, (receiver, GBL_INSTANCE_TYPE), (result, GBL_ENUM_TYPE)),
95 (loaded, (receiver, GBL_INSTANCE_TYPE), (result, GBL_ENUM_TYPE))
96)
97//! \endcond
98
99GBL_EXPORT GblType GblSettings_type (void) GBL_NOEXCEPT;
100
101GBL_EXPORT GblSettings* GblSettings_create (void) GBL_NOEXCEPT;
102GBL_EXPORT GblSettings* GblSettings_ref (GBL_CSELF) GBL_NOEXCEPT;
103GBL_EXPORT GblRefCount GblSettings_unref (GBL_SELF) GBL_NOEXCEPT;
104
105GBL_EXPORT const char* GblSettings_scope (GBL_CSELF) GBL_NOEXCEPT;
106GBL_EXPORT const char* GblSettings_pushScope (GBL_SELF, const char* pPrefix) GBL_NOEXCEPT;
107GBL_EXPORT void GblSettings_pushArray (GBL_SELF, const char* pName, size_t size) GBL_NOEXCEPT;
108GBL_EXPORT const char* GblSettings_pop (GBL_SELF) GBL_NOEXCEPT;
109GBL_EXPORT GBL_RESULT GblSettings_setArrayIndex (GBL_SELF, size_t index) GBL_NOEXCEPT;
110
111GBL_EXPORT GBL_RESULT GblSettings_sync (GBL_SELF) GBL_NOEXCEPT;
112
113GBL_EXPORT GBL_RESULT GblSettings_variant (GBL_CSELF, const char* pKey, GblVariant* pVariant) GBL_NOEXCEPT;
114GBL_EXPORT GBL_RESULT GblSettings_toValue (GBL_CSELF, const char* pKey, GblType type, ...) GBL_NOEXCEPT;
115GBL_EXPORT GblType GblSettings_typeOf (GBL_CSELF, const char* pKey) GBL_NOEXCEPT;
116
117GBL_EXPORT GblBool GblSettings_isNil (GBL_CSELF, const char* pKey) GBL_NOEXCEPT;
118GBL_EXPORT GblBool GblSettings_toBool (GBL_CSELF, const char* pKey, GblBool defaultValue) GBL_NOEXCEPT;
119GBL_EXPORT char GblSettings_toChar (GBL_CSELF, const char* pKey, char defaultValue) GBL_NOEXCEPT;
120GBL_EXPORT uint8_t GblSettings_toUint8 (GBL_CSELF, const char* pKey, uint8_t defaultValue) GBL_NOEXCEPT;
121GBL_EXPORT uint16_t GblSettings_toUint16 (GBL_CSELF, const char* pKey, uint16_t defaultValue) GBL_NOEXCEPT;
122GBL_EXPORT int16_t GblSettings_toInt16 (GBL_CSELF, const char* pKey, int16_t defaultValue) GBL_NOEXCEPT;
123GBL_EXPORT uint32_t GblSettings_toUint32 (GBL_CSELF, const char* pKey, uint32_t defaultValue) GBL_NOEXCEPT;
124GBL_EXPORT int32_t GblSettings_toInt32 (GBL_CSELF, const char* pKey, int32_t defaultValue) GBL_NOEXCEPT;
125GBL_EXPORT uint32_t GblSettings_toUint64 (GBL_CSELF, const char* pKey, uint32_t defaultValue) GBL_NOEXCEPT;
126GBL_EXPORT int32_t GblSettings_toInt64 (GBL_CSELF, const char* pKey, int32_t defaultValue) GBL_NOEXCEPT;
127GBL_EXPORT size_t GblSettings_toSize (GBL_CSELF, const char* pkey, size_t defaultValue) GBL_NOEXCEPT;
128GBL_EXPORT GblEnum GblSettings_toEnum (GBL_CSELF, const char* pKey, GblEnum defaultValue) GBL_NOEXCEPT;
129GBL_EXPORT GblFlags GblSettings_toFlags (GBL_CSELF, const char* pKey, GblFlags defaultValue) GBL_NOEXCEPT;
130GBL_EXPORT float GblSettings_toFloat (GBL_CSELF, const char* pKey, float defaultValue) GBL_NOEXCEPT;
131GBL_EXPORT double GblSettings_toDouble (GBL_CSELF, const char* pKey, double defaultValue) GBL_NOEXCEPT;
132GBL_EXPORT void* GblSettings_toPointer (GBL_CSELF, const char* pKey, void* pDefaultValue) GBL_NOEXCEPT;
133GBL_EXPORT const char* GblSettings_toString (GBL_CSELF, const char* pKey, const char* pDefValue) GBL_NOEXCEPT;
134GBL_EXPORT GblType GblSettings_toType (GBL_CSELF, const char* pKey, GblType defaultValue) GBL_NOEXCEPT;
135
136GBL_EXPORT GBL_RESULT GblSettings_setNil (GBL_SELF, const char* pKey) GBL_NOEXCEPT;
137GBL_EXPORT GBL_RESULT GblSettings_setBool (GBL_SELF, const char* pKey, GblBool value) GBL_NOEXCEPT;
138GBL_EXPORT GBL_RESULT GblSettings_setChar (GBL_SELF, const char* pKey, char value) GBL_NOEXCEPT;
139GBL_EXPORT GBL_RESULT GblSettings_setUint8 (GBL_SELF, const char* pKey, uint8_t value) GBL_NOEXCEPT;
140GBL_EXPORT GBL_RESULT GblSettings_setUint16 (GBL_SELF, const char* pKey, uint16_t value) GBL_NOEXCEPT;
141GBL_EXPORT GBL_RESULT GblSettings_setInt16 (GBL_SELF, const char* pKey, int16_t value) GBL_NOEXCEPT;
142GBL_EXPORT GBL_RESULT GblSettings_setUint32 (GBL_SELF, const char* pKey, uint32_t value) GBL_NOEXCEPT;
143GBL_EXPORT GBL_RESULT GblSettings_setInt32 (GBL_SELF, const char* pKey, int32_t value) GBL_NOEXCEPT;
144GBL_EXPORT GBL_RESULT GblSettings_setUint64 (GBL_SELF, const char* pKey, uint64_t value) GBL_NOEXCEPT;
145GBL_EXPORT GBL_RESULT GblSettings_setInt64 (GBL_SELF, const char* pKey, int64_t value) GBL_NOEXCEPT;
146GBL_EXPORT GBL_RESULT GblSettings_setSize (GBL_SELF, const char* pKey, size_t value) GBL_NOEXCEPT;
147GBL_EXPORT GBL_RESULT GblSettings_setEnum (GBL_SELF, const char* pKey, GblType type, GblEnum val) GBL_NOEXCEPT;
148GBL_EXPORT GBL_RESULT GblSettings_setFlags (GBL_SELF, const char* pKey, GblType type, GblFlags val) GBL_NOEXCEPT;
149GBL_EXPORT GBL_RESULT GblSettings_setFloat (GBL_SELF, const char* pKey, float value) GBL_NOEXCEPT;
150GBL_EXPORT GBL_RESULT GblSettings_setDouble (GBL_SELF, const char* pKey, double value) GBL_NOEXCEPT;
151GBL_EXPORT GBL_RESULT GblSettings_setPointer (GBL_SELF, const char* pKey, void* pValue) GBL_NOEXCEPT;
152GBL_EXPORT GBL_RESULT GblSettings_setString (GBL_SELF, const char* pKey, const char* pValue) GBL_NOEXCEPT;
153GBL_EXPORT GBL_RESULT GblSettings_setType (GBL_SELF, const char* pKey, GblType value) GBL_NOEXCEPT;
154
155#undef GBL_SELF_TYPE
156
157#endif // GIMBAL_SETTINGS_H
#define GBL_CLASS_CAST(cType, klass)
#define GBL_NOEXCEPT
#define GBL_SELF
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_TYPEID(instanceStruct)
#define GBL_INSTANCE_DERIVE(derivedInstance, baseInstance)
#define GBL_DECLARE_ENUM(E)
#define GBL_CLASS_DERIVE(...)
#define GBL_INSTANCE_END
#define GBL_EXPORT
#define GBL_CLASS_END
#define GBL_ENUM_TYPE
Type UUID of GblEnumClass.
Definition gimbal_enum.h:22
#define GBL_CLASSOF(cType, self)
#define GBL_CAST(cType, self)
#define GBL_STRING_TYPE
Builtin ID for string GblVariant type.
#define GBL_BOOL_TYPE
Builtin ID for boolean GblVariant type.
#define GBL_PROPERTIES(object,...)
Declares a list of properties for the given object/instance structure.
GBL_SETTINGS_STATUS
Status code for GblSettings state (GblSettings::status)
@ GBL_SETTINGS_STATUS_ERROR_FORMAT
Format Error.
@ GBL_SETTINGS_STATUS_ERROR_FILE
File Error.
@ GBL_SETTINGS_STATUS_OK
OK.
#define GBL_SIGNALS(instanceStruct,...)
uint32_t GblEnum
Standard-sized enum type, 32-bits across platforms.
uint32_t GblFlags
Standard-sized flags type, 32-bits across platforms.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
uint16_t GblRefCount
Type able to hold a reference counter across the codebase.
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51
const char GblStringRef
Reference-counted, const char*-compatible string type.
User-settings data management and persistence.