libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_variant.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblVariant structure and related functions
3 * \ingroup meta
4 *
5 * This file contains the GblVariant type and its associated API.
6 * GblVariant is the core, fundamental dynamically-typed structure
7 * capable of representing any type that is known to the type system
8 * uniformly.
9 *
10 * The convenience wrappers provide a wide variety of methods around
11 * a set of fundamental, low-level calls, which perform standard
12 * GblVariant lifetime and value management in a type-generic way:
13 *
14 * GblVariant v;
15 *
16 * // Always construct a variant before using it
17 * GblVariant_constructValueCopy(&v GBL_FLOAT_TYPE, -17.0f);
18 *
19 * // You can now fetch its value as a float
20 * float f = 0.0f;
21 * GblVariant_valueCopy(&v, GBL_FLOAT_TYPE, &f); // or GblVariant_float()
22 * GBL_ASSERT(f == -17.0f);
23 *
24 * // You can now freely assign and change its value
25 * // Lets do so by "moving" a reference to a GblObject into it
26 * GblVariant_setValueMove(&v, GBL_OBJECT_TYPE, GBL_NEW(GblObject));
27 *
28 * // ALWAYS call the destructor when it leaves scope to free resources
29 * // this will release the otherwise leaked reference to the new GblObject
30 * GblVariant_destruct(&v);
31 *
32 * \todo
33 * - function call operator()? Or call into a Closure?
34 * - serializing/deserializing
35 * - Ensure unregistering a type also removes its converters
36 * - when you have an instance/box/object type, have to propagate inner type to box's outer type
37 *
38 * \author 2023 Falco Girgis
39 * \copyright MIT License
40 */
41#ifndef GIMBAL_VARIANT_H
42#define GIMBAL_VARIANT_H
43
44#include "../../core/gimbal_typedefs.h"
45#include "../../core/gimbal_ctx.h"
46#include "../../strings/gimbal_string_ref.h"
47#include "gimbal_pointer.h"
48#include "../classes/gimbal_primitives.h"
49#include "../classes/gimbal_enum.h"
50#include "../classes/gimbal_flags.h"
51#include "../classes/gimbal_opaque.h"
52#include "../instances/gimbal_instance.h"
53
54//! Convience macro for GblVariant value initialization
55#define GBL_VARIANT_INIT { .type = GBL_INVALID_TYPE }
56//! Convience macro for declaring and initalizing a GblVariant
57#define GBL_VARIANT(name) GblVariant name = GBL_VARIANT_INIT
58
59//! Convenience macro providing a generically-typed constructor method
60#define GblVariant_construct(/*pVariant,*/ ...) GblVariant_construct_(__VA_ARGS__)
61 //! Convenience macro providing a generically-typed assignment method
62#define GblVariant_set(pVariant, ...) GblVariant_set_(pVariant, __VA_ARGS__)
63
64#define GBL_SELF_TYPE GblVariant
65
67
70
71//! Function signature for a type converter to be used with GblVariant_registerConverter()
72typedef GBL_RESULT (*GblVariantConverterFn)(GBL_CSELF, GblVariant* pOther);
73
74/*! \brief Contains a single generic, dynamically typed value
75 * \ingroup meta
76 *
77 * GblVariant is a type-tagged union capable of representing
78 * any type within the type system which implements the \ref
79 * GblIVariantClass interface.
80 *
81 * For the table-like accessors such as GblVariant_index() and
82 * GblVariant_setIndex(), the type must additionally implement
83 * the \ref GblITableVariantClass interface.
84 *
85 * \warning
86 * All fields within the structure are PRIVATE. You should
87 * ALWAYS use the API, which carefully manages lifetimes,
88 * conversions, validation, range-checking, and more rather
89 * than reaching directly for its members. The exception to
90 * this rule is when writing an actual implementation of
91 * GblIVariantClass for a type.
92 *
93 * \sa GblIVariantClass, GblITableVariantClass
94 */
95typedef struct GblVariant {
96 GblType type; //!< GblType UUID
97 union {
98 char character; //!< char value
99 GblBool boolean; //!< boolean value
100 uint8_t u8; //!< uint8_t value
101 uint16_t u16; //!< uint16_t value
102 int16_t i16; //!< int16_t value
103 uint32_t u32; //!< uint32_t value
104 int32_t i32; //!< int32_t value
105 uint64_t u64; //!< uint64_t value
106 int64_t i64; //!< int64_t value
107 GblEnum enumeration; //!< enum value
108 GblFlags flags; //!< GblFlags value
109 float f32; //!< float avlue
110 double f64; //!< double value
111 void* pVoid; //!< void* value
112 GBL_RESULT result; //!< GBL_RESULT value
113 GblFnPtr pFnPtr; //!< function pointer value
114 GblStringRef* pString; //!< GblStringRef value
115 GblType typeValue; //!< GblType value
116 GblBitmask bitmask; //!< GblBitmask value
117 GblDateTime* pDateTime; //!< GblDateTime value
118 GblInstance* pInstance; //!< GblInstance* value
119 GblBox* pBox; //!< GblBox* value
120 GblObject* pObject; //!< GblObject* value
121 };
122} GblVariant;
123
124//! Checks whether the given value can be represented by a GblVariant (implements GblIVariant)
126
127/*! \name Constructors
128 * \brief Methods for various types of construction
129 * \relatesalso GblVariant
130 * @{
131 */
132//! Invokes the default constructor for the given type
134//! Invokes the copy constructor, constructing then copying the \p pOther variant
136 const GblVariant* pOther) GBL_NOEXCEPT;
137//! Invokes the move constructor, constructing then moving the \p pOther variant
139 GblVariant* pOther) GBL_NOEXCEPT;
140//! Invokes the value copy constructor, constructing then copying the given value
142//! va_list* variation of GblVariant_constructValueCopy()
144 GblType type,
145 va_list* pList) GBL_NOEXCEPT;
146//! Invokes the value move constructor, constructing then moving the given value
148//! va_list* variation of GblVariant_constructValueMove()
150 GblType type,
151 va_list* pList) GBL_NOEXCEPT;
152//! Convenience wrapper for value constructing a variant with a NIL value
154//! Convenience wrapper for value constructing a variant with a bool value
156//! Convenience wrapper for value constructing a variant with a char value
158//! Convenience wrapper for value constructing a variant with a uint8_t value
160//! Convenience wrapper for value constructing a variant with a uint16 value
162//! Convenience wrapper for value constructing a variant with an int16 value
164//! Convenience wrapper for value constructing a variant with a uint32 value
166//! Convenience wrapper for value constructing a variant with an int32 value
168//! Convenience wrapper for value constructing a variant with a uint64 value
170//! Convenience wrapper for value constructing a variant with an int64 value
172//! Convenience wrapper for value constructing a variant with a float value
174//! Convenience wrapper for value constructing a variant with a double value
176//! Convenience wrapper for value copy constructing a variant with a const char*
178//! Convenience wrapper for value move constructing a variant with a GblStringRef (transferring ownership)
180//! Convenience wrapper for value copy constructing a string variant from a string view
182//! Convenience wrapper for value constructing a variant from a GblType
184//! Convenience wrapper for value copy constructing a variant with a size_t
186//! Convenience wrapper for value copy constructing a variant with a GblDateTime
188 const GblDateTime* pDateTime) GBL_NOEXCEPT;
189//! Convenience wrapper for value constructing an enum derived variant with its value
191 GblType type,
192 GblEnum value) GBL_NOEXCEPT;
193//! Convenience wrapper for value constructing a flags-derived variant with its value
195 GblType type,
196 GblFlags value) GBL_NOEXCEPT;
197//! Convenience wrapper for value constructing a pointer-derived variant with its value
199 GblType ptrType,
200 void* pValue) GBL_NOEXCEPT;
201//! Convenience wrapper for value copy constructing a variant from an opaque-derived type pointer
203 GblType opaqueType,
204 void* pValue) GBL_NOEXCEPT;
205//! Convenience wrapper for value move constructing a variant from an opaque-derived type pointer
207 GblType opaqueType,
208 void* pValue) GBL_NOEXCEPT;
209//! Convenience wrapper for value constructing a variant from a GblInstance pointer
211//! Convenience wrapper for value copy constructing a variant from a GblBox, increasing its refCount
213//! Convenience wrapper for value move constructing a variant from a GblBox, taking ownership of the reference
215//! Convenience wrapper for value copy constructing a variant from a GblObject, increasing its refCount
217//! Convenience wrapper for value m ove constructing a variant from a GblObject, taking ownership of the reference
219//! Destroys the given variant, invoking its destructor and resetting its type and value
221//! @}
222
223/*! \name Setters
224 * \brief Methods for modifying the value of a constructed GblVariant
225 * \relatesalso GblVariant
226 * @{
227 */
228//! Performs a copy assignment operation, setting \p pOther to the given variant's value
230 const GblVariant* pOther) GBL_NOEXCEPT;
231//! Performs a move assignment operation, moving the given variant's value into \p pOther
232GBL_EXPORT GBL_RESULT GblVariant_setMove (GBL_SELF, GblVariant* pOther) GBL_NOEXCEPT;
233//! Performs a generic value copy assignment operation, copying the variadic argument into the variant
235//! va_list* variation of GblVariant_setValueCopy(), where the value is sourdced from a va_list*
237 GblType type,
238 va_list* pVarArgs) GBL_NOEXCEPT;
239//! Performs a generic value move assignment operation, moving the variadic argument into the variant
241//! va_list* variation of GblVariant_setValueMove(), where the value is sourced from a va_list*
243 GblType type,
244 va_list* pVarArgs) GBL_NOEXCEPT;
245//! Clears and resets the given variants type and value. ONLY call after being the source of a move operation!
247//! Convenience wrapper assigning the value of a constructed variant to NIL
249//! Convenience wrapper assigning the value of a constructed variant to a boolean
251//! Convenience wrapper assigning the value of a constructed variant to a character
253//! Convenience wrapper assigning the value of a constructed variant to a uint8
255//! Convenience wrapper assigning the value of a constructed variant to a uint16
257//! Convenience wrapper assigning the value of a constructed variant to an int16
259//! Convenience wrapper assigning the value of a constructed variant to a uint32
261//! Convenience wrapper assigning the value of a constructed variant to an int32
263//! Convenience wrapper assigning the value of a constructed variant to a uint64
265//! Convenience wrapper assigning the value of a constructed variant to an int64
267//! Convenience wrapper assigning the value of a constructed variant to a float
269//! Convenience wrapper assigning the value of a constructed variant to a double
271//! Convenience wrapper assigning the value of a constructed variant to a copy of the given string
272GBL_EXPORT GBL_RESULT GblVariant_setString (GBL_SELF, const char* pValue) GBL_NOEXCEPT;
273//! Convenience wrapper assigning the value of a constructed variant to a copy of the given string view
275//! Convenience wrapper move assigning the value of a constructed variant to take the given reference
277//! Convenience wrapper assigning the value of a constructed variant to a GblType
279//! Convenience wrapper assigning the value of a constructed variant to a size_t
281//! Convenience wrapper copy assigning the value of a constructed variant to a GblDateTime*
283 const GblDateTime* pDt) GBL_NOEXCEPT;
284//! Convenience wrapper assigning the value of a constructed variant to that of an enum-derived type
286 GblType enumType,
287 GblEnum value) GBL_NOEXCEPT;
288//! Convenience wrapper assigning the value of a constructed variant to that of a GblFlags-derived type
290 GblType flagsType,
291 GblFlags value) GBL_NOEXCEPT;
292//! Convenience wrapper assigning the value of a constructed variant to that of a pointer-derived type
294 GblType ptrType,
295 void* pValue) GBL_NOEXCEPT;
296//! Convenience wrapper copy assigning the value of a constructed variant to that of an opaque-derived type
298 GblType opaqueType,
299 void* pValue) GBL_NOEXCEPT;
300//! Convenience wrapper move assigning the value of a constructed variant to that of an opaque-derived type
302 GblType opaqueType,
303 void* pValue) GBL_NOEXCEPT;
304//! Convenience wrapper assigning the value of a GblVariant to a GblInstance*
305GBL_EXPORT GBL_RESULT GblVariant_setInstance (GBL_SELF, GblInstance* pValue) GBL_NOEXCEPT;
306//! Convenience wrapper which assigns the value of the given variant to that of a new reference to a GblBox
308//! Convenience wrapper which assigns the value of the given variant to take ownership of a GblBox reference
310//! Convenience wrapper which assigns the value of the given variant to that of a new reference to a GblObject
312//! Convenience wrapper which assings the value of the given variant to take ownership of a GblBox reference
314//! @}
315
316//! Retrieves the name of the type of value contained by the given variant
318//! Attempts to fetch the class associated with the type stored within the variant
320//! Retrives the GblType UUID of the value contained by the given variant
322
323/*! \name Getters
324 * \brief Methods for retrieving the value of a constructed GblVariant
325 * \relatesalso GblVariant
326 * @{
327 */
328//! Attempts to retrieve a copy of the variant's value and store it into the provided pointer
330//! va_list* variant of GblVariant_valueCopy(), where the destination pointer comes from a va_list*
332//! Attempts to retrieve the actual value stored within the variant and store it into the provided pointer (no movement or copying)
334//! va_list* variant of GblVariant_valuePeek(), where destination pointer comes from a va_list*
336//! Attempts to move the value stored within the variant out of it and into the provided pointer
338//! va_list* variant of GblVariant_valueMove(), where destination pointer comes from a va_list*
340//! Returns GBL_TRUE if the value held by the given variant is not of GBL_INVALID_TYPE
342//! Returns GBL_TRUE if the value held by the variant is not of type GBL_NIL_TYPE
344//! Attempst to fetch the value of the variant as a bool, raising an error upon type mismatch
346//! Attempst to fetch the value of the variant as a char, raising an error upon type mismatch
348//! Attempst to fetch the value of the variant as a uint8, raising an error upon type mismatch
350//! Attempst to fetch the value of the variant as a uint16, raising an error upon type mismatch
352//! Attempst to fetch the value of the variant as an int16, raising an error upon type mismatch
354//! Attempst to fetch the value of the variant as a uint32, raising an error upon type mismatch
356//! Attempst to fetch the value of the variant as an int32, raising an error upon type mismatch
358//! Attempst to fetch the value of the variant as a uint64, raising an error upon type mismatch
360//! Attempst to fetch the value of the variant as an int64, raising an error upon type mismatch
362//! Attempst to fetch the value of the variant as a generic enum value, raising an error upon type mismatch
364//! Attempst to fetch the value of the variant as a generic GblFlags value, raising an error upon type mismatch
366//! Attempst to fetch the value of the variant as a float, raising an error upon type mismatch
368//! Attempst to fetch the value of the variant as a double, raising an error upon type mismatch
370//! Attempst to fetch the value of the variant as a string, raising an error upon type mismatch
372//! Attempst to fetch the value of the variant as a string, returning it within a view, raising an error upon type mismatch
374//! Attempst to fetch the value of the variant as a GblType, raising an error upon type mismatch
376//! Attempst to fetch the value of the variant as a generic pointer, raising an error upon type mismatch
378//! Attempst to fetch the value of the variant as a size_t, raising an error upon type mismatch
380//! Attempst to fetch the value of the variant as a GblDateTime, raising an error upon type mismatch
382//! Attempst to fetch a copy of the value of the variant as a generic opaque pointer, raising an error upon type mismatch
384//! Attempst to take the value of the variant (claiming ownerships) as a generic opaque pointer, raising an error upon type mismatch
386//! Attempst to fetch the value of the variant as a generic opaque pointer, raising an error upon type mismatch
388//! Attempts to fetch the value of the variant as a GblInstance derived type, returning a pointer to it
390//! Attempts to fetch a copy of the value of the variant by making a new generic GblBox reference, raising an error upon type mismatch
392//! Attempts to take the value stored within the variant as generic GblBox pointer, claiming ownerships of it
394//! Attempts to fetch the value stored within the variant as a pointer to a GblBox derived type
396//! Attempts to fetch a copy of the value of the variant by making a new generic GblObject reference, raising an error upon type mismatch
398//! Attempts to take the value stored within the variant as generic GblObject pointer, claiming ownerships of it
400//! Attempts to fetch the value stored within the variant as a pointer to a GblObject derived type
402//! @}
403//!
404/*! \name Table Accessors
405 * \brief Methods for managing and manipulating variants as tables
406 * \relatesalso GblVariant
407 * @{
408 */
409//! Looks up the table entry with the given \p pKey, storing its value in \p pValue and also returning it
411 const GblVariant* pKey,
412 GblVariant* pValue) GBL_NOEXCEPT;
413//! Looks up the talbe entry with the given string key, storing its value in \p pValue and also returning it
415 const char* pName,
416 GblVariant* pValue) GBL_NOEXCEPT;
417//! Looks up the table entry with the given integral key, storing its value in \p pValue and also returning it
419 size_t index,
420 GblVariant* pValue) GBL_NOEXCEPT;
421//! Sets the value of the table entry with the corresponding GblVariant key to \p pValue, returning a status code
423 const GblVariant* pKey,
424 GblVariant* pValue) GBL_NOEXCEPT;
425//! Sets the value of the table entry with the corresponding string key to \p pValue, returning a status code
427 const char* pName,
428 GblVariant* pValue) GBL_NOEXCEPT;
429//! Sets the value of the table entry with the corresponding integral key to \p pValue, returning a status code
431 size_t index,
432 GblVariant* pValue) GBL_NOEXCEPT;
433//! Given the current entry's key (or NIL for the first iteration), sets the next key as well as its value, returning GBL_FALSE after the final entry
435 GblVariant* pKey,
436 GblVariant* pValue) GBL_NOEXCEPT;
437//! Returns the number of table entries within the given GblVariant
439//! @}
440
441/*! \name Builtin Conversions
442 * \brief Methods for converting between types
443 * \relatesalso GblVariant
444 * @{
445 */
446//! Convenience method that attempts to convert the variant's type to bool and return its value
448//! Convenience method that attempts to convert the variant's type to char and return its value
450//! Convenience method that attempts to convert the variant's type to uint8 and return its value
452//! Convenience method that attempts to convert the variant's type to uint16 and return its value
454//! Convenience method that attempts to convert the variant's type to int16 and return its value
456//! Convenience method that attempts to convert the variant's type to uint32 and return its value
458//! Convenience method that attempts to convert the variant's type to int32 and return its value
460//! Convenience method that attempts to convert the variant's type to uint64 and return its value
462//! Convenience method that attempts to convert the variant's type to int64 and return its value
464//! Convenience method that attempts to convert the variant's type to a generic enum and return its value
466//! Convenience method that attempts to convert the variant's type to a generic GblFlags and return its value
468//! Convenience method that attempts to convert the variant's type to float and return its value
470//! Convenience method that attempts to convert the variant's type to double and return its value
472//! Convenience method that attempts to convert the variant's type to pointer and return its value
474//! Convenience method that attempts to convert the variant's type to string and return its value
476//! Convenience method that attempts to convert the variant's type to string view and return its value
478//! Convenience method that attempts to convert the variant's type to GblType and return its value
480//! Convenience method that attempts to convert the variant's type to size_t and return its value
482//! Convenience method that attempts to convert the variant's type to GblDateTime and return its value
484//! @}
485
486/*! \name Generic Conversions
487 * \brief Generic conversion registration and operations
488 * \relatesalso GblVariant
489 * @{
490 */
491//! Registers a converter with the type system for going from one type of variant to another
493 GblType toType,
494 GblVariantConverterFn pFnConv) GBL_NOEXCEPT;
495//! Unregisters a converter with the type system from going from one type to another type of variant
497 GblType toType) GBL_NOEXCEPT;
498//! Retrieves the current number of type conversion routines held by the type registry
500//! Returns GBL_TRUE if a method can be found to convert from one type to another type of variant
502 GblType toType) GBL_NOEXCEPT;
503//! Fills \p pToVariant with the value of \p pSelf, converted to the type contained by \p pToVariant
505 GblVariant* pToVariant) GBL_NOEXCEPT;
506//! @}
507
508/*! \name Utilities
509 * \brief Methods offering various operators and utility functionality
510 * \relatesalso GblVariant
511 * @{
512 */
513//! Peforms a comparison between the two types of variants, implicitly converting between them if necessary
515 const GblVariant* pOther) GBL_NOEXCEPT;
516//! Returns GBL_TRUE if the result of the comparison between two variants is 0 (meaning both equal)
518 const GblVariant* pOther) GBL_NOEXCEPT;
519//! Attempts to serialize the value stored within the given variant to a GblStringBuffer
521 GblStringBuffer* pString) GBL_NOEXCEPT;
522//! Attempts to deserialize a value within a GblStringBuffer to store within the given variant
524 const GblStringBuffer* pStr) GBL_NOEXCEPT;
525//! Calculates a 32-bit hash value corresponding to the given variant's value
527//! @}
528
530
531#if !defined(GBL_DREAMCAST) && !defined(GBL_GAMECUBE) && !defined(GBL_PSP)
532# define GBL_VARIANT_CONSTRUCT_GENERIC_PLATFORM_ENTRIES()
533#else
534# define GBL_VARIANT_CONSTRUCT_GENERIC_PLATFORM_ENTRIES()
535 (int, GblVariant_constructInt32),
536#endif
537
538//! \cond
539#define GBL_VARIANT_CONSTRUCT_TABLE (
541 (
542 (char, GblVariant_constructChar),
543 (uint8_t, GblVariant_constructUint8),
544 (uint16_t, GblVariant_constructUint16),
545 (int16_t, GblVariant_constructInt16),
546 (uint32_t, GblVariant_constructUint32),
548 (int32_t, GblVariant_constructInt32),
549 (uint64_t, GblVariant_constructUint64),
550 (int64_t, GblVariant_constructInt64),
551 (float, GblVariant_constructFloat),
552 (double, GblVariant_constructDouble),
553 (const char*, GblVariant_constructString),
554 (char*, GblVariant_constructString),
555 (GblStringView, GblVariant_constructStringView),
556 (void*, GblVariant_constructPointer),
557 (const void*, GblVariant_constructPointer),
558 (const GblVariant*, GblVariant_constructCopy),
559 (GblVariant*, GblVariant_constructCopy)
560 )
561 )
562#define GblVariant_construct_N(pVariant, ...) GBL_META_GENERIC_MACRO_GENERATE(GBL_VARIANT_CONSTRUCT_TABLE, GBL_TUPLE_FIRST (__VA_ARGS__))(pVariant, __VA_ARGS__)
563#define GblVariant_construct_1(pVariant) GblVariant_constructNil(pVariant)
564#define GblVariant_construct_(...) GBL_VA_OVERLOAD_CALL(GblVariant_construct, GBL_VA_OVERLOAD_SUFFIXER_1_N, __VA_ARGS__)
565
566#define GBL_VARIANT_SET_TABLE (
568 (
569 (char, GblVariant_setChar),
570 (uint8_t, GblVariant_setUint8),
571 (uint16_t, GblVariant_setUint16),
572 (int16_t, GblVariant_setInt16),
573 (uint32_t, GblVariant_setUint32),
574 (int32_t, GblVariant_setInt32),
575 (uint64_t, GblVariant_setUint64),
576 (int64_t, GblVariant_setInt64),
577 (float, GblVariant_setFloat),
578 (double, GblVariant_setDouble),
579 (char*, GblVariant_setString),
580 (const char*, GblVariant_setString),
581 (GblStringView, GblVariant_setStringView),
582 (const void*, GblVariant_setPointer),
583 (void*, GblVariant_setPointer),
584 (const GblVariant*, GblVariant_setCopy),
585 (GblVariant*, GblVariant_setCopy)
586 )
587 )
588#define GblVariant_set_(pVariant, ...) GBL_META_GENERIC_MACRO_GENERATE(GBL_VARIANT_SET_TABLE, GBL_TUPLE_FIRST(__VA_ARGS__))(pVariant, __VA_ARGS__)
589//! \endcond
590
591#undef GBL_SELF_TYPE
592
593#endif // GIMBAL_VARIANT_H
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_FORWARD_DECLARE_STRUCT(S)
#define GBL_EXPORT
#define GBL_VA_OVERLOAD_CALL(BASE, SUFFIXER,...)
#define GBL_TUPLE_FIRST(...)
#define GBL_VA_OVERLOAD_SUFFIXER_1_N(...)
#define GBL_META_GENERIC_MACRO_NO_DEFAULT
#define GBL_META_GENERIC_MACRO_GENERATE(traits, X)
#define GBL_INVALID_TYPE
GblType UUID of the invalid type.
Definition gimbal_type.h:31
uint32_t GblHash
Type representing a calculated numeric hash across the codebase.
uint32_t GblEnum
Standard-sized enum type, 32-bits across platforms.
uint32_t GblFlags
Standard-sized flags type, 32-bits across platforms.
void(* GblFnPtr)()
Type used for holding an untyped function pointer.
uint8_t GblBool
Basic boolean type, standardized to sizeof(char)
#define GBL_VARIANT_CONSTRUCT_GENERIC_PLATFORM_ENTRIES()
const char * GblVariant_typeName(const GblVariant *pSelf)
Retrives the GblType UUID of the value contained by the given variant.
GblType GblVariant_typeOf(const GblVariant *pSelf)
Retrieves the name of the type of value contained by the given variant.
GblClass * GblVariant_classOf(const GblVariant *pSelf)
Attempts to fetch the class associated with the type stored within the variant.
#define GBL_VARIANT_INIT
Convience macro for GblVariant value initialization.
GblBool GblVariant_checkTypeCompatible(GblType type)
Checks whether the given value can be represented by a GblVariant (implements GblIVariant)
#define GblVariant_construct(...)
Convenience macro providing a generically-typed constructor method.
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:52
const char GblStringRef
Reference-counted, const char*-compatible string type.
Contains a single generic, dynamically typed value.
double GblVariant_toDouble(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to double and return its value.
GBL_RESULT GblVariant_constructObjectCopy(GblVariant *pSelf, GblObject *pObj)
Convenience wrapper for value copy constructing a variant from a GblObject, increasing its refCount.
GBL_RESULT GblVariant_setInstance(GblVariant *pSelf, GblInstance *pValue)
Convenience wrapper assigning the value of a GblVariant to a GblInstance*.
GBL_RESULT GblVariant_setElement(GblVariant *pSelf, size_t index, GblVariant *pValue)
Sets the value of the table entry with the corresponding integral key to pValue, returning a status c...
GBL_RESULT GblVariant_unregisterConverter(GblType fromType, GblType toType)
Unregisters a converter with the type system from going from one type to another type of variant.
GBL_RESULT GblVariant_setObjectMove(GblVariant *pSelf, GblObject *pValue)
Convenience wrapper which assings the value of the given variant to take ownership of a GblBox refere...
GblVariant * GblVariant_index(const GblVariant *pSelf, const GblVariant *pKey, GblVariant *pValue)
Looks up the table entry with the given pKey, storing its value in pValue and also returning it.
GBL_RESULT GblVariant_valueCopy(const GblVariant *pSelf,...)
Attempts to retrieve a copy of the variant's value and store it into the provided pointer.
GBL_RESULT GblVariant_setDouble(GblVariant *pSelf, double value)
Convenience wrapper assigning the value of a constructed variant to a double.
GblBool GblVariant_isNil(const GblVariant *pSelf)
Returns GBL_TRUE if the value held by the variant is not of type GBL_NIL_TYPE.
GBL_RESULT GblVariant_setValueMove(GblVariant *pSelf, GblType type,...)
Performs a generic value move assignment operation, moving the variadic argument into the variant.
GBL_RESULT GblVariant_constructInt32(GblVariant *pSelf, int32_t value)
Convenience wrapper for value constructing a variant with an int32 value.
void * GblVariant_opaquePeek(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a generic opaque pointer, raising an error upon type mi...
double GblVariant_double(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a double, raising an error upon type mismatch.
GBL_RESULT GblVariant_valuePeek(const GblVariant *pSelf,...)
Attempts to retrieve the actual value stored within the variant and store it into the provided pointe...
size_t GblVariant_toSize(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to size_t and return its value.
GBL_RESULT GblVariant_setCopy(GblVariant *pSelf, const GblVariant *pOther)
Performs a copy assignment operation, setting pOther to the given variant's value.
GBL_RESULT GblVariant_setPointer(GblVariant *pSelf, GblType ptrType, void *pValue)
Convenience wrapper assigning the value of a constructed variant to that of a pointer-derived type.
GBL_RESULT GblVariant_setEnum(GblVariant *pSelf, GblType enumType, GblEnum value)
Convenience wrapper assigning the value of a constructed variant to that of an enum-derived type.
GBL_RESULT GblVariant_constructObjectMove(GblVariant *pSelf, GblObject *pObj)
Convenience wrapper for value m ove constructing a variant from a GblObject, taking ownership of the ...
GBL_RESULT GblVariant_convert(const GblVariant *pSelf, GblVariant *pToVariant)
Fills pToVariant with the value of pSelf, converted to the type contained by pToVariant.
GBL_RESULT GblVariant_constructUint16(GblVariant *pSelf, uint16_t value)
Convenience wrapper for value constructing a variant with a uint16 value.
GblStringRef * pString
GblStringRef value.
GBL_RESULT GblVariant_constructDateTime(GblVariant *pSelf, const GblDateTime *pDateTime)
Convenience wrapper for value copy constructing a variant with a GblDateTime.
GblFlags GblVariant_flags(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a generic GblFlags value, raising an error upon type mi...
GBL_RESULT GblVariant_constructEnum(GblVariant *pSelf, GblType type, GblEnum value)
Convenience wrapper for value constructing an enum derived variant with its value.
GBL_RESULT GblVariant_setSize(GblVariant *pSelf, size_t value)
Convenience wrapper assigning the value of a constructed variant to a size_t.
GblBitmask bitmask
GblBitmask value.
GBL_RESULT GblVariant_setDateTime(GblVariant *pSelf, const GblDateTime *pDt)
Convenience wrapper copy assigning the value of a constructed variant to a GblDateTime*.
GBL_RESULT GblVariant_setIndex(GblVariant *pSelf, const GblVariant *pKey, GblVariant *pValue)
Sets the value of the table entry with the corresponding GblVariant key to pValue,...
float f32
float avlue
GBL_RESULT GblVariant_setValueCopy(GblVariant *pSelf, GblType type,...)
Performs a generic value copy assignment operation, copying the variadic argument into the variant.
GBL_RESULT GblVariant_setUint16(GblVariant *pSelf, uint16_t value)
Convenience wrapper assigning the value of a constructed variant to a uint16.
GblDateTime * GblVariant_dateTime(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a GblDateTime, raising an error upon type mismatch.
GblInstance * GblVariant_instance(const GblVariant *pSelf)
Attempts to fetch the value of the variant as a GblInstance derived type, returning a pointer to it.
GBL_RESULT result
GBL_RESULT value.
GBL_RESULT GblVariant_constructFlags(GblVariant *pSelf, GblType type, GblFlags value)
Convenience wrapper for value constructing a flags-derived variant with its value.
GBL_RESULT GblVariant_destruct(GblVariant *pSelf)
Destroys the given variant, invoking its destructor and resetting its type and value.
GblBox * GblVariant_boxPeek(const GblVariant *pSelf)
Attempts to fetch the value stored within the variant as a pointer to a GblBox derived type.
GblBox * pBox
GblBox* value.
GBL_RESULT GblVariant_setUint64(GblVariant *pSelf, uint64_t value)
Convenience wrapper assigning the value of a constructed variant to a uint64.
GBL_RESULT GblVariant_constructCopy(GblVariant *pSelf, const GblVariant *pOther)
Invokes the copy constructor, constructing then copying the pOther variant.
GBL_RESULT GblVariant_constructDouble(GblVariant *pSelf, double value)
Convenience wrapper for value constructing a variant with a double value.
GblBool GblVariant_equals(const GblVariant *pSelf, const GblVariant *pOther)
Returns GBL_TRUE if the result of the comparison between two variants is 0 (meaning both equal)
GBL_RESULT GblVariant_setBoxMove(GblVariant *pSelf, GblBox *pValue)
Convenience wrapper which assigns the value of the given variant to take ownership of a GblBox refere...
GBL_RESULT GblVariant_setTypeValue(GblVariant *pSelf, GblType value)
Convenience wrapper assigning the value of a constructed variant to a GblType.
GblStringRef * GblVariant_string(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a string, raising an error upon type mismatch.
uint32_t GblVariant_toUint32(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to uint32 and return its value.
GblFlags flags
GblFlags value.
GBL_RESULT GblVariant_constructUint32(GblVariant *pSelf, uint32_t value)
Convenience wrapper for value constructing a variant with a uint32 value.
GblEnum GblVariant_enum(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a generic enum value, raising an error upon type mismat...
GblVariant * GblVariant_element(const GblVariant *pSelf, size_t index, GblVariant *pValue)
Looks up the table entry with the given integral key, storing its value in pValue and also returning ...
GBL_RESULT GblVariant_setOpaqueCopy(GblVariant *pSelf, GblType opaqueType, void *pValue)
Convenience wrapper copy assigning the value of a constructed variant to that of an opaque-derived ty...
double f64
double value
GBL_RESULT GblVariant_setUint32(GblVariant *pSelf, uint32_t value)
Convenience wrapper assigning the value of a constructed variant to a uint32.
GblStringView GblVariant_stringView(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a string, returning it within a view,...
GBL_RESULT GblVariant_setInt64(GblVariant *pSelf, int64_t value)
Convenience wrapper assigning the value of a constructed variant to an int64.
GblBool GblVariant_next(const GblVariant *pSelf, GblVariant *pKey, GblVariant *pValue)
Given the current entry's key (or NIL for the first iteration), sets the next key as well as its valu...
GblBool boolean
boolean value
GBL_RESULT GblVariant_constructChar(GblVariant *pSelf, char value)
Convenience wrapper for value constructing a variant with a char value.
GblType typeValue
GblType value.
uint32_t GblVariant_uint32(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a uint32, raising an error upon type mismatch.
int16_t i16
int16_t value
GblObject * pObject
GblObject* value.
GblType GblVariant_typeValue(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a GblType, raising an error upon type mismatch.
int GblVariant_compare(const GblVariant *pSelf, const GblVariant *pOther)
Peforms a comparison between the two types of variants, implicitly converting between them if necessa...
size_t GblVariant_size(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a size_t, raising an error upon type mismatch.
char GblVariant_char(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a char, raising an error upon type mismatch.
GBL_RESULT GblVariant_setFloat(GblVariant *pSelf, float value)
Convenience wrapper assigning the value of a constructed variant to a float.
GBL_RESULT GblVariant_constructUint64(GblVariant *pSelf, uint64_t value)
Convenience wrapper for value constructing a variant with a uint64 value.
GblDateTime * GblVariant_toDateTime(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to GblDateTime and return its value.
GblVariant * GblVariant_field(const GblVariant *pSelf, const char *pName, GblVariant *pValue)
Looks up the talbe entry with the given string key, storing its value in pValue and also returning it...
GblHash GblVariant_hash(const GblVariant *pSelf)
Calculates a 32-bit hash value corresponding to the given variant's value.
GblBool GblVariant_canConvert(GblType fromType, GblType toType)
Returns GBL_TRUE if a method can be found to convert from one type to another type of variant.
GblFlags GblVariant_toFlags(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to a generic GblFlags and return its v...
GBL_RESULT GblVariant_setStringView(GblVariant *pSelf, GblStringView value)
Convenience wrapper assigning the value of a constructed variant to a copy of the given string view.
GblBox * GblVariant_boxCopy(const GblVariant *pSelf)
Attempts to fetch a copy of the value of the variant by making a new generic GblBox reference,...
GblEnum GblVariant_toEnum(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to a generic enum and return its value...
GBL_RESULT GblVariant_setStringRef(GblVariant *pSelf, GblStringRef *pRef)
Convenience wrapper move assigning the value of a constructed variant to take the given reference.
GBL_RESULT GblVariant_constructInt64(GblVariant *pSelf, int64_t value)
Convenience wrapper for value constructing a variant with an int64 value.
GBL_RESULT GblVariant_setFlags(GblVariant *pSelf, GblType flagsType, GblFlags value)
Convenience wrapper assigning the value of a constructed variant to that of a GblFlags-derived type.
GBL_RESULT GblVariant_constructUint8(GblVariant *pSelf, uint8_t value)
Convenience wrapper for value constructing a variant with a uint8_t value.
GBL_RESULT GblVariant_valuePeekVa(GblVariant *pSelf, va_list *pVa)
va_list* variant of GblVariant_valuePeek(), where destination pointer comes from a va_list*
GblBox * GblVariant_boxMove(GblVariant *pSelf)
Attempts to take the value stored within the variant as generic GblBox pointer, claiming ownerships o...
uint8_t GblVariant_toUint8(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to uint8 and return its value.
uint64_t GblVariant_toUint64(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to uint64 and return its value.
GBL_RESULT GblVariant_constructPointer(GblVariant *pSelf, GblType ptrType, void *pValue)
Convenience wrapper for value constructing a pointer-derived variant with its value.
int16_t GblVariant_toInt16(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to int16 and return its value.
GBL_RESULT GblVariant_constructString(GblVariant *pSelf, const char *pValue)
Convenience wrapper for value copy constructing a variant with a const char*.
size_t GblVariant_converterCount(void)
Retrieves the current number of type conversion routines held by the type registry.
int32_t i32
int32_t value
int64_t i64
int64_t value
int64_t GblVariant_toInt64(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to int64 and return its value.
GblType type
GblType UUID.
GBL_RESULT GblVariant_constructMove(GblVariant *pSelf, GblVariant *pOther)
Invokes the move constructor, constructing then moving the pOther variant.
GBL_RESULT GblVariant_valueMove(GblVariant *pSelf,...)
Attempts to move the value stored within the variant out of it and into the provided pointer.
void * GblVariant_opaqueMove(GblVariant *pSelf)
Attempst to take the value of the variant (claiming ownerships) as a generic opaque pointer,...
GBL_RESULT GblVariant_setBool(GblVariant *pSelf, GblBool value)
Convenience wrapper assigning the value of a constructed variant to a boolean.
GBL_RESULT GblVariant_constructNil(GblVariant *pSelf)
Convenience wrapper for value constructing a variant with a NIL value.
GblObject * GblVariant_objectCopy(const GblVariant *pSelf)
Attempts to fetch a copy of the value of the variant by making a new generic GblObject reference,...
GBL_RESULT GblVariant_valueCopyVa(const GblVariant *pSelf, va_list *pVa)
va_list* variant of GblVariant_valueCopy(), where the destination pointer comes from a va_list*
GBL_RESULT GblVariant_constructBool(GblVariant *pSelf, GblBool value)
Convenience wrapper for value constructing a variant with a bool value.
GBL_RESULT GblVariant_constructOpaqueCopy(GblVariant *pSelf, GblType opaqueType, void *pValue)
Convenience wrapper for value copy constructing a variant from an opaque-derived type pointer.
uint64_t GblVariant_uint64(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a uint64, raising an error upon type mismatch.
uint16_t GblVariant_toUint16(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to uint16 and return its value.
uint16_t u16
uint16_t value
GBL_RESULT GblVariant_constructDefault(GblVariant *pSelf, GblType type)
Invokes the default constructor for the given type.
GBL_RESULT GblVariant_setString(GblVariant *pSelf, const char *pValue)
Convenience wrapper assigning the value of a constructed variant to a copy of the given string.
uint32_t u32
uint32_t value
GblType GblVariant_toTypeValue(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to GblType and return its value.
GblEnum enumeration
enum value
GBL_RESULT GblVariant_load(GblVariant *pSelf, const GblStringBuffer *pStr)
Attempts to deserialize a value within a GblStringBuffer to store within the given variant.
GBL_RESULT GblVariant_constructValueCopy(GblVariant *pSelf, GblType type,...)
Invokes the value copy constructor, constructing then copying the given value.
size_t GblVariant_count(const GblVariant *pSelf)
Returns the number of table entries within the given GblVariant.
GBL_RESULT GblVariant_constructFloat(GblVariant *pSelf, float value)
Convenience wrapper for value constructing a variant with a float value.
GBL_RESULT GblVariant_setChar(GblVariant *pSelf, char value)
Convenience wrapper assigning the value of a constructed variant to a character.
GBL_RESULT GblVariant_setBoxCopy(GblVariant *pSelf, GblBox *pValue)
Convenience wrapper which assigns the value of the given variant to that of a new reference to a GblB...
char GblVariant_toChar(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to char and return its value.
void * pVoid
void* value
GBL_RESULT GblVariant_constructSize(GblVariant *pSelf, size_t value)
Convenience wrapper for value copy constructing a variant with a size_t.
GblBool GblVariant_isValid(const GblVariant *pSelf)
Returns GBL_TRUE if the value held by the given variant is not of GBL_INVALID_TYPE.
uint8_t GblVariant_uint8(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a uint8, raising an error upon type mismatch.
int32_t GblVariant_toInt32(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to int32 and return its value.
GBL_RESULT GblVariant_constructBoxMove(GblVariant *pSelf, GblBox *pValue)
Convenience wrapper for value move constructing a variant from a GblBox, taking ownership of the refe...
GBL_RESULT GblVariant_setObjectCopy(GblVariant *pSelf, GblObject *pValue)
Convenience wrapper which assigns the value of the given variant to that of a new reference to a GblO...
void * GblVariant_pointer(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a generic pointer, raising an error upon type mismatch.
GBL_RESULT GblVariant_setInt16(GblVariant *pSelf, int16_t value)
Convenience wrapper assigning the value of a constructed variant to an int16.
GBL_RESULT GblVariant_setMove(GblVariant *pSelf, GblVariant *pOther)
Performs a move assignment operation, moving the given variant's value into pOther.
GBL_RESULT GblVariant_registerConverter(GblType fromType, GblType toType, GblVariantConverterFn pFnConv)
Registers a converter with the type system for going from one type of variant to another.
GblBool GblVariant_toBool(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to bool and return its value.
GBL_RESULT GblVariant_constructOpaqueMove(GblVariant *pSelf, GblType opaqueType, void *pValue)
Convenience wrapper for value move constructing a variant from an opaque-derived type pointer.
GblBool GblVariant_bool(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a bool, raising an error upon type mismatch.
float GblVariant_float(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a float, raising an error upon type mismatch.
GBL_RESULT GblVariant_constructBoxCopy(GblVariant *pSelf, GblBox *pValue)
Convenience wrapper for value copy constructing a variant from a GblBox, increasing its refCount.
GBL_RESULT GblVariant_invalidate(GblVariant *pSelf)
Clears and resets the given variants type and value. ONLY call after being the source of a move opera...
int16_t GblVariant_int16(const GblVariant *pSelf)
Attempst to fetch the value of the variant as an int16, raising an error upon type mismatch.
GBL_RESULT GblVariant_setValueCopyVa(GblVariant *pSelf, GblType type, va_list *pVarArgs)
va_list* variation of GblVariant_setValueCopy(), where the value is sourdced from a va_list*
GBL_RESULT GblVariant_constructStringView(GblVariant *pSelf, GblStringView value)
Convenience wrapper for value copy constructing a string variant from a string view.
char character
char value
GblStringRef * GblVariant_toString(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to string and return its value.
GblObject * GblVariant_objectMove(GblVariant *pSelf)
Attempts to take the value stored within the variant as generic GblObject pointer,...
GBL_RESULT GblVariant_setOpaqueMove(GblVariant *pSelf, GblType opaqueType, void *pValue)
Convenience wrapper move assigning the value of a constructed variant to that of an opaque-derived ty...
GblObject * GblVariant_objectPeek(const GblVariant *pSelf)
Attempts to fetch the value stored within the variant as a pointer to a GblObject derived type.
GBL_RESULT GblVariant_constructValueMoveVa(GblVariant *pSelf, GblType type, va_list *pList)
va_list* variation of GblVariant_constructValueMove()
GBL_RESULT GblVariant_constructValueCopyVa(GblVariant *pSelf, GblType type, va_list *pList)
va_list* variation of GblVariant_constructValueCopy()
uint8_t u8
uint8_t value
GblStringView GblVariant_toStringView(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to string view and return its value.
void * GblVariant_opaqueCopy(const GblVariant *pSelf)
Attempst to fetch a copy of the value of the variant as a generic opaque pointer, raising an error up...
GblInstance * pInstance
GblInstance* value.
GblDateTime * pDateTime
GblDateTime value.
GBL_RESULT GblVariant_valueMoveVa(GblVariant *pSelf, va_list *pVa)
va_list* variant of GblVariant_valueMove(), where destination pointer comes from a va_list*
GBL_RESULT GblVariant_constructTypeValue(GblVariant *pSelf, GblType type)
Convenience wrapper for value constructing a variant from a GblType.
uint64_t u64
uint64_t value
GBL_RESULT GblVariant_constructInt16(GblVariant *pSelf, int16_t value)
Convenience wrapper for value constructing a variant with an int16 value.
GblFnPtr pFnPtr
function pointer value
GBL_RESULT GblVariant_setValueMoveVa(GblVariant *pSelf, GblType type, va_list *pVarArgs)
va_list* variation of GblVariant_setValueMove(), where the value is sourced from a va_list*
float GblVariant_toFloat(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to float and return its value.
GBL_RESULT GblVariant_setUint8(GblVariant *pSelf, uint8_t value)
Convenience wrapper assigning the value of a constructed variant to a uint8.
void * GblVariant_toPointer(GblVariant *pSelf)
Convenience method that attempts to convert the variant's type to pointer and return its value.
int64_t GblVariant_int64(const GblVariant *pSelf)
Attempst to fetch the value of the variant as an int64, raising an error upon type mismatch.
uint16_t GblVariant_uint16(const GblVariant *pSelf)
Attempst to fetch the value of the variant as a uint16, raising an error upon type mismatch.
GBL_RESULT GblVariant_setNil(GblVariant *pSelf)
Convenience wrapper assigning the value of a constructed variant to NIL.
GBL_RESULT GblVariant_constructInstance(GblVariant *pSelf, GblInstance *pValue)
Convenience wrapper for value constructing a variant from a GblInstance pointer.
GBL_RESULT GblVariant_setInt32(GblVariant *pSelf, int32_t value)
Convenience wrapper assigning the value of a constructed variant to an int32.
GBL_RESULT GblVariant_setField(GblVariant *pSelf, const char *pName, GblVariant *pValue)
Sets the value of the table entry with the corresponding string key to pValue, returning a status cod...
int32_t GblVariant_int32(const GblVariant *pSelf)
Attempst to fetch the value of the variant as an int32, raising an error upon type mismatch.
GBL_RESULT GblVariant_constructValueMove(GblVariant *pSelf, GblType type,...)
Invokes the value move constructor, constructing then moving the given value.
GBL_RESULT GblVariant_save(const GblVariant *pSelf, GblStringBuffer *pString)
Attempts to serialize the value stored within the given variant to a GblStringBuffer.
GBL_RESULT GblVariant_constructStringRef(GblVariant *pSelf, GblStringRef *pRef)
Convenience wrapper for value move constructing a variant with a GblStringRef (transferring ownership...