Main Page   Modules   Class Hierarchy   Compound List   File List   Compound Members   File Members  

utils.h File Reference

Various utility functions, macros and templates. More...

Go to the source code of this file.

Compounds

struct  IObjectImplInternal
 Helper internal structure. More...

struct  UUID_Info
 Utility structure used for the interface map. 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.


Detailed Description

Various utility functions, macros and templates.


Define Documentation

#define IMPLEMENT_IOBJECT component   
 

Value:

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; \
      \
    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.

See also:
UUID_MAP_BEGIN, UUID_MAP_ENTRY, UUID_MAP_ENTRY_2, UUID_MAP_END

#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.

The second parameter is the interface that should be used to disambiguate.

#define xplcdelete   delete
 

Internal macro.

This macro is needed to cooperate correctly with the "delete detector".


Function Documentation

template<class Interface>
Interface* get IObject   aObj
 

XPLC equivalent to dynamic_cast.

This templated function is a typesafe way to call the getInterface method of a component and cast it properly. If the component does not support the interface, a NULL pointer will be returned.

template<class Interface>
Interface* mutate IObject   aObj
 

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.


Generated on Sun Sep 26 04:01:25 2004 for XPLC by doxygen1.2.18