libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_variant.h File Reference

Go to the source code of this file.

Data Structures

struct  GblVariant
 

Macros

#define GBL_VARIANT_INIT
 
#define GBL_VARIANT(name)
 
#define GblVariant_construct(...)
 
#define GblVariant_set(pVariant, ...)
 

Typedefs

typedef GBL_RESULT(* GblVariantConverterFn) (const GblVariant *pSelf, GblVariant *pOther)
 

Functions

GblBool GblVariant_checkTypeCompatible (GblType type)
 
const char * GblVariant_typeName (const GblVariant *pSelf)
 

Detailed Description

GblVariant structure and related functions.

This file contains the GblVariant type and its associated API. GblVariant is the core, fundamental dynamically-typed structure capable of representing any type that is known to the type system uniformly.

The convenience wrappers provide a wide variety of methods around a set of fundamental, low-level calls, which perform standard GblVariant lifetime and value management in a type-generic way:

GblVariant v;

// Always construct a variant before using it
GblVariant_constructValueCopy(&v GBL_FLOAT_TYPE, -17.0f);

// You can now fetch its value as a float
float f = 0.0f;
GblVariant_valueCopy(&v, GBL_FLOAT_TYPE, &f); // or GblVariant_float()
GBL_ASSERT(f == -17.0f);

// You can now freely assign and change its value
// Lets do so by "moving" a reference to a GblObject into it
GblVariant_setValueMove(&v, GBL_OBJECT_TYPE, GBL_NEW(GblObject));

// ALWAYS call the destructor when it leaves scope to free resources
// this will release the otherwise leaked reference to the new GblObject
GblVariant_destruct(&v);
Todo:
  • function call operator()? Or call into a Closure?
  • serializing/deserializing
  • Ensure unregistering a type also removes its converters
  • when you have an instance/box/object type, have to propagate inner type to box's outer type
Author
2023 Falco Girgis

Definition in file gimbal_variant.h.

Macro Definition Documentation

◆ GBL_VARIANT_INIT

#define GBL_VARIANT_INIT

Convience macro for GblVariant value initialization.

Definition at line 55 of file gimbal_variant.h.

◆ GBL_VARIANT

#define GBL_VARIANT (   name)

Convience macro for declaring and initalizing a GblVariant.

Definition at line 57 of file gimbal_variant.h.

◆ GblVariant_construct

#define GblVariant_construct (   ...)

Convenience macro providing a generically-typed constructor method.

Definition at line 60 of file gimbal_variant.h.

◆ GblVariant_set

#define GblVariant_set (   pVariant,
  ... 
)

Convenience macro providing a generically-typed assignment method.

Definition at line 62 of file gimbal_variant.h.

Typedef Documentation

◆ GblVariantConverterFn

typedef GBL_RESULT(* GblVariantConverterFn) (const GblVariant *pSelf, GblVariant *pOther)

Function signature for a type converter to be used with GblVariant_registerConverter()

Definition at line 72 of file gimbal_variant.h.

Function Documentation

◆ GblVariant_checkTypeCompatible()

GblBool GblVariant_checkTypeCompatible ( GblType  type)

Checks whether the given value can be represented by a GblVariant (implements GblIVariant)

◆ GblVariant_typeName()

const char * GblVariant_typeName ( const GblVariant pSelf)

Retrives the GblType UUID of the value contained by the given variant.