WvStreams
|
Various utility functions, macros and templates. More...
#include <stddef.h>
#include <xplc/core.h>
#include <xplc/IWeakRef.h>
Go to the source code of this file.
Classes | |
struct | UUID_Info |
Utility structure used for the interface map. More... | |
struct | IObjectImplInternal |
Helper internal structure. More... | |
class | WeakRef |
Common implementation of a weak reference. More... | |
Defines | |
#define | UUID_MAP_BEGIN(component) const UUID_Info component::xplc_iobject_uuids[] = { |
Start the interface map for "component". | |
#define | UUID_MAP_ENTRY(iface) { &iface##_IID, reinterpret_cast<ptrdiff_t>(static_cast<iface*>(reinterpret_cast<ThisXPLCComponent*>(1))) - 1 }, |
Add an entry to an interface map. | |
#define | UUID_MAP_ENTRY_2(iface, iface2) { &iface##_IID, reinterpret_cast<ptrdiff_t>(static_cast<iface2*>(reinterpret_cast<ThisXPLCComponent*>(1))) - 1 }, |
Add an entry to an interface map for an ambiguous interface. | |
#define | UUID_MAP_END { 0, 0 } }; |
Marks the end of an interface map. | |
#define | xplcdelete delete |
Internal macro. | |
#define | IMPLEMENT_IOBJECT(component) |
Helper macro to implement the IObject methods automatically. | |
Functions | |
template<class Interface > | |
Interface * | get (IObject *aObj) |
XPLC equivalent to dynamic_cast. | |
template<class Interface > | |
Interface * | mutate (IObject *aObj) |
A version of get() that releases its parameter. |
Various utility functions, macros and templates.
Definition in file utils.h.
#define UUID_MAP_ENTRY_2 | ( | iface, | |
iface2 | |||
) | { &iface##_IID, reinterpret_cast<ptrdiff_t>(static_cast<iface2*>(reinterpret_cast<ThisXPLCComponent*>(1))) - 1 }, |
#define xplcdelete delete |
#define IMPLEMENT_IOBJECT | ( | component | ) |
private: \ IObjectImplInternal xplc_iobject_internal; \ static const UUID_Info xplc_iobject_uuids[]; \ typedef component ThisXPLCComponent; \ public: \ virtual unsigned int addRef() { \ return ++xplc_iobject_internal.refcount; \ } \ virtual unsigned int release() { \ if(--xplc_iobject_internal.refcount) \ return xplc_iobject_internal.refcount; \ /* protect against re-entering the destructor */ \ xplc_iobject_internal.refcount = 1; \ if(xplc_iobject_internal.weakref) { \ xplc_iobject_internal.weakref->release(); \ xplc_iobject_internal.weakref->object = 0; \ } \ xplcdelete this; \ return 0; \ } \ virtual IObject* getInterface(const UUID& uuid) { \ return xplc_iobject_internal.getInterface(this, uuid, xplc_iobject_uuids); \ } \ virtual IWeakRef* getWeakRef() { \ if(!xplc_iobject_internal.weakref) \ xplc_iobject_internal.weakref = new WeakRef(reinterpret_cast<IObject*>(reinterpret_cast<ptrdiff_t>(this) + xplc_iobject_uuids->delta)); \ xplc_iobject_internal.weakref->addRef(); \ return xplc_iobject_internal.weakref; \ }
Helper macro to implement the IObject methods automatically.
Put this at the beginning of your class, specifiying the class name as the parameter, and it will automatically implement all the IObject methods. You also need to define an interface map.
A version of get() that releases its parameter.
This templated function is very similar to the "get" one, except that it automatically releases the inbound reference, without regard whether the getInterface actually yielded something.
Definition at line 198 of file utils.h.
References IObject::getInterface(), and IObject::release().