AtxReferenceable.h File Reference

Header file for the ATX_Referenceable interface. More...

#include "AtxInterfaces.h"
#include "AtxDefs.h"
#include "AtxTypes.h"
#include "AtxDebug.h"

Go to the source code of this file.

Defines

#define ATX_Referenceable_AddReference(object)   ATX_INTERFACE(object)->AddReference(object)
 Convenience macro used to call the AddReference() method on objects that implement the ATX_Referenceable interface.
#define ATX_Referenceable_Release(object)   ATX_INTERFACE(object)->Release(object)
 Convenience macro used to call the Release() method on objects that implement the ATX_Referenceable interface.
#define ATX_RELEASE_OBJECT(object)
 Macro used to safely release a reference on an object.
#define ATX_REFERENCE_OBJECT(object)
 Macro used to safely add a reference to an object.
#define ATX_IMPLEMENT_REFERENCEABLE_INTERFACE(_class, _counter)
#define ATX_IMPLEMENT_REFERENCEABLE_INTERFACE_EX(_class, _base, _counter)

Variables

ATX_Result(*) AddReference (ATX_Referenceable *self)
 Increments the reference counter.
ATX_Result(*) Release (ATX_Referenceable *self)
 Decrements the reference counter.


Detailed Description

Header file for the ATX_Referenceable interface.


Define Documentation

#define ATX_IMPLEMENT_REFERENCEABLE_INTERFACE ( _class,
_counter   ) 

Value:

ATX_METHOD _class##_AddReference(ATX_Referenceable* _self)         \
{                                                                  \
    _class* self = ATX_SELF(_class, ATX_Referenceable);            \
    self->_counter++;                                              \
    return ATX_SUCCESS;                                            \
}                                                                  \
ATX_METHOD _class##_Release(ATX_Referenceable* _self)              \
{                                                                  \
    _class* self = ATX_SELF(_class, ATX_Referenceable);            \
    if (--self->_counter == 0) {                                   \
        _class##_Destroy(self);                                    \
    }                                                              \
    return ATX_SUCCESS;                                            \
}                                                                  \
ATX_BEGIN_INTERFACE_MAP(_class, ATX_Referenceable)                 \
    _class##_AddReference,                                         \
    _class##_Release                                               \
};

#define ATX_IMPLEMENT_REFERENCEABLE_INTERFACE_EX ( _class,
_base,
_counter   ) 

Value:

ATX_METHOD _class##_AddReference(ATX_Referenceable* _self)                \
{                                                                         \
    _class* self = ATX_SELF_EX(_class, _base, ATX_Referenceable);         \
    ATX_BASE(self, _base)._counter++;                                     \
    return ATX_SUCCESS;                                                   \
}                                                                         \
ATX_METHOD _class##_Release(ATX_Referenceable* _self)                     \
{                                                                         \
    _class* self = ATX_SELF_EX(_class, _base, ATX_Referenceable);         \
    if (--ATX_BASE(self, _base)._counter == 0) {                          \
        _class##_Destroy(self);                                           \
    }                                                                     \
    return ATX_SUCCESS;                                                   \
}                                                                         \
ATX_BEGIN_INTERFACE_MAP_EX(_class, _base, ATX_Referenceable)              \
    _class##_AddReference,                                                \
    _class##_Release                                                      \
};

#define ATX_REFERENCE_OBJECT ( object   ) 

Value:

do {                                                          \
    if (object) {                                             \
        ATX_Referenceable* referenceable =                    \
            ATX_CAST(object, ATX_Referenceable);              \
        ATX_ASSERT(referenceable != NULL);                    \
        ATX_Referenceable_AddReference(referenceable);        \
    }                                                         \
} while(0)
Macro used to safely add a reference to an object.

This macro will try to get an ATX_Referenceable interface for the object. If the object does not implement that interface, an exception is thrown. If the object implements that interface, the macro will call the AddReference() method.

#define ATX_RELEASE_OBJECT ( object   ) 

Value:

do {                                                          \
    if (object) {                                             \
        ATX_Referenceable* referenceable =                    \
            ATX_CAST(object, ATX_Referenceable);              \
        ATX_ASSERT(referenceable != NULL);                    \
        ATX_Referenceable_Release(referenceable);             \
        object = NULL;                                        \
    }                                                         \
} while(0)
Macro used to safely release a reference on an object.

This macro will try to get an ATX_Referenceable interface for the object. If the object does not implement that interface, an exception is thrown. If the object implements that interface, the macro will call the Release() method. As a side effect, this macro will also clear its object reference to turn it into a NULL object reference, so that further use of that object reference may be prevented


Variable Documentation

ATX_Result(*) AddReference(ATX_Referenceable *self)

Increments the reference counter.

Parameters:
self Pointer to the object on which this method is called

ATX_Result(*) Release(ATX_Referenceable *self)

Decrements the reference counter.

Parameters:
self Pointer to the object on which this method is called