libGimbal 0.1.0
C17-Based Extended Standard Library and Cross-Language Runtime Framework
Loading...
Searching...
No Matches
gimbal::Context Class Reference
Inheritance diagram for gimbal::Context:
GblContext GblObject GblBox GblITableVariant GblInstance

Public Member Functions

const CallRecord & getCallRecord (void) const
 
void clearCallRecord (void)
 
virtual void logPush (const StackFrame &frame)
 
virtual void logPop (const StackFrame &frame, uint32_t count)
 
virtual void logWrite (const StackFrame &frame, LogLevel level, const char *pFmt, va_list varArgs)
 
virtual void * memAlloc (const StackFrame &frame, Size size, Size alignment, const char *pDebugInfoStr)
 
virtual void * memRealloc (const StackFrame &frame, void *pPtr, Size newSize, Size newAlign)
 
virtual void memFree (const StackFrame &frame, void *pPtr)
 
virtual void * do_allocate (size_t bytes, size_t align) override
 
virtual void do_deallocate (void *pPtr, size_t bytes, size_t align) override
 
virtual bool do_is_equal (const memory_resource &other) const noexcept override
 

Static Public Member Functions

static ContextfromGblObj (GblContext *pContext)
 
static Version getVersion (void)
 

Additional Inherited Members

- Data Fields inherited from GblContext
union { 
 
   GblContextClass *   pClass 
 
   GblObject   base 
 
};  
 
GblCallRecord lastIssue
 
uint32_t logStackDepth
 
GblFlags logFilter
 
- Data Fields inherited from GblObject
union { 
 
   GblObjectClass *   pClass 
 
   GblBox   base 
 
};  
 
- Data Fields inherited from GblBox
union { 
 
   GblBoxClass *   pClass 
 
   GblInstance   base 
 
};  
 
struct { 
 
   GblArrayMap *   pFields 
 
   volatile uint16_t   refCounter 
 
   uint16_t   contextType: 1 
 
   uint16_t   constructedInPlace: 1 
 
