home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Utilities / RefCtCol.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  5.6 KB  |  184 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        RefCtCol.cpp
  3.  
  4.     Contains:    ODRefCntCollection of ODRefCntObject
  5.  
  6.     Owned by:    David McCusker
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.      
  11.  
  12. */
  13.  
  14. #ifndef _REFCTCOL_
  15. #include "RefCtCol.h"
  16. #endif
  17.  
  18. #ifndef __EXCEPT__
  19. #include "Except.h"
  20. #endif
  21.  
  22. #ifndef _ODNEW_
  23. #include "ODNew.h"
  24. #endif
  25.  
  26. #pragma segment ODCollections
  27.  
  28. //------------------------------------------------------------------------------
  29. // ODObjectOrdColl::^ODObjectOrdColl
  30. //------------------------------------------------------------------------------
  31.  
  32. ODObjectOrdColl::~ODObjectOrdColl()
  33. {
  34. }
  35.  
  36. //------------------------------------------------------------------------------
  37. // ODObjectOrdColl::ElementsMatch (OVERRIDE)
  38. //------------------------------------------------------------------------------
  39.  
  40. ODBoolean ODObjectOrdColl::ElementsMatch(ElementType v1,ElementType v2) const
  41. {
  42.     Environment* ev = somGetGlobalEnvironment();
  43.     return ODObjectsAreEqual(ev, (ODObject*) v1, (ODObject*) v2);
  44. }
  45.  
  46. //======================================================================================
  47. // Class ODRefCntCollection
  48. //======================================================================================
  49.  
  50. //------------------------------------------------------------------------------
  51. // ODRefCntCollection::ODRefCntCollection
  52. //------------------------------------------------------------------------------
  53.  
  54. ODRefCntCollection::ODRefCntCollection(Environment* ev)
  55.     : fCol( ), fEv( ev )
  56. {
  57. }
  58.  
  59. //------------------------------------------------------------------------------
  60. // ODRefCntCollection::ODRefCntCollection
  61. //------------------------------------------------------------------------------
  62.  
  63.  
  64. ODRefCntCollection::ODRefCntCollection(Environment* ev, ODMemoryHeapID where)
  65.     : fCol( where ), fEv( ev )
  66. {
  67. }
  68.  
  69. // ODRefCntCollection::~ODRefCntCollection
  70. //------------------------------------------------------------------------------
  71.  
  72. ODRefCntCollection::~ODRefCntCollection()
  73. {
  74.     this->RemoveAndReleaseAll();
  75. }
  76.  
  77. //------------------------------------------------------------------------------
  78. // ODRefCntCollection::AddFirst
  79. //------------------------------------------------------------------------------
  80.  
  81. void ODRefCntCollection::AddFirstAndAcquire(ODRefCntObject* element)
  82. {
  83.     fCol.OrderedCollection::AddLast(element);
  84.     ODAcquireObject(fEv, element); // function, not macro
  85. }
  86.  
  87. //------------------------------------------------------------------------------
  88. // ODRefCntCollection::AddLast
  89. //------------------------------------------------------------------------------
  90.  
  91. void ODRefCntCollection::AddLastAndAcquire(ODRefCntObject* element)
  92. {
  93.     fCol.OrderedCollection::AddLast(element);
  94.     ODAcquireObject(fEv, element); // function, not macro
  95. }
  96.  
  97. //------------------------------------------------------------------------------
  98. // ODRefCntCollection::AddBefore
  99. //------------------------------------------------------------------------------
  100.  
  101. void ODRefCntCollection::AddBeforeAndAcquire(ODRefCntObject* existing, ODRefCntObject* tobeadded)
  102. {
  103.     fCol.OrderedCollection::AddBefore(existing, tobeadded);
  104.     ODAcquireObject(fEv, tobeadded); // function, not macro
  105. }
  106.  
  107. //------------------------------------------------------------------------------
  108. // ODRefCntCollection::AddAfter
  109. //------------------------------------------------------------------------------
  110.  
  111. void ODRefCntCollection::AddAfterAndAcquire(ODRefCntObject* existing, ODRefCntObject* tobeadded)
  112. {
  113.     fCol.OrderedCollection::AddAfter(existing, tobeadded);
  114.     ODAcquireObject(fEv, tobeadded); // function, not macro
  115. }
  116.  
  117. //------------------------------------------------------------------------------
  118. // ODRefCntCollection::RemoveAndRelease
  119. //------------------------------------------------------------------------------
  120.  
  121. ODBoolean ODRefCntCollection::RemoveAndRelease(ODRefCntObject* existing)
  122. {
  123.     ODBoolean removed = fCol.OrderedCollection::Remove(existing);
  124.     if ( removed )
  125.         ODRelease(fEv, existing); // function, not macro
  126.     return removed;
  127. }
  128.  
  129. //------------------------------------------------------------------------------
  130. // ODRefCntCollection::RemoveAndReleaseAll
  131. //------------------------------------------------------------------------------
  132.  
  133. void ODRefCntCollection::RemoveAndReleaseAll()
  134. {
  135.     OrderedCollectionIterator iter(&fCol);
  136.     
  137.     TRY
  138.         for (ODRefCntObject* rco = (ODRefCntObject*) iter.First();
  139.                 iter.IsNotComplete();
  140.                 rco = (ODRefCntObject*) iter.Next() )
  141.         {
  142.             ODRelease(fEv, rco); // function, not macro
  143.         }
  144.     CATCH_ALL
  145.     ENDTRY
  146.  
  147.     // delete iter;
  148.  
  149.     fCol.RemoveAll();
  150. }
  151.  
  152. //------------------------------------------------------------------------------
  153. // ODRefCntCollection::CreateIterator
  154. //------------------------------------------------------------------------------
  155.  
  156. // ODRefCntCollectionIterator* ODRefCntCollection::CreateIterator()
  157. // {
  158. //     return new(fCol.GetHeap()) ODRefCntCollectionIterator(this);
  159. // }
  160.  
  161. //======================================================================================
  162. // ODRefCntCollectionIterator
  163. //======================================================================================
  164.  
  165. //------------------------------------------------------------------------------
  166. // ODRefCntCollectionIterator::ODRefCntCollectionIterator
  167. //------------------------------------------------------------------------------
  168.  
  169. ODRefCntCollectionIterator::ODRefCntCollectionIterator(ODRefCntCollection* collection)    
  170.     : fIter( &collection->fCol )
  171. {
  172. }
  173.  
  174. //------------------------------------------------------------------------------
  175. // ODRefCntCollectionIterator::~ODRefCntCollectionIterator
  176. //------------------------------------------------------------------------------
  177.  
  178. ODRefCntCollectionIterator::~ODRefCntCollectionIterator()                        
  179. {
  180. }
  181.  
  182.  
  183.  
  184.