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

Go to the source code of this file.

Data Structures

struct  GblInterfaceImpl
 
struct  GblTypeInfo
 

Macros

#define GBL_INVALID_TYPE
 

Typedefs

typedef uintptr_t GblType
 
typedef GBL_RESULT(* GblClassInitFn) (GblClass *, const void *)
 
typedef GBL_RESULT(* GblClassFinalFn) (GblClass *, const void *)
 
typedef GBL_RESULT(* GblInstanceInitFn) (GblInstance *)
 

Enumerations

enum  GblTypeFlags
 

Functions

Registry

Methods for managing the type registry

GblType GblType_register (const char *pName, GblType baseType, const GblTypeInfo *pInfo, GblFlags flags)
 
GBL_RESULT GblType_unregister (GblType type)
 
size_t GblType_count (void)
 
GblType GblType_next (GblType previousType)
 
Querying

Methods for looking up or querying types

GblType GblType_find (const char *pName)
 
GblType GblType_findQuark (GblQuark quark)
 
Attributes

Accessor methods for getting a type's information

const char * GblType_name (GblType self)
 
GblQuark GblType_nameQuark (GblType self)
 
GblType GblType_parent (GblType self)
 
const GblTypeInfoGblType_info (GblType self)
 
GblFlags GblType_flags (GblType self)
 
Resource Tracking

Methods for querying a type's active resource counters

GblRefCount GblType_classRefCount (GblType self)
 
GblRefCount GblType_instanceCount (GblType self)
 
Hierarchy

Methods for querying a type's hierarchy

GblType GblType_root (GblType self)
 
GblType GblType_base (GblType self, size_t depth)
 
GblType GblType_ancestor (GblType self, size_t level)
 
size_t GblType_depth (GblType self)
 
Type Checking

Methods performing type system queries on a type

GblBool GblType_verify (GblType self)
 
GblBool GblType_check (GblType self, GblType other)
 
GblBool GblType_depends (GblType self, GblType dependency)
 
GblBool GblType_derives (GblType self, GblType superType)
 
GblBool GblType_implements (GblType self, GblType ifaceType)
 
GblType GblType_common (GblType self, GblType other)
 
GblBool GblType_maps (GblType self, GblType iface)
 
GblBool GblType_conforms (GblType self, GblType dependent)
 

Detailed Description

GblType UUID, meta type registration, and API.

This file provides the lowest-level entry-point and API into the meta type system, built around GblType, a UUID which is returned after registering a type.

To register a type with the type system and get a UUID for it, simply use GblType_register().

UUIDs are automatically made available for all builtin types.

Todo:
  • GblType_next does not iterate over builtin types
    • GblType_foreach() is probably better!
  • GBL_PROTCOL_TYPE solidification and testing
Author
2023 Falco Girgis

Definition in file gimbal_type.h.

Macro Definition Documentation

◆ GBL_INVALID_TYPE

#define GBL_INVALID_TYPE

GblType UUID of the invalid type.

Definition at line 31 of file gimbal_type.h.

Typedef Documentation

◆ GblClassInitFn

typedef GBL_RESULT(* GblClassInitFn) (GblClass *, const void *)

Function type used as a GblType's GblClass initializer.

Definition at line 53 of file gimbal_type.h.

◆ GblClassFinalFn

typedef GBL_RESULT(* GblClassFinalFn) (GblClass *, const void *)

Function type used as a GblType's GblClass finalizer.

Definition at line 54 of file gimbal_type.h.

◆ GblInstanceInitFn

typedef GBL_RESULT(* GblInstanceInitFn) (GblInstance *)

Function type used as a GblType's GblInstance initializer.

Definition at line 55 of file gimbal_type.h.

Enumeration Type Documentation

◆ GblTypeFlags

Flags controlling behavior of GblTypes. These can be set at any level in a type heirarchy.

Enumerator
GBL_TYPE_FLAGS_NONE 

Type which adds no additional flags beyond what's inherited.

GBL_TYPE_FLAG_BUILTIN 

Type was automatically registered as a builtin type (do not use on a new type)

