ASN1C C/C++ Common Runtime  ASN1C v7.2.x
OSRTContext.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2003-2018 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.*/
47 #ifndef _OSRTCONTEXT_H_
48 #define _OSRTCONTEXT_H_
49 
50 #include "rtxsrc/rtxContext.h"
51 #include "rtxsrc/rtxDiag.h"
52 #include "rtxsrc/rtxError.h"
53 #include "rtxsrc/rtxMemory.h"
54 
55 #if defined(_MSC_VER)
56 // this disables 'unreferenced inline function has been removed' warning
57 #pragma warning(disable: 4514)
58 #endif
59 
65 class EXTRTCLASS OSRTContext {
66  private:
67  EXTRTMETHOD OSRTContext (OSCTXT*);
68 
69  protected:
75 
79  OSUINT32 mCount;
80 
84  OSBOOL mbInitialized;
85 
91  int mStatus;
92 
93  public:
98  EXTRTMETHOD OSRTContext ();
99 
103  virtual EXTRTMETHOD ~OSRTContext ();
104 
110  inline OSCTXT* getPtr () { return &mCtxt; }
111 
112  inline const OSCTXT* getPtr () const { return &mCtxt; }
113 
117  EXTRTMETHOD OSUINT32 getRefCount();
118 
125  inline int getStatus () const {
126  return (0 == mStatus) ? rtxErrGetLastError (&mCtxt) : mStatus;
127  }
128 
133  inline OSBOOL isInitialized () { return mbInitialized; }
134 
138  EXTRTMETHOD void _ref();
139 
143  EXTRTMETHOD void _unref();
144 
153  EXTRTMETHOD char* getErrorInfo ();
154 
167  EXTRTMETHOD char* getErrorInfo (size_t* pBufSize);
168 
185  EXTRTMETHOD char* getErrorInfo (char* pBuf, size_t& bufSize);
186 
196  inline void* memAlloc (size_t numocts) {
197  return rtxMemAlloc (&mCtxt, numocts);
198  }
199 
209  inline void* memAllocZ (size_t numocts) {
210  return rtxMemAllocZ (&mCtxt, numocts);
211  }
212 
219  inline void memFreeAll () {
220  rtxMemFree (&mCtxt);
221  }
222 
231  inline void memFreePtr (void* ptr) {
232  rtxMemFreePtr (&mCtxt, ptr);
233  }
234 
244  inline void* memRealloc (void* ptr, size_t numocts) {
245  return rtxMemRealloc (&mCtxt, ptr, numocts);
246  }
247 
252  inline void memReset () {
253  rtxMemReset (&mCtxt);
254  }
255 
260  inline void printErrorInfo () {
261  rtxErrPrint (&mCtxt);
262  }
263 
268  inline void resetErrorInfo () {
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 
416 #endif // _OSRTCONTEXT_H_
#define rtxMemAllocZ(pctxt, nbytes)
Definition: rtxMemory.h:326
void * memAllocZ(size_t numocts)
Definition: OSRTContext.h:209
void memReset()
Definition: OSRTContext.h:252
OSCTXT mCtxt
Definition: OSRTContext.h:74
EXTRTMETHOD void _ref()
OSBOOL isInitialized()
Definition: OSRTContext.h:133
void resetErrorInfo()
Definition: OSRTContext.h:268
void rtxErrPrint(OSCTXT *pctxt)
void rtxMemReset(OSCTXT *pctxt)
int operator==(const ASN1OBJID &lhs, const ASN1OBJID &rhs)
OSBOOL mbInitialized
Definition: OSRTContext.h:84
#define rtxMemAlloc(pctxt, nbytes)
Definition: rtxMemory.h:301
virtual ~OSRTCtxtPtr()
Definition: OSRTContext.h:344
Definition: OSRTContext.h:310
int rtxErrGetLastError(const OSCTXT *pctxt)
int mStatus
Definition: OSRTContext.h:91
#define rtxMemRealloc(pctxt, mem_p, nbytes)
Definition: rtxMemory.h:360
void memFreeAll()
Definition: OSRTContext.h:219
OSCTXT * getCtxtPtr()
Definition: OSRTContext.h:400
Definition: OSRTContext.h:65
OSUINT32 mCount
Definition: OSRTContext.h:79
void printErrorInfo()
Definition: OSRTContext.h:260
OSBOOL setDiag(OSBOOL value=TRUE)
Definition: OSRTContext.h:278
OSCTXT * getPtr()
Definition: OSRTContext.h:110
int rtxErrReset(OSCTXT *pctxt)
void memFreePtr(void *ptr)
Definition: OSRTContext.h:231
OSBOOL isNull() const
Definition: OSRTContext.h:394
EXTRTMETHOD void _unref()
Definition: rtxContext.h:185
#define rtxMemFreePtr(pctxt, mem_p)
Definition: rtxMemory.h:393
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:125
void rtxMemFree(OSCTXT *pctxt)
void * memRealloc(void *ptr, size_t numocts)
Definition: OSRTContext.h:244
void * memAlloc(size_t numocts)
Definition: OSRTContext.h:196
OSRTCtxtPtr(OSRTContext *rf=0)
Definition: OSRTContext.h:325