home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / Sources / FWGrObj.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  5.9 KB  |  191 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWGrObj.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWGROBJ_H
  13. #include "FWGrObj.h"
  14. #endif
  15.  
  16. #ifndef FWGRGLOB_H
  17. #include "FWGrGlob.h"
  18. #endif
  19.  
  20. // ----- Foundation Includes -----
  21.  
  22. #ifndef FWSTREAM_H
  23. #include "FWStream.h"
  24. #endif
  25.  
  26. #ifndef FWCLAINF_H
  27. #include "FWClaInf.h"
  28. #endif
  29.  
  30. // ----- OpenDoc Includes -----
  31.  
  32. //========================================================================================
  33. //    RunTime Info
  34. //========================================================================================
  35.  
  36. #if FW_LIB_EXPORT_PRAGMAS
  37. #pragma lib_export on
  38. #endif
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment fwgraphx
  42. #endif
  43.  
  44. FW_DEFINE_CLASS_M0(FW_CGraphicCountedPtrRep)
  45. FW_DEFINE_CLASS_M0(FW_CGraphicCountedPtr)
  46.  
  47. //========================================================================================
  48. //    class FW_CGraphicCountedPtrRep
  49. //========================================================================================
  50.  
  51. //----------------------------------------------------------------------------------------
  52. //    FW_CGraphicCountedPtrRep::FW_CGraphicCountedPtrRep
  53. //----------------------------------------------------------------------------------------
  54.  
  55. FW_CGraphicCountedPtrRep::FW_CGraphicCountedPtrRep() :
  56.     fRefCount(0)
  57. {
  58. }
  59.  
  60. //----------------------------------------------------------------------------------------
  61. //    FW_CGraphicCountedPtrRep::~FW_CGraphicCountedPtrRep
  62. //----------------------------------------------------------------------------------------
  63.  
  64. FW_CGraphicCountedPtrRep::~FW_CGraphicCountedPtrRep()
  65. {
  66. }
  67.  
  68. //----------------------------------------------------------------------------------------
  69. //    FW_CGraphicCountedPtrRep::Purge
  70. //----------------------------------------------------------------------------------------
  71.  
  72. void FW_CGraphicCountedPtrRep::Purge()
  73. {
  74. }
  75.  
  76. //----------------------------------------------------------------------------------------
  77. //    FW_CGraphicCountedPtrRep::Write
  78. //----------------------------------------------------------------------------------------
  79.  
  80. void FW_CGraphicCountedPtrRep::Write(FW_CWritableStream& archive, const void* rep)
  81. {
  82.     ((FW_CGraphicCountedPtrRep*)rep)->Flatten(archive);
  83. }
  84.  
  85. //========================================================================================
  86. //    class FW_CGraphicCountedPtr
  87. //========================================================================================
  88.  
  89. //----------------------------------------------------------------------------------------
  90. //    FW_CGraphicCountedPtr::~FW_CGraphicCountedPtr
  91. //----------------------------------------------------------------------------------------
  92.  
  93. FW_CGraphicCountedPtr::~FW_CGraphicCountedPtr()
  94. {
  95.     FW_START_DESTRUCTOR
  96.     DownCount();
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //    FW_CGraphicCountedPtr::FW_CGraphicCountedPtr
  101. //----------------------------------------------------------------------------------------
  102.  
  103. FW_CGraphicCountedPtr::FW_CGraphicCountedPtr() :
  104.     fRep(NULL)
  105. {
  106.     FW_END_CONSTRUCTOR
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CGraphicCountedPtr::FW_CGraphicCountedPtr
  111. //----------------------------------------------------------------------------------------
  112.  
  113. FW_CGraphicCountedPtr::FW_CGraphicCountedPtr(const FW_CGraphicCountedPtr& other) :
  114.     fRep(other.fRep)
  115. {
  116.     UpCount();
  117.     FW_END_CONSTRUCTOR
  118. }
  119.  
  120. //----------------------------------------------------------------------------------------
  121. //    FW_CGraphicCountedPtr::UpCount
  122. //----------------------------------------------------------------------------------------
  123.  
  124. void FW_CGraphicCountedPtr::UpCount()
  125. {
  126.     if (fRep)
  127.         fRep->IncrementRefCount();
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    FW_CGraphicCountedPtr::DownCount
  132. //----------------------------------------------------------------------------------------
  133.  
  134. void FW_CGraphicCountedPtr::DownCount()
  135. {    
  136.     if (fRep && !fRep->Release())
  137.         delete fRep;
  138.     // It is not necessary to set fRep to NULL. To see why, see how DownCount is used above.
  139.     // In all cases, fRep is either immediately reset, or the instance is being destroyed.
  140.     // Note too that DownCount is private.
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. //    FW_CGraphicCountedPtr::SetRep
  145. //----------------------------------------------------------------------------------------
  146.  
  147. void FW_CGraphicCountedPtr::SetRep(FW_CGraphicCountedPtrRep* rep)
  148. {
  149.     if (fRep != rep)
  150.     {
  151.         DownCount();
  152.         fRep = rep;
  153.         UpCount();
  154.     }
  155. }
  156.  
  157. //========================================================================================
  158. //    Global operators << and >>
  159. //========================================================================================
  160.  
  161. //----------------------------------------------------------------------------------------
  162. //    operator>>
  163. //----------------------------------------------------------------------------------------
  164.  
  165. FW_FUNC_ATTR FW_CReadableStream& operator>>(FW_CReadableStream& archive, FW_CGraphicCountedPtr &object)
  166. {
  167.     FW_CGraphicCountedPtrRep* rep = NULL;
  168.     
  169.     void * voidPtr = (void *)rep;
  170.     FW_CDynamicArchiver::InputObject(archive, voidPtr);
  171.     rep = (FW_CGraphicCountedPtrRep*)voidPtr;
  172.  
  173.     FW_ASSERT(rep != NULL);        // Should be an exception???
  174.  
  175.     object.SetRep(rep);
  176.     
  177.     return archive;
  178. }
  179.  
  180. //----------------------------------------------------------------------------------------
  181. //    operator<<
  182. //----------------------------------------------------------------------------------------
  183.  
  184. FW_FUNC_ATTR FW_CWritableStream& operator<<(FW_CWritableStream& archive, const FW_CGraphicCountedPtr &object)
  185. {
  186.     FW_CDynamicArchiver::OutputObject(archive, object.GetRep(), FW_CLASSNAME_FROM_POINTER(object.GetRep()));
  187.     return archive;
  188. }
  189.  
  190.  
  191.