home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / CLASS.ZIP / OBJECT.CC < prev    next >
Text File  |  1993-02-14  |  4KB  |  177 lines

  1. #include "object.h"
  2. #include "memory.h"
  3.  
  4.  
  5. object::object(void)
  6. {
  7. #ifdef SHOWCALLS
  8.     fprintf(stderr, "Calling object(%x)\n", this);
  9. #endif
  10.        bSuccessfullConstructed = TRUE;
  11.        DosCreateMutexSem((unsigned char*)0, &hMtxAccess, 0, FALSE);
  12. }
  13.  
  14.  
  15. object::~object(void)
  16. {    
  17. #ifdef SHOWCALLS
  18.     fprintf(stderr, "Calling ~object(%x)\n", this);
  19. #endif
  20.        DosCloseMutexSem(hMtxAccess);
  21. }
  22.  
  23.  
  24. void *object::operator new(unsigned int iSize)
  25. {       unsigned int *pObject;
  26.  
  27.         if (!(pObject = malloc(iSize + sizeof(unsigned int))))
  28.                return (void *)0;
  29.         *pObject = iSize;
  30.         memset(pObject += 1, 0, iSize);
  31.         return (void*)pObject;
  32. }
  33.  
  34.  
  35. void object::operator delete(void *pObject)
  36. {      unsigned int *pSize;
  37.        memset(pObject, 0, *(pSize = ((unsigned int*)pObject - 1)));
  38.        free(pSize);
  39. }
  40.  
  41.  
  42. void construct::doSomething(void)
  43. {
  44. #ifdef SHOWCALLS
  45.        fprintf(stderr, "construct::doSomething(%x)\n", this);
  46. #endif SHOWCALLS
  47. }
  48.  
  49.  
  50. //     Only if init() is direct called
  51. void construct::destructAll()
  52. {
  53. #ifdef SHOWCALLS
  54.        fprintf(stderr, "construct::destructAll(%x)\n", this);
  55. #endif SHOWCALLS
  56.        if (bSuccessfullConstructed)
  57.        {       destructPre();
  58.                destruct();
  59.                destructPost();
  60.        }
  61. }
  62.  
  63.  
  64. void construct::run(void)
  65. {
  66. #ifdef SHOWCALLS
  67.        fprintf(stderr, "construct::run(%x)\n", this);
  68. #endif SHOWCALLS
  69. #ifdef DEBUG
  70.        fprintf(stderr, "this->doSomething() = %x\n", &this->doSomething);
  71. #endif
  72.        if (init())
  73.        {       printFileLine();
  74. #ifdef DEBUG
  75.        fprintf(stderr, "doSomething() = %x\n", &this->doSomething);
  76. #endif
  77.                doSomething();
  78.                printFileLine();
  79.                destructAll();
  80.        }
  81. #ifdef SHOWCALLS
  82.        fprintf(stderr, "Leaving construct::run(%x)\n", this);
  83. #endif SHOWCALLS
  84. }
  85.  
  86.  
  87. Boolean construct::init(void)
  88. {
  89. #ifdef SHOWCALLS
  90.        fprintf(stderr, "construct::init(%x)\n", this);
  91. #endif SHOWCALLS
  92. #ifdef DEBUG
  93.        fprintf(stderr, "this->doSomething() = %x\n", &this->doSomething);
  94. #endif
  95.       if (bSuccessfullConstructed)
  96.        {       if (initPre())
  97.                        if (create())
  98.                        {
  99. #ifdef SHOWCALLS
  100.        fprintf(stderr,"Calling initPost(%x) inside construct::init(%x)\n", this, this);
  101. #endif
  102.                                if (initPost())
  103.                                        return TRUE;
  104.                                else
  105.                                {       destruct();
  106.                                        destructPost();
  107.                                        bSuccessfullConstructed = FALSE;
  108.                                        return FALSE;
  109.                                }
  110.                        }
  111.                        else
  112.                        {       destructPost();
  113.                                bSuccessfullConstructed = FALSE;
  114.                                return FALSE;
  115.                        }
  116.                else
  117.                {       bSuccessfullConstructed = FALSE;
  118.                        return FALSE;
  119.                }
  120.        }
  121.        else
  122.        {       bSuccessfullConstructed = FALSE;
  123.                return FALSE;
  124.        }
  125. }
  126.  
  127.  
  128. Boolean construct::initPre(void)
  129. {
  130. #ifdef SHOWCALLS
  131.        fprintf(stderr, "construct::initPre(%x)\n", this);
  132. #endif SHOWCALLS
  133.       return TRUE;
  134. }
  135.  
  136.  
  137. Boolean construct::create(void)
  138. {
  139. #ifdef SHOWCALLS
  140.        fprintf(stderr, "construct::create(%x)\n", this);
  141. #endif SHOWCALLS
  142.       return TRUE;
  143. }
  144.  
  145.  
  146. Boolean construct::initPost(void)
  147. {
  148. #ifdef SHOWCALLS
  149.        fprintf(stderr, "construct::initPost(%x)\n", this);
  150. #endif SHOWCALLS
  151.       return TRUE;
  152. }
  153.  
  154.  
  155. void construct::destructPost(void)
  156. {
  157. #ifdef SHOWCALLS
  158.        fprintf(stderr, "construct::destructPost(%x)\n", this);
  159. #endif SHOWCALLS
  160. }
  161.  
  162.  
  163. void construct::destructPre(void)
  164. {
  165. #ifdef SHOWCALLS
  166.        fprintf(stderr, "construct::destructPre(%x)\n", this);
  167. #endif SHOWCALLS
  168. }
  169.  
  170.  
  171. void construct::destruct(void)
  172. {
  173. #ifdef SHOWCALLS
  174.        fprintf(stderr, "construct::destruct(%x)\n", this);
  175. #endif SHOWCALLS
  176. }
  177.