home *** CD-ROM | disk | FTP | other *** search
/ DOS/V Power Report 1996 November / VPR9611B.ISO / vabasic / ntclnt.exe / DISK8 / data.8 / datab / INCLUDE / DLLCLASS.HH < prev    next >
Text File  |  1996-07-29  |  4KB  |  182 lines

  1. /*****************************************************************************
  2.  ***   $Source: /rcs/crcs/general/dllclass.hh,v $
  3.  ***   Checked int by: $Author: patrice $
  4.  ***   $Date: 1995/11/27 01:28:16 $
  5.  ***   $Revision: 1.8 $
  6.  *****************************************************************************
  7.  ***                                       ***
  8.  ***          Copyright (c) 1994, Visual Edge Software Ltd.           ***
  9.  ***                                        ***
  10.  ***   All rights reserved.  This notice is  intended  as  a  precaution   ***
  11.  ***   against    inadvertent publication, and shall not be deemed to con-   ***
  12.  ***   stitute an acknowledgment that publication has  occurred     nor  to   ***
  13.  ***   imply  any  waiver  of confidentiality.    The year included in the   ***
  14.  ***   notice is the year of the creation of the work.               ***
  15.  ***                                        ***
  16.  *****************************************************************************/
  17. //      Copyright (c) International Business Machines Inc, 1995
  18.  
  19. #ifndef DLLCLASS_HH
  20. #define DLLCLASS_HH
  21.  
  22. #include <stdlib.h>
  23. #include <vealloc.h>
  24.  
  25. #ifdef new
  26. // We are in debugging malloc mode: undefine the new operator for now.
  27. #undef new
  28. #undef OP_NEW
  29. #endif
  30.  
  31. //-----------------------------------------------------------------------------
  32. // Class VeDllBasedClass
  33. //    Base class for all objects which are to be located in DLL's
  34. //    Provides new and delete operator for the class.
  35. //    These operators make sure the memory is allocated in the correct
  36. //    location.  This also provides support for the debugging VeMalloc.
  37. // LAST REV:    January 31, 1995  Fix8122
  38. //-----------------------------------------------------------------------------
  39.  
  40. class VeDllBasedClass
  41. {
  42.     public:
  43.  
  44.     // Due to bugs in the HP C++ compiler inline operators
  45.     // must be defined inside the class definition.
  46.     
  47. #if defined(MEMDEBUG) && !defined(NOVIPERNEW)
  48.  
  49.     void* operator new(size_t size, const char *fname, unsigned lnum)
  50.     {
  51.         return VeDebugMalloc(size, fname, lnum);
  52.     }
  53.  
  54. #ifdef ANSIcplusplus
  55.  
  56.     void* operator new[](size_t size, const char *fname, unsigned lnum)
  57.     {
  58.         return VeDebugMalloc(size, fname, lnum);
  59.     }
  60.  
  61. #endif // ANSIcplusplus
  62.  
  63. #endif // defined(MEMDEBUG) && !defined(NOVIPERNEW)
  64.  
  65. #ifdef __DEBUG_ALLOC__
  66.     void* operator new(size_t size, const char *, size_t)
  67. #else
  68.     void* operator new(size_t size)
  69. #endif
  70.     {
  71.         return VeMalloc(size);
  72.     }
  73.  
  74. #ifdef ANSIcplusplus
  75.  
  76.     void* operator new[](size_t size)
  77.     {
  78.         return VeMalloc(size);
  79.     }
  80.  
  81. #endif // ANSIcplusplus
  82.  
  83. #ifdef __DEBUG_ALLOC__
  84.     void operator delete(void *pntr, const char *, size_t)
  85. #else
  86.     void operator delete(void *pntr)
  87. #endif
  88.     {
  89.         VeFree(pntr);
  90.     }
  91. };
  92.  
  93. //=============================================================================
  94.  
  95. #if defined(MEMDEBUG) && !defined(NOVIPERNEW)
  96.  
  97. #define VNEW_LOC(b)                              \
  98.     void* operator new(size_t size, const char *fname, unsigned lnum) \
  99.     {                                  \
  100.         return b::operator new (size, fname, lnum);          \
  101.     }
  102.  
  103. #ifdef ANSIcplusplus
  104.  
  105. #define VNEWARRAY_LOC(b)                            \
  106.     void* operator new[](size_t size, const char *fname, unsigned lnum) \
  107.     {                                    \
  108.         return b::operator new (size, fname, lnum);            \
  109.     }
  110.  
  111. #else // ANSIcplusplus
  112.  
  113. #define VNEWARRAY_LOC(b)
  114.  
  115. #endif // ANSIcplusplus
  116.  
  117. #else // MEMDEBUG && !NOVIPERNEW
  118.  
  119. #define VNEW_LOC(b)
  120. #define VNEWARRAY_LOC(b)
  121.  
  122. #endif // MEMDEBUG && !NOVIPERNEW
  123.  
  124. #ifdef __DEBUG_ALLOC__
  125. #define VNEW(b)                \
  126.      void *operator new (size_t size, const char *fname, size_t line) \
  127.     {                    \
  128.         return b::operator new (size, fname, line);    \
  129.     }
  130. #else
  131. #define VNEW(b)                \
  132.      void *operator new (size_t size)    \
  133.     {                    \
  134.         return b::operator new (size);    \
  135.     }
  136. #endif
  137.  
  138. #ifdef ANSIcplusplus
  139.  
  140. #ifdef __DEBUG_ALLOC__
  141. #define VNEWARRAY(b)                \
  142.      void *operator new[](size_t size, const char *fname, size_t line) \
  143.     {                    \
  144.         return b::operator new (size, fname, line);    \
  145.     }
  146. #else
  147. #define VNEWARRAY(b)                \
  148.      void *operator new[](size_t size)    \
  149.     {                    \
  150.         return b::operator new (size);    \
  151.     }
  152. #endif
  153.  
  154. #else // ANSIcplusplus
  155.  
  156. #define VNEWARRAY(b)
  157.  
  158. #endif // ANSIcplusplus
  159.  
  160. #ifdef __DEBUG_ALLOC__
  161. #define VDELETE(b)                \
  162.     void operator delete (void *ptr, const char *fname, size_t line) \
  163.     {                    \
  164.         b::operator delete (ptr, fname, line);    \
  165.     }
  166. #else
  167. #define VDELETE(b)                \
  168.     void operator delete (void *ptr)    \
  169.     {                    \
  170.         b::operator delete (ptr);    \
  171.     }
  172. #endif
  173.  
  174. #define VMI_ALLOCATION(b)     VNEW(b)            \
  175.                 VNEWARRAY(b)        \
  176.                 VDELETE(b)
  177.  
  178. // Redefine the new operator now that we are done.
  179. #include <defnew.hh>
  180.  
  181. #endif // DLLCLASS_HH
  182.