   uint16_t   derivedFlags: 14 
 
private_ 
 
- Data Fields inherited from GblInstance
GblClasspClass
 

Detailed Description

Definition at line 38 of file gimbal_context.hpp.

Constructor & Destructor Documentation

◆ Context()

gimbal::Context::Context ( void  )
inline

Definition at line 51 of file gimbal_context.hpp.

51 {
52
53 pOldClass_ = GBL_CONTEXT_CLASS(GblClass_createFloating(GBL_CONTEXT_TYPE));
54 GblContextClass* pClass = GBL_CONTEXT_CLASS(GblClass_createFloating(GBL_CONTEXT_TYPE));
55
56 pClass->iAllocatorIFace.pFnAlloc = gblMemAlloc_;
57 pClass->iAllocatorIFace.pFnRealloc = gblMemRealloc_;
58 pClass->iAllocatorIFace.pFnFree = gblMemFree_;
59 pClass->iLoggerIFace.pFnWrite = gblLogWrite_;
60 pClass->iLoggerIFace.pFnPush = gblLogPush_;
61 pClass->iLoggerIFace.pFnPop = gblLogPop_;
62
63 Exception::checkThrow(GblInstance_constructWithClass(GBL_INSTANCE(static_cast<GblContext*>(this)), GBL_CLASS(pClass)));
64
65 GblObject_userdataSet(GBL_OBJECT(static_cast<GblContext*>(this)), this);
66
67 }
GblClass * GblClass_createFloating(GblType type, size_t size)
Creates a standalone, unowned, "floating" class for the given type, which can override defaults.
#define GBL_INSTANCE(self)
Casts GblInstance-compatible to GblInstance.
#define GBL_OBJECT(self)
Casts a GblInstance to a GblObject.
GblClass structure for GblContext.
Top-level context object.
GblContextClass * pClass
Pointer to class/vtable structure.
GBL_RESULT(* pFnFree)(GblIAllocator *pSelf, const GblStackFrame *pFrame, void *pData)
Virtual method invoked when a free is requested.
GBL_RESULT(* pFnRealloc)(GblIAllocator *pSelf, const GblStackFrame *pFrame, void *pData, size_t newSize, size_t newAlign, void **ppNewData)
Virtual method invoked when a reallocation is requested.
GBL_RESULT(* pFnAlloc)(GblIAllocator *pSelf, const GblStackFrame *pFrame, size_t size, size_t align, const char *pDbgStr, void **ppData)
Virtual method invoked when an allocation is requested.

◆ ~Context()

virtual gimbal::Context::~Context ( void  )
inlinevirtual

Definition at line 70 of file gimbal_context.hpp.

70 {
71 GblInstance_destruct(GBL_INSTANCE(static_cast<GblContext*>(this)));
72 GblClass_destroyFloating(GBL_CLASS(pOldClass_));
73 }
GBL_RESULT GblClass_destroyFloating(GblClass *pSelf)
Destroys the standalone, "floating" class, releasing its memory allocation.
GblRefCount GblInstance_destruct(GblInstance *pSelf)
Destructs but doesn't deallocate an instance. It must have been created with GblInstance_construct().

Member Function Documentation

◆ fromGblObj()

static Context * gimbal::Context::fromGblObj ( GblContext pContext)
inlinestatic

Definition at line 45 of file gimbal_context.hpp.

45 {
46 return pContext ?
47 static_cast<Context*>(GblObject_userdata(GBL_OBJECT(pContext)))
48 : NULL;
49 }

◆ getVersion()

static Version gimbal::Context::getVersion ( void  )
inlinestatic

Definition at line 76 of file gimbal_context.hpp.

76 {
77 Version version;
78 //Exception::checkThrow(gblContextVersion(&version, nullptr));
79 return version;
80 }

◆ getCallRecord()

const CallRecord & gimbal::Context::getCallRecord ( void  ) const
inline

Definition at line 83 of file gimbal_context.hpp.

83 {
84 return *static_cast<const CallRecord*>(&this->lastIssue);
85 }

◆ clearCallRecord()

void gimbal::Context::clearCallRecord ( void  )
inline

Definition at line 87 of file gimbal_context.hpp.

87 {
88 Exception::checkThrow(GblContext_lastIssueClear(this));
89 }

◆ logPush()

virtual void gimbal::Context::logPush ( const StackFrame &  frame)
inlinevirtual

Definition at line 94 of file gimbal_context.hpp.

94 {
95 GBL_API_BEGIN(frame.pContext);
96 GBL_API_CALL(pOldClass_->iLoggerIFace.pFnPush((GblILogger*)static_cast<GblContext*>(this), &frame));
97 GBL_API_END_BLOCK();
98 Exception::checkThrow(GBL_API_RESULT());
99 }

◆ logPop()

virtual void gimbal::Context::logPop ( const StackFrame &  frame,
uint32_t  count 
)
inlinevirtual

Definition at line 100 of file gimbal_context.hpp.

100 {
101 gimbal::Result result = pOldClass_->iLoggerIFace.pFnPop((GblILogger*)static_cast<GblContext*>(this), &frame, count);
102 Exception::checkThrow(result);
103 }

◆ logWrite()

virtual void gimbal::Context::logWrite ( const StackFrame &  frame,
LogLevel  level,
const char *  pFmt,
va_list  varArgs 
)
inlinevirtual

Definition at line 104 of file gimbal_context.hpp.

104 {
105 GBL_API_BEGIN(static_cast<GblContext*>(this));
106 GBL_API_CALL(pOldClass_->iLoggerIFace.pFnWrite((GblILogger*)static_cast<GblContext*>(this), &frame, level, pFmt, varArgs));
107 GBL_API_END_BLOCK();
108 Exception::checkThrow(GBL_API_RESULT());
109 }

◆ memAlloc()

virtual void * gimbal::Context::memAlloc ( const StackFrame &  frame,
Size  size,
Size  alignment,
const char *  pDebugInfoStr 
)
inlinevirtual

Definition at line 111 of file gimbal_context.hpp.

111 {
112 void* pPtr = nullptr;
113 GBL_API_BEGIN(static_cast<GblContext*>(this));
114 GBL_API_CALL(pOldClass_->iAllocatorIFace.pFnAlloc((GblIAllocator*)static_cast<GblContext*>(this), &frame, size, alignment, pDebugInfoStr, &pPtr));
115 GBL_API_END_BLOCK();
116 Exception::checkThrow(GBL_API_RESULT());
117 return pPtr;
118 }

◆ memRealloc()

virtual void * gimbal::Context::memRealloc ( const StackFrame &  frame,
void *  pPtr,
Size  newSize,
Size  newAlign 
)
inlinevirtual

Definition at line 120 of file gimbal_context.hpp.

120 {
121 void* pNewPtr = nullptr;
122 GBL_API_BEGIN(static_cast<GblContext*>(this));
123 GBL_API_CALL(pOldClass_->iAllocatorIFace.pFnRealloc((GblIAllocator*)static_cast<GblContext*>(this), &frame, pPtr, newSize, newAlign, &pNewPtr));
124 GBL_API_END_BLOCK();
125 Exception::checkThrow(GBL_API_RESULT());
126 return pNewPtr;
127 }

◆ memFree()

virtual void gimbal::Context::memFree ( const StackFrame &  frame,
void *  pPtr 
)
inlinevirtual

Definition at line 129 of file gimbal_context.hpp.

129 {
130 GBL_API_BEGIN(static_cast<GblContext*>(this));
131 GBL_API_CALL(pOldClass_->iAllocatorIFace.pFnFree((GblIAllocator*)static_cast<GblContext*>(this), &frame, pPtr));
132 GBL_API_END_BLOCK();
133 Exception::checkThrow(GBL_API_RESULT());
134 }

◆ do_allocate()

virtual void * gimbal::Context::do_allocate ( size_t  bytes,
size_t  align 
)
inlineoverridevirtual

Definition at line 137 of file gimbal_context.hpp.

137 {
138 GBL_API_BEGIN(static_cast<GblContext*>(this));
139 void* pValue = nullptr;
140 try {
141 pValue = GBL_API_MALLOC(bytes, align, "PMR SHIT!");
142 } GBL_RESULT_CATCH(GBL_API_RESULT());
143 GBL_API_END_BLOCK();
144 return pValue;
145 }

◆ do_deallocate()

virtual void gimbal::Context::do_deallocate ( void *  pPtr,
size_t  bytes,
size_t  align 
)
inlineoverridevirtual

Definition at line 146 of file gimbal_context.hpp.

146 {
147 GBL_UNUSED(bytes); GBL_UNUSED(align);
148 GBL_API_BEGIN(static_cast<GblContext*>(this));
149 try {
150 GBL_API_FREE(pPtr);
151 } GBL_RESULT_CATCH(GBL_API_RESULT());
152 GBL_API_END_BLOCK();
153 }

◆ do_is_equal()

virtual bool gimbal::Context::do_is_equal ( const memory_resource &  other) const
inlineoverridevirtualnoexcept

Definition at line 154 of file gimbal_context.hpp.

154 {
155 return this == &other;
156 }

The documentation for this class was generated from the following file: