home *** CD-ROM | disk | FTP | other *** search
/ Info-Mac 3 / Info_Mac_1994-01.iso / Development / Source / Arashi 1.1 Source / For your think c folder / Juri's Class Library / CBaseObject.c next >
Encoding:
C/C++ Source or Header  |  1993-02-09  |  1.6 KB  |  105 lines  |  [TEXT/KAHL]

  1. /*/
  2.      Project Arashi: CBaseObject.c
  3.      Major release: Version 1.1, 7/22/92
  4.  
  5.      Last modification: Tuesday, February 9, 1993, 8:51
  6.      Created: Friday, October 23, 1992, 16:22
  7.  
  8.      Copyright © 1992-1993, Juri Munkki
  9. /*/
  10.  
  11. #include <CBaseObject.h>
  12.  
  13. void    CBaseObject::IBaseObject()
  14. {
  15.     lockCounter = 0;
  16. }
  17.  
  18. void    CBaseObject::Lock()
  19. {
  20.     if(!lockCounter)
  21.         HLock((Handle)this);
  22.     lockCounter++;
  23. }
  24.  
  25. void    CBaseObject::Unlock()
  26. {
  27.     if(lockCounter != 0)
  28.     {    if(--lockCounter == 0)
  29.         {    HUnlock((Handle)this);
  30.         }
  31.     }
  32. }
  33.  
  34. void    CBaseObject::ForceUnlock()
  35. {
  36.     if(lockCounter > 1) lockCounter = 1;
  37.     Unlock();
  38. }    
  39.  
  40. void    CBaseObject::Dispose()
  41. {
  42.     delete(this);
  43. }
  44.  
  45. /*
  46. **    This is a utility method for all
  47. **    my classes. The idea is to make
  48. **    copying Handles that are part of
  49. **    an object easy like this:
  50. **
  51. **        thing = CloneHandle(thing);
  52. **
  53. **    Note that you can't simply call
  54. **    HandToHand(&thing), because thing
  55. **    is an instance variable in a block
  56. **    that might move.
  57. */
  58. void    *CBaseObject::CloneHandle(
  59.     void    *theHandle)
  60. {
  61.     short    state;
  62.     
  63.     state = HGetState(theHandle);
  64.     HandToHand(&theHandle);
  65.     if(theHandle)
  66.         HSetState(theHandle, state);
  67.     
  68.     return theHandle;
  69. }
  70.  
  71. /*
  72. **    Never call this method, but override it,
  73. **    if you are writing a class that should
  74. **    duplicate handles when an object is cloned.
  75. */
  76. void    CBaseObject::CloneFields()
  77. {
  78.  
  79. }
  80.  
  81. /*
  82. **    Call clone to make a deep copy of the object.
  83. */
  84. void    *CBaseObject::Clone()
  85. {
  86.     CBaseObject    *myCopy;
  87.     short        state;
  88.     
  89.     myCopy = this;
  90.     
  91.     state = HGetState(this);
  92.     HandToHand(&myCopy);
  93.     
  94.     if(myCopy)
  95.     {    HSetState(myCopy,state);
  96.         myCopy->CloneFields();
  97.     }
  98.     
  99.     return myCopy;
  100. }
  101.  
  102. long    CBaseObject::HowMuchMemory()
  103. {
  104.     return GetHandleSize(this);
  105. }