34 #ifndef __XPLC_UTILS_H__ 35 #define __XPLC_UTILS_H__ 37 #if defined(__GNUC__) && __GNUC__ > 3 38 # pragma GCC system_header 47 #include <xplc/core.h> 48 #include <xplc/IWeakRef.h> 63 #define UUID_MAP_BEGIN(component) const UUID_Info component::xplc_iobject_uuids[] = { 68 #define UUID_MAP_ENTRY(iface) { &iface##_IID, reinterpret_cast<ptrdiff_t>(static_cast<iface*>(reinterpret_cast<ThisXPLCComponent*>(1))) - 1 }, 75 #define UUID_MAP_ENTRY_2(iface, iface2) { &iface##_IID, reinterpret_cast<ptrdiff_t>(static_cast<iface2*>(reinterpret_cast<ThisXPLCComponent*>(1))) - 1 }, 80 #define UUID_MAP_END { 0, 0 } }; 103 IObject* getInterface(
void*
self,
const UUID& uuid,
112 #define xplcdelete delete 123 #define IMPLEMENT_IOBJECT(component) \ 125 IObjectImplInternal xplc_iobject_internal; \ 126 static const UUID_Info xplc_iobject_uuids[]; \ 127 typedef component ThisXPLCComponent; \ 129 virtual unsigned int addRef() { \ 130 return ++xplc_iobject_internal.refcount; \ 132 virtual unsigned int release() { \ 133 if(--xplc_iobject_internal.refcount) \ 134 return xplc_iobject_internal.refcount; \ 136 xplc_iobject_internal.refcount = 1; \ 137 if(xplc_iobject_internal.weakref) { \ 138 xplc_iobject_internal.weakref->release(); \ 139 xplc_iobject_internal.weakref->object = 0; \ 144 virtual IObject* getInterface(const UUID& uuid) { \ 145 return xplc_iobject_internal.getInterface(this, uuid, xplc_iobject_uuids); \ 147 virtual IWeakRef* getWeakRef() { \ 148 if(!xplc_iobject_internal.weakref) \ 149 xplc_iobject_internal.weakref = new WeakRef(reinterpret_cast<IObject*>(reinterpret_cast<ptrdiff_t>(this) + xplc_iobject_uuids->delta)); \ 150 xplc_iobject_internal.weakref->addRef(); \ 151 return xplc_iobject_internal.weakref; \ 183 template<
class Interface>
197 template<
class Interface>
The basic interface which is included by all other XPLC interfaces and objects.
virtual unsigned int release()=0
Indicate that you are finished using this object.
The structure underlying UUIDs.
IObject * object
The object that the weak reference is pointing at.
#define IMPLEMENT_IOBJECT(component)
Helper macro to implement the IObject methods automatically.
unsigned int refcount
Holds the reference count.
Represents a weak reference to another object.
Common implementation of a weak reference.
Utility structure used for the interface map.
virtual IObject * getInterface(const UUID &)=0
Returns the requested XPLC interface.
Helper internal structure.
Interface * mutate(IObject *aObj)
A version of get() that releases its parameter.
WeakRef(IObject *aObj)
Initialize a weak reference.
virtual unsigned int addRef()=0
Indicate you are using this object.
virtual IObject * getObject()
Obtains an addRef()'d strong reference to the referenced object.
WeakRef * weakref
Pointer to a weak reference object.