libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_ivariant.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblIVariant interface for GblVariant compatibility
3 * \ingroup interfaces
4 *
5 * \todo
6 * - Shouldn't the RHS variant automatically be invalidated after a "move" operation?
7 *
8 * \author 2023 Falco Girgis
9 * \copyright MIT License
10 */
11
12#ifndef GIMBAL_IVARIANT_H
13#define GIMBAL_IVARIANT_H
14
16#include <stdarg.h>
17
18/*! \name Type System
19 * \brief Type UUID and cast operators
20 * @{
21 */
22#define GBL_IVARIANT_TYPE (GBL_BUILTIN_TYPE(IVARIANT))
23#define GBL_IVARIANT(instance) ((GblIVariant*)GblInstance_cast(GBL_INSTANCE(instance), GBL_IVARIANT_TYPE))
24#define GBL_IVARIANT_CLASS(klass) ((GblIVariantClass*)GblClass_cast(GBL_CLASS(klass), GBL_IVARIANT_TYPE))
25#define GBL_IVARIANT_GET_CLASS(instance) (GBL_IVARIANT_CLASS(GblInstance_class(GBL_INSTANCE(instance))))
26//! @}
27
28#define GBL_IVARIANT_VALUE_VAR_ARG_MAX 4
29
31
33GBL_FORWARD_DECLARE_STRUCT(GblStringBuffer);
34
35GBL_DECLARE_FLAGS(GBL_IVARIANT_OP_FLAGS) {
36 GBL_IVARIANT_OP_FLAG_RELOCATABLE = 0x00001,
37 GBL_IVARIANT_OP_FLAG_CONSTRUCT_DEFAULT = 0x00002,
38 GBL_IVARIANT_OP_FLAG_CONSTRUCT_COPY = 0x00004,
39 GBL_IVARIANT_OP_FLAG_CONSTRUCT_MOVE = 0x00008,
40 GBL_IVARIANT_OP_FLAG_CONSTRUCT_VALUE_COPY = 0x00010,
41 GBL_IVARIANT_OP_FLAG_CONSTRUCT_VALUE_MOVE = 0x00020,
42 GBL_IVARIANT_OP_FLAG_CONSTRUCT_MASK = 0x0003e,
43 GBL_IVARIANT_OP_FLAG_SET_COPY = 0x00040,
44 GBL_IVARIANT_OP_FLAG_SET_MOVE = 0x00080,
45 GBL_IVARIANT_OP_FLAG_SET_VALUE_COPY = 0x00100,
46 GBL_IVARIANT_OP_FLAG_SET_VALUE_MOVE = 0x00200,
47 GBL_IVARIANT_OP_FLAG_SET_MASK = 0x003c0,
48 GBL_IVARIANT_OP_FLAG_GET_VALUE_COPY = 0x00400,
49 GBL_IVARIANT_OP_FLAG_GET_VALUE_PEEK = 0x00800,
50 GBL_IVARIANT_OP_FLAG_GET_VALUE_MOVE = 0x01000,
51 GBL_IVARIANT_OP_FLAG_GET_MASK = 0x01c00,
52 GBL_IVARIANT_OP_FLAG_VALUELESS_TYPE = 0x40000
53};
54
55#define VARIANT GblVariant* pVariant
56#define CVARIANT const VARIANT
57
58//! Virtual method table for GblIVariantClass
59typedef struct GblIVariantVTable {
60 GBL_IVARIANT_OP_FLAGS supportedOps;
61 char pSetValueFmt[GBL_IVARIANT_VALUE_VAR_ARG_MAX];
62 char pGetValueFmt[GBL_IVARIANT_VALUE_VAR_ARG_MAX];
63
64 GBL_RESULT (*pFnConstruct)(VARIANT, size_t argc, GblVariant* pArgs, GBL_IVARIANT_OP_FLAGS op);
65 GBL_RESULT (*pFnDestruct) (VARIANT);
66 GBL_RESULT (*pFnSet) (VARIANT, size_t argc, GblVariant* pArgs, GBL_IVARIANT_OP_FLAGS op);
67 GBL_RESULT (*pFnGet) (VARIANT, size_t argc, GblVariant* pArgs, GBL_IVARIANT_OP_FLAGS op);
68 GBL_RESULT (*pFnCompare) (CVARIANT, const GblVariant* pOther, int* pResult);
69 GBL_RESULT (*pFnSave) (CVARIANT, GblStringBuffer* pString);
70 GBL_RESULT (*pFnLoad) (VARIANT, const GblStringBuffer* pString);
71} GblIVariantVTable;
72
73/*! \struct GblIVariantClass
74 * \extends GblInterface
75 * \brief GblInterface for GblVariant type compatibilty
76 *
77 * GblIVariantClass represents an interface that must
78 * be implemented by any type wishing to be stored
79 * within, convertible to/from, or compatible with a
80 * GblVariant in any way.
81 *
82 * \sa GblVariant
83 */
85 const GblIVariantVTable* pVTable;
87
88#define GBL_SELF_TYPE GblIVariantClass
89#define GBL_KEY const GblVariant* pKey
90#define GBL_VALUE GblVariant* pValue
91
92GBL_EXPORT GBL_RESULT GblIVariantClass_validate (GBL_CSELF) GBL_NOEXCEPT;
93GBL_EXPORT GBL_RESULT GblIVariantClass_constructDefault (GBL_CSELF, VARIANT) GBL_NOEXCEPT;
94GBL_EXPORT GBL_RESULT GblIVariantClass_constructCopy (GBL_CSELF, VARIANT, const GblVariant* pOther) GBL_NOEXCEPT;
95GBL_EXPORT GBL_RESULT GblIVariantClass_constructMove (GBL_CSELF, VARIANT, GblVariant* pOther) GBL_NOEXCEPT;
96GBL_EXPORT GBL_RESULT GblIVariantClass_constructValueCopy (GBL_CSELF, VARIANT, va_list* pVarArgs) GBL_NOEXCEPT;
97GBL_EXPORT GBL_RESULT GblIVariantClass_constructValueMove (GBL_CSELF, VARIANT, va_list* pVarArgs) GBL_NOEXCEPT;
98GBL_EXPORT GBL_RESULT GblIVariantClass_setCopy (GBL_CSELF, VARIANT, const GblVariant* pOther) GBL_NOEXCEPT;
99GBL_EXPORT GBL_RESULT GblIVariantClass_setMove (GBL_CSELF, VARIANT, GblVariant* pOther) GBL_NOEXCEPT;
100GBL_EXPORT GBL_RESULT GblIVariantClass_setValueCopy (GBL_CSELF, VARIANT, va_list* pVarArgs) GBL_NOEXCEPT;
101GBL_EXPORT GBL_RESULT GblIVariantClass_setValueMove (GBL_CSELF, VARIANT, va_list* pVarArgs) GBL_NOEXCEPT;
102GBL_EXPORT GBL_RESULT GblIVariantClass_getValueCopy (GBL_CSELF, CVARIANT, va_list* pVarArgs) GBL_NOEXCEPT;
103GBL_EXPORT GBL_RESULT GblIVariantClass_getValuePeek (GBL_CSELF, CVARIANT, va_list* pVarArgs) GBL_NOEXCEPT;
104GBL_EXPORT GBL_RESULT GblIVariantClass_getValueMove (GBL_CSELF, CVARIANT, va_list* pVarArgs) GBL_NOEXCEPT;
105GBL_EXPORT GBL_RESULT GblIVariantClass_destruct (GBL_CSELF, VARIANT) GBL_NOEXCEPT;
106
107GBL_EXPORT GBL_RESULT GblIVariantClass_compare (GBL_CSELF,
108 CVARIANT,
109 const GblVariant* pOther,
110 int* pCmpResult) GBL_NOEXCEPT;
111
112GBL_EXPORT GBL_RESULT GblIVariantClass_save (GBL_CSELF, CVARIANT, GblStringBuffer* pString) GBL_NOEXCEPT;
113
114GBL_EXPORT GBL_RESULT GblIVariantClass_load (GBL_CSELF,
115 VARIANT,
116 const GblStringBuffer* pString) GBL_NOEXCEPT;
117
118#undef CVARIANT
119#undef VARIANT
120
121#undef GBL_SELF_TYPE
122#undef GBL_KEY
123#undef GBL_VALUE
124
126
127#endif // GIMBAL_IVARIANT_H
#define GBL_BUILTIN_TYPE(prefix)
Returns a type from the macro prefix of a builtin type.
#define GBL_CLASS(klass)
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_INTERFACE_END
#define GBL_INTERFACE_DERIVE(...)
#define GBL_DECLARE_FLAGS(F)
#define GBL_EXPORT
#define GBL_IVARIANT_TYPE
#define GBL_IVARIANT_CLASS(klass)
#define CVARIANT
#define GBL_IVARIANT_VALUE_VAR_ARG_MAX
#define VARIANT
Virtual method table for GblIVariantClass.