00001
00014 #ifndef __EMAIOBJECT_HPP__
00015 #define __EMAIOBJECT_HPP__
00016
00017 #include <EmaiExceptions.hpp>
00018
00024 namespace Emai
00025 {
00026
00031 template <class ObjectType>
00032 class Object
00033 {
00034 protected:
00035 Object();
00036 ~Object();
00037
00038 Object(
00039 ObjectType inObject,
00040 bool inAddRef);
00041 Object(
00042 const Object& inCopy);
00043 Object& operator = (
00044 const Object& inCopy);
00045
00046 ObjectType mObject;
00047
00048 typedef Object<ObjectType> Parent;
00049
00050 public:
00051
00055 void AddRef();
00056
00065 void Release();
00066
00073 EmaiUint32 RefCount();
00074
00084 void SetUserData(
00085 EmaiUint32 inKey,
00086 const void* inData,
00087 EmaiUint32 inDataSize);
00088
00100 void GetUserData(
00101 EmaiUint32 inKey,
00102 void* outData,
00103 EmaiUint32& ioDataSize);
00104
00105 operator ObjectType() const;
00106 };
00107
00108
00109
00110
00111
00112 template <class ObjectType>
00113 Object<ObjectType>::Object(
00114 ObjectType inObject,
00115 bool inAddRef
00116 ):
00117 mObject(inObject)
00118 {
00119 if (inAddRef)
00120 AddRef();
00121 }
00122
00123 template <class ObjectType>
00124 Object<ObjectType>::Object():
00125 mObject(NULL)
00126 {
00127 }
00128
00129 template <class ObjectType>
00130 Object<ObjectType>::Object(
00131 const Object<ObjectType>& inCopy
00132 ):
00133 mObject(NULL)
00134 {
00135 if (inCopy.mObject != NULL)
00136 {
00137 CheckErrorCode(EmaiObjectAddRef(inCopy.mObject));
00138 mObject = inCopy.mObject;
00139 }
00140 }
00141
00142 template <class ObjectType>
00143 Object<ObjectType>&
00144 Object<ObjectType>::operator = (
00145 const Object<ObjectType>& inCopy
00146 )
00147 {
00148 Release();
00149 mObject = NULL;
00150
00151 if (inCopy.mObject != NULL)
00152 CheckErrorCode(EmaiObjectAddRef(inCopy.mObject));
00153
00154 mObject = inCopy.mObject;
00155 return *this;
00156 }
00157
00158 template <class ObjectType>
00159 Object<ObjectType>::~Object()
00160 {
00161 Release();
00162 }
00163
00164 template <class ObjectType>
00165 void
00166 Object<ObjectType>::AddRef()
00167 {
00168 if (mObject != NULL)
00169 CheckErrorCode(EmaiObjectAddRef(mObject));
00170 }
00171
00172 template <class ObjectType>
00173 void
00174 Object<ObjectType>::Release()
00175 {
00176 if (mObject != NULL)
00177 CheckErrorCode(EmaiObjectRelease(mObject));
00178 }
00179
00180 template <class ObjectType>
00181 EmaiUint32
00182 Object<ObjectType>::RefCount()
00183 {
00184 EmaiUint32 refCount = 0;
00185 CheckErrorCode(EmaiObjectGetRefCount(mObject, &refCount));
00186 return refCount;
00187 }
00188
00189 template <class ObjectType>
00190 void
00191 Object<ObjectType>::SetUserData(
00192 EmaiUint32 inKey,
00193 const void* inData,
00194 EmaiUint32 inDataSize
00195 )
00196 {
00197 CheckErrorCode(EmaiObjectSetUserData(mObject, inKey, inData, inDataSize));
00198 }
00199
00200 template <class ObjectType>
00201 void
00202 Object<ObjectType>::GetUserData(
00203 EmaiUint32 inKey,
00204 void* outData,
00205 EmaiUint32& ioDataSize
00206 )
00207 {
00208 CheckErrorCode(EmaiObjectGetUserData(mObject, inKey, outData, &ioDataSize));
00209 }
00210
00211 template <class ObjectType>
00212 Object<ObjectType>::operator ObjectType() const
00213 {
00214 return mObject;
00215 }
00216
00217 }
00218
00219
00220 #endif