OSRTContext.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00047 #ifndef _OSRTCONTEXT_H_
00048 #define _OSRTCONTEXT_H_
00049
00050 #include "rtxsrc/rtxContext.h"
00051 #include "rtxsrc/rtxDiag.h"
00052 #include "rtxsrc/rtxError.h"
00053 #include "rtxsrc/rtxMemory.h"
00054
00055 #if defined(_MSC_VER)
00056
00057 #pragma warning(disable: 4514)
00058 #endif
00059
00065 class EXTERNRTX OSRTContext {
00066 private:
00067 OSRTContext (OSCTXT*);
00068
00069 protected:
00074 OSCTXT mCtxt;
00075
00079 OSUINT32 mCount;
00080
00084 OSBOOL mbInitialized;
00085
00091 int mStatus;
00092
00093 public:
00098 OSRTContext ();
00099
00103 virtual ~OSRTContext ();
00104
00110 inline OSCTXT* getPtr () { return &mCtxt; }
00111
00112 inline const OSCTXT* getPtr () const { return &mCtxt; }
00113
00117 OSUINT32 getRefCount();
00118
00125 inline int getStatus () const {
00126 return (0 == mStatus) ? rtxErrGetLastError (&mCtxt) : mStatus;
00127 }
00128
00133 inline OSBOOL isInitialized () { return mbInitialized; }
00134
00138 void _ref();
00139
00143 void _unref();
00144
00152 char* getErrorInfo ();
00153
00163 char* getErrorInfo (size_t* pBufSize);
00164
00181 char* getErrorInfo (char* pBuf, size_t& bufSize);
00182
00192 inline void* memAlloc (size_t numocts) {
00193 return rtxMemAlloc (&mCtxt, numocts);
00194 }
00195
00202 inline void memFreeAll () {
00203
00204 }
00205
00214 inline void memFreePtr (void* ptr) {
00215 rtxMemFreePtr (&mCtxt, ptr);
00216 }
00217
00227 inline void* memRealloc (void* ptr, size_t numocts) {
00228 return rtxMemRealloc (&mCtxt, ptr, numocts);
00229 }
00230
00235 inline void memReset () {
00236
00237 }
00238
00243 inline void printErrorInfo () {
00244 rtxErrPrint (&mCtxt);
00245 }
00246
00251 inline void resetErrorInfo () {
00252 rtxErrReset (&mCtxt);
00253 }
00254
00261 inline OSBOOL setDiag (OSBOOL value=TRUE) {
00262 return rtxSetDiag (&mCtxt, value);
00263 }
00264
00275 virtual int setRunTimeKey (const OSOCTET* key, size_t keylen);
00276
00283 inline int setStatus (int stat) {
00284 mStatus = stat;
00285 return stat;
00286 }
00287
00288 };
00289
00296 class EXTERNRTX OSRTCtxtPtr {
00297 protected:
00302 OSRTContext* mPointer;
00303
00304 public:
00311 OSRTCtxtPtr (OSRTContext* rf = 0) : mPointer(rf) {
00312 if (mPointer != 0) mPointer->_ref();
00313 }
00314
00321 OSRTCtxtPtr (const OSRTCtxtPtr& o) : mPointer(o.mPointer) {
00322 if (mPointer != 0) mPointer->_ref();
00323 }
00324
00330 virtual ~OSRTCtxtPtr() { if (mPointer != 0) mPointer->_unref(); }
00331
00340 OSRTCtxtPtr& operator= (const OSRTCtxtPtr& rf) {
00341 if (mPointer != 0) mPointer->_unref();
00342 mPointer = rf.mPointer;
00343 if (mPointer != 0) mPointer->_ref();
00344 return *this;
00345 }
00346
00351 OSRTCtxtPtr& operator= (OSRTContext* rf) {
00352 if (mPointer != 0) mPointer->_unref();
00353 mPointer = rf;
00354 if (mPointer != 0) mPointer->_ref();
00355 return *this;
00356 }
00357
00361 operator OSRTContext* () { return mPointer; }
00362 operator const OSRTContext* () const { return mPointer; }
00363
00367 OSRTContext* operator -> () { return mPointer; }
00368 const OSRTContext* operator -> () const { return mPointer; }
00369
00373 OSBOOL operator == (const OSRTContext* o) const {
00374 return (mPointer == o);
00375 }
00376
00380 inline OSBOOL isNull() const { return (mPointer == 0); }
00381
00386 inline OSCTXT* getCtxtPtr() { return isNull() ? 0 : mPointer->getPtr(); }
00387
00388 };
00389
00394 EXTERNRTX void* operator new (size_t nbytes, OSCTXT* pctxt);
00395
00400 EXTERNRTX void operator delete (void* pmem, OSCTXT* pctxt);
00401
00402 #endif // _OSRTCONTEXT_H_