home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SUClone.cpp
-
- Contains: Implementation SUCloneHelper class.
-
- Owned by: Vincent Lo
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <3> 5/26/95 VL 1251403: Multithreading naming support.
- <2> 5/25/95 jpa List.h --> LinkList.h [1253324]
- <1> 1/26/95 VL first checked in
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _SUCLONE_
- #include "SUClone.h"
- #endif
-
- #ifndef _LINKLIST_
- #include "LinkList.h"
- #endif
-
- #ifndef _ODNEW_
- #include "ODNew.h"
- #endif
-
- //==============================================================================
- // Local classes
- //==============================================================================
-
- class ScopeIDLink : public Link {
-
- public:
-
- ScopeIDLink(ODID id) {fID = id;}
- ~ScopeIDLink() {};
-
- ODID GetID() {return fID;};
-
- private:
-
- ODID fID;
- };
-
- class ScopeIDList
- {
- public:
-
- ScopeIDList() {fHeap = ODRecoverHeapID(this);}
-
- ~ScopeIDList() {fLinkedList.DeleteAllLinks();}
-
- void Reset() {fLinkedList.DeleteAllLinks();}
-
- void Add(ODID id);
-
- ODBoolean Exists(ODID id);
-
- private:
-
- LinkedList fLinkedList;
- ODMemoryHeapID fHeap;
-
- ODMemoryHeapID GetHeap() {return fHeap;}
- };
-
-
- //==============================================================================
- // SUCloneHelper
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // SUCloneHelper::SUCloneHelper
- //------------------------------------------------------------------------------
-
- SUCloneHelper::SUCloneHelper()
- {
- fHeap = ODRecoverHeapID(this);
- fScopeIDList = new(GetHeap()) ScopeIDList;
- }
-
- //------------------------------------------------------------------------------
- // SUCloneHelper::SUCloneHelper
- //------------------------------------------------------------------------------
-
- SUCloneHelper::~SUCloneHelper()
- {
- delete fScopeIDList;
- }
-
- //------------------------------------------------------------------------------
- // SUCloneHelper::ShouldClone
- //------------------------------------------------------------------------------
-
- ODBoolean SUCloneHelper::ShouldClone(ODDraftKey key, ODID scopeID)
- {
- ODBoolean shouldClone = kODFalse;
-
- if (fKey != key) {
- fScopeIDList->Reset();
- fScopeIDList->Add(scopeID);
- fKey = key;
- shouldClone = kODTrue;
- }
- else if (fScopeIDList->Exists(scopeID) == kODFalse) {
- fScopeIDList->Add(scopeID);
- shouldClone = kODTrue;
- }
- return shouldClone;
- }
-
- //==============================================================================
- // ScopeIDList
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ScopeIDList::Add
- //------------------------------------------------------------------------------
-
- void ScopeIDList::Add(ODID id)
- {
- ScopeIDLink* link = new(GetHeap()) ScopeIDLink(id);
- fLinkedList.AddFirst(link);
- }
-
- //------------------------------------------------------------------------------
- // ScopeIDList::Exists
- //------------------------------------------------------------------------------
-
- ODBoolean ScopeIDList::Exists(ODID id)
- {
- ODBoolean exists = kODFalse;
-
- LinkedListIterator iter(&fLinkedList);
-
- ScopeIDLink* link = (ScopeIDLink*) iter.First();
- while (iter.IsNotComplete() && (exists == kODFalse)) {
- if (link->GetID() == id)
- exists = kODTrue;
- link = (ScopeIDLink*) iter.Next();
- }
-
- return exists;
- }
-