|
CppInterOp
C++ Language Interoperability Layer
|
#include "include/CppInterOp/Box.h"
Classes | |
| struct | ObjectOps |
| Operations vtable for a K_PtrOrObj payload. More... | |
Public Types | |
| enum | Kind : int { K_Bool , K_Char_S , K_SChar , K_UChar , K_Short , K_UShort , K_Int , K_UInt , K_Long , K_ULong , K_LongLong , K_ULongLong , K_Float , K_Double , K_LongDouble , K_Char_U , K_Void , K_PtrOrObj , K_Unspecified } |
Public Member Functions | |
| Box ()=default | |
| Box (const Box &o) noexcept | |
| Box & | operator= (const Box &o) noexcept |
| Box (Box &&o) noexcept | |
| Box & | operator= (Box &&o) noexcept |
| ~Box () noexcept | |
| Kind | getKind () const noexcept |
| void * | getType () const noexcept |
| template<class T > | |
| T | unbox () const noexcept |
| AOT-typed extraction. | |
| void * | getObjectPtr () const noexcept |
| Object payload accessor; only valid for K_PtrOrObj. | |
| template<class T > | |
| T | convertTo () const noexcept |
Runtime convert across Kinds: dispatches on the actual Kind and returns the value reinterpreted (via static_cast) as T. | |
| template<class V > | |
| auto | visit (V &&vis) const -> decltype(vis(int{})) |
| Runtime-typed dispatch via visitor. | |
Static Public Member Functions | |
| template<class T > | |
| static Box | Create (T x, void *type=nullptr) noexcept |
| AOT-typed construction for fundamentals. | |
| static Box | AdoptObject (void *obj, const ObjectOps *ops, void *type) noexcept |
| Object-payload construction. | |
| enum Cpp::Box::Kind : int |
|
default |
|
inlinenoexcept |
Definition at line 149 of file Box.h.
References K_PtrOrObj.
|
inlinenoexcept |
Definition at line 167 of file Box.h.
References K_Unspecified.
|
inlinenoexcept |
Definition at line 184 of file Box.h.
References K_PtrOrObj.
Referenced by operator=(), and operator=().
|
inlinestaticnoexcept |
Object-payload construction.
obj enters with refcount 1 (the producer's invariant); ~Box calls ops->release(obj) which on the last drop runs the payload's destructor. The ops table is const-static, defined in the TU that knows the concrete payload type.
Definition at line 225 of file Box.h.
References K_PtrOrObj.
Referenced by compat::MakeValueBox().
|
inlinenoexcept |
Runtime convert across Kinds: dispatches on the actual Kind and returns the value reinterpreted (via static_cast) as T.
Mirrors clang::Value::convertTo<T>. Only valid for fundamental Kinds (K_Bool ... K_LongDouble); K_PtrOrObj / K_Void / K_Unspecified are caller-must-check-Kind cases.
Definition at line 247 of file Box.h.
References visit().
|
inlinestaticnoexcept |
|
inlinenoexcept |
Object payload accessor; only valid for K_PtrOrObj.
Returns the raw pointer set at AdoptObject time. Layout is producer-defined – the producer that installed the ObjectOps knows how to extract the underlying object.
Definition at line 238 of file Box.h.
References K_PtrOrObj.
Definition at line 172 of file Box.h.
References K_Unspecified, and ~Box().
Definition at line 156 of file Box.h.
References K_PtrOrObj, and ~Box().
|
inlinenoexcept |
AOT-typed extraction.
T must match the runtime Kind exactly (UB to read an inactive union member otherwise – e.g. calling unbox<int>() on a K_Long Box). For unknown-kind extraction use visit() or check getKind() against KindOf<T>() first. The assert is a no-op under NDEBUG so the AOT-fold path stays zero-overhead.
|
inline |
Runtime-typed dispatch via visitor.
Switch over Kind, call visitor with the typed T extracted from storage. K_PtrOrObj / K_Void / K_* non-fundamental kinds are not dispatched – caller checks Kind first.
Definition at line 257 of file Box.h.
Referenced by convertTo().