libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal_opaque.h
Go to the documentation of this file.
1/*! \file
2 * \brief GblOpaqueClass and API for managing Opaque types
3 * \ingroup meta
4 *
5 * \author 2023 Falco Girgis
6 * \copyright MIT License
7 */
8#ifndef GIMBAL_OPAQUE_H
9#define GIMBAL_OPAQUE_H
10
12
13/*! \name Type System
14 * \brief Type UUID and cast macros
15 * @{
16 */
17#define GBL_OPAQUE_TYPE (GBL_TYPEID(GblOpaque)) //!< Type UUID for GblOpaque
18#define GBL_OPAQUE_CLASS(klass) (GBL_CLASS_CAST(GblOpaque, klass)) //!< Function-style GblOpaqueClass cast from GblClass
19//! @}
20
22
23//! Function signature for for an opaque copy operation, see \ref GblOpaqueVTable::pFnCopy
24typedef GBL_RESULT (*GblOpaqueCopyFn)(void* pOpaque, void** ppNewOpaque);
25//! Function signature for an opaque free operation, see \ref GblOpaqueVTable::pFnFree
26typedef GBL_RESULT (*GblOpaqueFreeFn)(void* pOpaque);
27
28//! Virtual table structure for a GblOpaqueClass
29typedef struct GblOpaqueVTable {
30 GblOpaqueCopyFn pFnCopy; //!< Copy method
31 GblOpaqueFreeFn pFnFree; //!< Free method
32} GblOpaqueVTable;
33
34/*! \struct GblOpaqueClass
35 * \extends GblPrimitiveClass
36 * \brief GblClass structure for opaque types
37 *
38 * Simply contains a virtual table pointer
39 * to the implementation details.
40 */
41GBL_CLASS_DERIVE(GblOpaque, GblPrimitive)
42 const GblOpaqueVTable* pVTable; //!< Pointer to the virtual table structure
44
45/*! \name Static Methods
46 * \brief Miscellaenous and Utility methods
47 * @{
48 */
49//! Returns the GblType UUID for GblOpaque
51//! Registers an opaque subtype with the virtual table given by \p pVTable
53 const GblOpaqueVTable* pVTable) GBL_NOEXCEPT;
54
55GBL_EXPORT GblType GblOpaque_registerRef (const char* pName) GBL_NOEXCEPT;
56//! @}
57
58/*! \name Instance Methods
59 * \brief Methods for dealing with opaque instances (usually handled internally)
60 * @{
61 */
62//! Copies an opaque structure with the given type into \p ppNewOpaque, using its vtable
63GBL_EXPORT GBL_RESULT GblOpaque_copy (void* pOpaque,
64 GblType type,
65 void** ppNewOpaque) GBL_NOEXCEPT;
66//! Frees an opaque structure with the given type using its vtable
67GBL_EXPORT GBL_RESULT GblOpaque_free (void* pOpaque,
69//! @}
70
72
73#endif // GIMBAL_Opaque_H
#define GBL_CLASS_CAST(cType, klass)
#define GBL_NOEXCEPT
#define GBL_DECLS_BEGIN
#define GBL_TYPEID(instanceStruct)
#define GBL_CLASS_DERIVE(...)
#define GBL_EXPORT
#define GBL_CLASS_END
GBL_RESULT GblOpaque_free(void *pOpaque, GblType type)
Frees an opaque structure with the given type using its vtable.
GBL_RESULT GblOpaque_copy(void *pOpaque, GblType type, void **ppNewOpaque)
Copies an opaque structure with the given type into ppNewOpaque, using its vtable.
GblType GblOpaque_register(const char *pName, const GblOpaqueVTable *pVTable)
Registers an opaque subtype with the virtual table given by pVTable.
GblType GblOpaque_type(void)
Returns the GblType UUID for GblOpaque.
uintptr_t GblType
Meta Type UUID.
Definition gimbal_type.h:51
const GblOpaqueVTable * pVTable
Pointer to the virtual table structure.
Virtual table structure for a GblOpaqueClass.
GblOpaqueCopyFn pFnCopy
Copy method.
GblOpaqueFreeFn pFnFree
Free method.