home *** CD-ROM | disk | FTP | other *** search
- /*
- File: RefCtCol.cpp
-
- Contains: ODRefCntCollection of ODRefCntObject
-
- Owned by: David McCusker
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
-
-
- */
-
- #ifndef _REFCTCOL_
- #include "RefCtCol.h"
- #endif
-
- #ifndef __EXCEPT__
- #include "Except.h"
- #endif
-
- #ifndef _ODNEW_
- #include "ODNew.h"
- #endif
-
- #pragma segment ODCollections
-
- //------------------------------------------------------------------------------
- // ODObjectOrdColl::^ODObjectOrdColl
- //------------------------------------------------------------------------------
-
- ODObjectOrdColl::~ODObjectOrdColl()
- {
- }
-
- //------------------------------------------------------------------------------
- // ODObjectOrdColl::ElementsMatch (OVERRIDE)
- //------------------------------------------------------------------------------
-
- ODBoolean ODObjectOrdColl::ElementsMatch(ElementType v1,ElementType v2) const
- {
- Environment* ev = somGetGlobalEnvironment();
- return ODObjectsAreEqual(ev, (ODObject*) v1, (ODObject*) v2);
- }
-
- //======================================================================================
- // Class ODRefCntCollection
- //======================================================================================
-
- //------------------------------------------------------------------------------
- // ODRefCntCollection::ODRefCntCollection
- //------------------------------------------------------------------------------
-
- ODRefCntCollection::ODRefCntCollection(Environment* ev)
- : fCol( ), fEv( ev )
- {
- }
-
- //------------------------------------------------------------------------------
- // ODRefCntCollection::ODRefCntCollection
- //------------------------------------------------------------------------------
-
-
- ODRefCntCollection::ODRefCntCollection(Environment* ev, ODMemoryHeapID where)
- : fCol( where ), fEv( ev )
- {
- }
-
- // ODRefCntCollection::~ODRefCntCollection
- //------------------------------------------------------------------------------
-
- ODRefCntCollection::~ODRefCntCollection()
- {
- this->RemoveAndReleaseAll();
- }
-
- //------------------------------------------------------------------------------
- // ODRefCntCollection::AddFirst
- //------------------------------------------------------------------------------
-
- void ODRefCntCollection::AddFirstAndAcquire(ODRefCntObject* element)
- {
- fCol.OrderedCollection::AddLast(element);
- ODAcquireObject(fEv, element); // function, not macro
- }
-
- //------------------------------------------------------------------------------
- // ODRefCntCollection::AddLast
- //------------------------------------------------------------------------------
-
- void ODRefCntCollection::AddLastAndAcquire(ODRefCntObject* element)
- {
- fCol.OrderedCollection::AddLast(element);
- ODAcquireObject(fEv, element); // function, not macro
- }
-
- //------------------------------------------------------------------------------
- // ODRefCntCollection::AddBefore
- //------------------------------------------------------------------------------
-
- void ODRefCntCollection::AddBeforeAndAcquire(ODRefCntObject* existing, ODRefCntObject* tobeadded)
- {
- fCol.OrderedCollection::AddBefore(existing, tobeadded);
- ODAcquireObject(fEv, tobeadded); // function, not macro
- }
-
- //------------------------------------------------------------------------------
- // ODRefCntCollection::AddAfter
- //------------------------------------------------------------------------------
-
- void ODRefCntCollection::AddAfterAndAcquire(ODRefCntObject* existing, ODRefCntObject* tobeadded)
- {
- fCol.OrderedCollection::AddAfter(existing, tobeadded);
- ODAcquireObject(fEv, tobeadded); // function, not macro
- }
-
- //------------------------------------------------------------------------------
- // ODRefCntCollection::RemoveAndRelease
- //------------------------------------------------------------------------------
-
- ODBoolean ODRefCntCollection::RemoveAndRelease(ODRefCntObject* existing)
- {
- ODBoolean removed = fCol.OrderedCollection::Remove(existing);
- if ( removed )
- ODRelease(fEv, existing); // function, not macro
- return removed;
- }
-
- //------------------------------------------------------------------------------
- // ODRefCntCollection::RemoveAndReleaseAll
- //------------------------------------------------------------------------------
-
- void ODRefCntCollection::RemoveAndReleaseAll()
- {
- OrderedCollectionIterator iter(&fCol);
-
- TRY
- for (ODRefCntObject* rco = (ODRefCntObject*) iter.First();
- iter.IsNotComplete();
- rco = (ODRefCntObject*) iter.Next() )
- {
- ODRelease(fEv, rco); // function, not macro
- }
- CATCH_ALL
- ENDTRY
-
- // delete iter;
-
- fCol.RemoveAll();
- }
-
- //------------------------------------------------------------------------------
- // ODRefCntCollection::CreateIterator
- //------------------------------------------------------------------------------
-
- // ODRefCntCollectionIterator* ODRefCntCollection::CreateIterator()
- // {
- // return new(fCol.GetHeap()) ODRefCntCollectionIterator(this);
- // }
-
- //======================================================================================
- // ODRefCntCollectionIterator
- //======================================================================================
-
- //------------------------------------------------------------------------------
- // ODRefCntCollectionIterator::ODRefCntCollectionIterator
- //------------------------------------------------------------------------------
-
- ODRefCntCollectionIterator::ODRefCntCollectionIterator(ODRefCntCollection* collection)
- : fIter( &collection->fCol )
- {
- }
-
- //------------------------------------------------------------------------------
- // ODRefCntCollectionIterator::~ODRefCntCollectionIterator
- //------------------------------------------------------------------------------
-
- ODRefCntCollectionIterator::~ODRefCntCollectionIterator()
- {
- }
-
-
-
-