ASN1C C/C++ Common Runtime  ASN1C v7.4.x
OSRTContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2020 Objective Systems, Inc.
3  *
4  * This software is furnished under a license and may be used and copied
5  * only in accordance with the terms of such license and with the
6  * inclusion of the above copyright notice. This software or any other
7  * copies thereof may not be provided or otherwise made available to any
8  * other person. No title to and ownership of the software is hereby
9  * transferred.
10  *
11  * The information in this software is subject to change without notice
12  * and should not be construed as a commitment by Objective Systems, Inc.
13  *
14  * PROPRIETARY NOTICE
15  *
16  * This software is an unpublished work subject to a confidentiality agreement
17  * and is protected by copyright and trade secret law. Unauthorized copying,
18  * redistribution or other use of this work is prohibited.
19  *
20  * The above notice of copyright on this source code product does not indicate
21  * any actual or intended publication of such source code.
22  *
23  *****************************************************************************/
24 /*The following is the text for the main C++ Runtime index page.*/
46 #ifndef _OSRTCONTEXT_H_
47 #define _OSRTCONTEXT_H_
48 
49 #include "rtxsrc/rtxContext.h"
50 #include "rtxsrc/rtxDiag.h"
51 #include "rtxsrc/rtxError.h"
52 #include "rtxsrc/rtxMemory.h"
53 
54 #if defined(_MSC_VER)
55 // this disables 'unreferenced inline function has been removed' warning
56 #pragma warning(disable: 4514)
57 #endif
58 
64 class EXTRTCLASS OSRTContext {
65  private:
66  EXTRTMETHOD OSRTContext (OSCTXT*);
67 
68  protected:
74 
78  OSUINT32 mCount;
79 
83  OSBOOL mbInitialized;
84 
90  int mStatus;
91 
92  public:
97  EXTRTMETHOD OSRTContext ();
98 
102  virtual EXTRTMETHOD ~OSRTContext ();
103 
109  inline OSCTXT* getPtr () { return &mCtxt; }
110 
111  inline const OSCTXT* getPtr () const { return &mCtxt; }
112 
116  EXTRTMETHOD OSUINT32 getRefCount();
117 
124  inline int getStatus () const {
125  return (0 == mStatus) ? rtxErrGetLastError (&mCtxt) : mStatus;
126  }
127 
132  inline OSBOOL isInitialized () { return mbInitialized; }
133 
137  EXTRTMETHOD void _ref();
138 
142  EXTRTMETHOD void _unref();
143 
152  EXTRTMETHOD char* getErrorInfo ();
153 
166  EXTRTMETHOD char* getErrorInfo (size_t* pBufSize);
167 
184  EXTRTMETHOD char* getErrorInfo (char* pBuf, size_t& bufSize);
185 
195  inline void* memAlloc (size_t numocts) {
196  return rtxMemAlloc (&mCtxt, numocts);
197  }
198 
208  inline void* memAllocZ (size_t numocts) {
209  return rtxMemAllocZ (&mCtxt, numocts);
210  }
211 
218  inline void memFreeAll () {
219  rtxMemFree (&mCtxt);
220  }
221 
230  inline void memFreePtr (void* ptr) {
231  rtxMemFreePtr (&mCtxt, ptr);
232  }
233 
243  inline void* memRealloc (void* ptr, size_t numocts) {
244  return rtxMemRealloc (&mCtxt, ptr, numocts);
245  }
246 
251  inline void memReset () {
252  rtxMemReset (&mCtxt);
253  }
254 
259  inline void printErrorInfo () {
260  rtxErrPrint (&mCtxt);
261  }
262 
267  inline void resetErrorInfo () {
268  mStatus = 0;
269  rtxErrReset (&mCtxt);
270  }
271 
278  inline OSBOOL setDiag (OSBOOL value=TRUE) {
279  return rtxSetDiag (&mCtxt, value);
280  }
281 
292  virtual EXTRTMETHOD int setRunTimeKey (const OSOCTET* key, size_t keylen);
293 
300  int setStatus (int stat);
301 
302 };
303 
310 class EXTRTCLASS OSRTCtxtPtr {
311  protected:
317 
318  public:
325  OSRTCtxtPtr (OSRTContext* rf = 0) : mPointer(rf) {
326  if (mPointer != 0) mPointer->_ref();
327  }
328 
335  OSRTCtxtPtr (const OSRTCtxtPtr& o) : mPointer(o.mPointer) {
336  if (mPointer != 0) mPointer->_ref();
337  }
338 
344  virtual ~OSRTCtxtPtr() { if (mPointer != 0) mPointer->_unref(); }
345 
354  OSRTCtxtPtr& operator= (const OSRTCtxtPtr& rf) {
355  if (mPointer != 0) mPointer->_unref();
356  mPointer = rf.mPointer;
357  if (mPointer != 0) mPointer->_ref();
358  return *this;
359  }
360 
365  OSRTCtxtPtr& operator= (OSRTContext* rf) {
366  if (mPointer != 0) mPointer->_unref();
367  mPointer = rf;
368  if (mPointer != 0) mPointer->_ref();
369  return *this;
370  }
371 
375  operator OSRTContext* () { return mPointer; }
376  operator const OSRTContext* () const { return mPointer; }
377 
381  OSRTContext* operator -> () { return mPointer; }
382  const OSRTContext* operator -> () const { return mPointer; }
383 
387  OSBOOL operator == (const OSRTContext* o) const {
388  return (mPointer == o);
389  }
390 
394  inline OSBOOL isNull() const { return (mPointer == 0); }
395 
400  inline OSCTXT* getCtxtPtr() { return isNull() ? 0 : mPointer->getPtr(); }
401 
402 };
403 
408 EXTERNRT void* operator new (size_t nbytes, OSCTXT* pctxt);
409 
414 EXTERNRT void operator delete (void* pmem, OSCTXT* pctxt);
415 
421 class EXTRTCLASS OSRTElemNameGuard {
422 protected:
423  OSCTXT* mpCtxt;
424 
425 public:
426  OSRTElemNameGuard (OSCTXT* pctxt, const char* elemName) : mpCtxt(pctxt)
427  {
428  rtxCtxtPushElemName (mpCtxt, OSUTF8(elemName));
429  }
431  {
432  rtxCtxtPopElemName (mpCtxt);
433  }
434 } ;
435 
436 #endif // _OSRTCONTEXT_H_
#define rtxMemAllocZ(pctxt, nbytes)
Definition: rtxMemory.h:340
void * memAllocZ(size_t numocts)
Definition: OSRTContext.h:208
void memReset()
Definition: OSRTContext.h:251
OSCTXT mCtxt
Definition: OSRTContext.h:73
const OSUTF8CHAR * rtxCtxtPopElemName(OSCTXT *pctxt)
EXTRTMETHOD void _ref()
OSBOOL isInitialized()
Definition: OSRTContext.h:132
void resetErrorInfo()
Definition: OSRTContext.h:267
void rtxErrPrint(OSCTXT *pctxt)
void rtxMemReset(OSCTXT *pctxt)
int operator==(const ASN1OBJID &lhs, const ASN1OBJID &rhs)
OSBOOL mbInitialized
Definition: OSRTContext.h:83
int rtxCtxtPushElemName(OSCTXT *pctxt, const OSUTF8CHAR *elemName)
#define rtxMemAlloc(pctxt, nbytes)
Definition: rtxMemory.h:315
virtual ~OSRTCtxtPtr()
Definition: OSRTContext.h:344
Definition: OSRTContext.h:310
int rtxErrGetLastError(const OSCTXT *pctxt)
int mStatus
Definition: OSRTContext.h:90
#define rtxMemRealloc(pctxt, mem_p, nbytes)
Definition: rtxMemory.h:374
void memFreeAll()
Definition: OSRTContext.h:218
OSCTXT * getCtxtPtr()
Definition: OSRTContext.h:400
Definition: OSRTContext.h:64
OSUINT32 mCount
Definition: OSRTContext.h:78
void printErrorInfo()
Definition: OSRTContext.h:259
OSBOOL setDiag(OSBOOL value=TRUE)
Definition: OSRTContext.h:278
OSCTXT * getPtr()
Definition: OSRTContext.h:109
int rtxErrReset(OSCTXT *pctxt)
void memFreePtr(void *ptr)
Definition: OSRTContext.h:230
OSBOOL isNull() const
Definition: OSRTContext.h:394
EXTRTMETHOD void _unref()
Definition: rtxContext.h:189
#define rtxMemFreePtr(pctxt, mem_p)
Definition: rtxMemory.h:407
OSRTCtxtPtr(const OSRTCtxtPtr &o)
Definition: OSRTContext.h:335
OSRTContext * mPointer
Definition: OSRTContext.h:316
OSBOOL rtxSetDiag(OSCTXT *pctxt, OSBOOL value)
int getStatus() const
Definition: OSRTContext.h:124
void rtxMemFree(OSCTXT *pctxt)
Definition: OSRTContext.h:421
void * memRealloc(void *ptr, size_t numocts)
Definition: OSRTContext.h:243
void * memAlloc(size_t numocts)
Definition: OSRTContext.h:195
OSRTCtxtPtr(OSRTContext *rf=0)
Definition: OSRTContext.h:325