GBL_TYPE_FLAG_TYPEINFO_STATIC 

Type's GblTypeInfo specified upon registration is static, so no internal storage has to be allocated for storing a copy.

GBL_TYPE_FLAG_CLASS_PINNED 

Type's GblClass is never destroyed and remains persistent upon construction.

The default behavior is to create/destroy as referenced.

GBL_TYPE_FLAG_CLASS_PREINIT 

Type's GblClass should be constructed immediately, rather than lazily upon use by default.

Also implies class pinning.

GBL_TYPE_FLAG_UNMAPPABLE 

Cannot obtain Type's associated GblInterface from a GblClass it has been mapped to.

Disambiguates casting with common interface base classes.

GBL_TYPE_FLAG_INCOMPLETE 

Incomplete/partial type missing some type dependency.

GBL_TYPE_FLAG_ABSTRACT 

Type cannot be instantiated without being derived.

GBL_TYPE_FLAG_FINAL 

Type cannot be derived from.

GBL_TYPE_FLAGS_MASK 

Mask of all user type flags.

Definition at line 58 of file gimbal_type.h.

58 {
59 GBL_TYPE_FLAGS_NONE = 0, //!< Type which adds no additional flags beyond what's inherited
60 GBL_TYPE_FLAG_BUILTIN = (1 << 6), //!< Type was automatically registered as a builtin type (do not use on a new type)
61 GBL_TYPE_FLAG_TYPEINFO_STATIC = (1 << 7), //!< Type's GblTypeInfo specified upon registration is static, so no internal storage has to be allocated for storing a copy
62 GBL_TYPE_FLAG_CLASS_PINNED = (1 << 8), //!< Type's GblClass is never destroyed and remains persistent upon construction. The default behavior is to create/destroy as referenced.
63 GBL_TYPE_FLAG_CLASS_PREINIT = (1 << 9), //!< Type's GblClass should be constructed immediately, rather than lazily upon use by default. Also implies class pinning.
64 GBL_TYPE_FLAG_UNMAPPABLE = (1 << 10), //!< Cannot obtain Type's associated GblInterface from a GblClass it has been mapped to. Disambiguates casting with common interface base classes.
65 GBL_TYPE_FLAG_INCOMPLETE = (1 << 11), //!< Incomplete/partial type missing some type dependency
66 GBL_TYPE_FLAG_ABSTRACT = (1 << 12), //!< Type cannot be instantiated without being derived
67 GBL_TYPE_FLAG_FINAL = (1 << 13), //!< Type cannot be derived from
68 GBL_TYPE_FLAGS_MASK = 0xffffffc0 //!< Mask of all user type flags
GblTypeFlags
Flags controlling behavior of GblTypes. These can be set at any level in a type heirarchy.
Definition gimbal_type.h:58
@ GBL_TYPE_FLAG_TYPEINFO_STATIC
Type's GblTypeInfo specified upon registration is static, so no internal storage has to be allocated ...
Definition gimbal_type.h:61
@ GBL_TYPE_FLAGS_MASK
Mask of all user type flags.
Definition gimbal_type.h:68
@ GBL_TYPE_FLAG_CLASS_PREINIT
Type's GblClass should be constructed immediately, rather than lazily upon use by default.
Definition gimbal_type.h:63
@ GBL_TYPE_FLAG_FINAL
Type cannot be derived from.
Definition gimbal_type.h:67
@ GBL_TYPE_FLAGS_NONE
Type which adds no additional flags beyond what's inherited.
Definition gimbal_type.h:59
@ GBL_TYPE_FLAG_CLASS_PINNED
Type's GblClass is never destroyed and remains persistent upon construction.
Definition gimbal_type.h:62
@ GBL_TYPE_FLAG_ABSTRACT
Type cannot be instantiated without being derived.
Definition gimbal_type.h:66
@ GBL_TYPE_FLAG_BUILTIN
Type was automatically registered as a builtin type (do not use on a new type)
Definition gimbal_type.h:60
@ GBL_TYPE_FLAG_UNMAPPABLE
Cannot obtain Type's associated GblInterface from a GblClass it has been mapped to.
Definition gimbal_type.h:64
@ GBL_TYPE_FLAG_INCOMPLETE
Incomplete/partial type missing some type dependency.
Definition gimbal_type.h:65

Function Documentation

◆ GblType_register()

GblType GblType_register ( const char *  pName,
GblType  baseType,
const GblTypeInfo pInfo,
GblFlags  flags 
)

Registers a new type with the given information, returning a unique identifier for it.

◆ GblType_unregister()

GBL_RESULT GblType_unregister ( GblType  type)

Unregisters a type from the type system. Typically not done, better not be used.

◆ GblType_count()

size_t GblType_count ( void  )

Returns the total number of types registered to the type system.

◆ GblType_next()

GblType GblType_next ( GblType  previousType)

Iterates over the registry by passing a previously returned type or GBL_TYPE_INVALID initially.

◆ GblType_find()

GblType GblType_find ( const char *  pName)

Queries the internal type registry for a GblType by its type name.

◆ GblType_findQuark()

GblType GblType_findQuark ( GblQuark  quark)

Queries the registry for a GblType using a GblQuark of its type name (faster)

◆ GblType_name()

const char * GblType_name ( GblType  self)

Returns the type name string associated with the given GblType.

◆ GblType_nameQuark()

GblQuark GblType_nameQuark ( GblType  self)

Returns the type name quark associated with the given GblType.

◆ GblType_parent()

GblType GblType_parent ( GblType  self)

Returns the given type's parent's GblType or GBL_INVALID_TYPE if it's a root type.

◆ GblType_info()

const GblTypeInfo * GblType_info ( GblType  self)

Returns the GblTypeInfo struct for the given type, containing its meta information.

◆ GblType_flags()

GblFlags GblType_flags ( GblType  self)

Returns the combined flags for a given type, including flags it has inherited.

◆ GblType_classRefCount()

GblRefCount GblType_classRefCount ( GblType  self)

Returns the reference counter for the given GblType's internally-managed default GblClass.

◆ GblType_instanceCount()

GblRefCount GblType_instanceCount ( GblType  self)

Returns the number of active instances of the given GblType.

◆ GblType_root()

GblType GblType_root ( GblType  self)

Returns the root parent GblType of the given GblType.

◆ GblType_base()

GblType GblType_base ( GblType  self,
size_t  depth 
)

Returns the base GblType of the given GblType, where a depth of 0 is its root.

◆ GblType_ancestor()

GblType GblType_ancestor ( GblType  self,
size_t  level 
)

Similar to GblType_base(), but in the reverse direction. level 0 is identity.

◆ GblType_depth()

size_t GblType_depth ( GblType  self)

Returns the depth of the given GblType, where a depth of 0 means it's a root type.

◆ GblType_verify()

GblBool GblType_verify ( GblType  self)

Returns GBL_TRUE if the given type is a valid, registred type.

◆ GblType_check()

GblBool GblType_check ( GblType  self,
GblType  other 
)

Returns GBL_TRUE if the given type can be safely cast to the other type.

◆ GblType_depends()

GblBool GblType_depends ( GblType  self,
GblType  dependency 
)

Returns GBL_TRUE if the given type depends on the dependency type.

◆ GblType_derives()

GblBool GblType_derives ( GblType  self,
GblType  superType 
)

Returns GBL_TRUE if the given type is a subtype, inheriting from superType.

◆ GblType_implements()

GblBool GblType_implements ( GblType  self,
GblType  ifaceType 
)

Returns GBL_TRUE if the given type has implemented ifaceType.

◆ GblType_common()

GblType GblType_common ( GblType  self,
GblType  other 
)

Returns the most-derived, deepest common-type between the given type and other.

◆ GblType_maps()

GblBool GblType_maps ( GblType  self,
GblType  iface 
)

Returns true if the given type's class contains an implementation of the iface interface.

◆ GblType_conforms()

GblBool GblType_conforms ( GblType  self,
GblType  dependent 
)

Returns true if the given type meets all type dependencies for the dependent type.