home *** CD-ROM | disk | FTP | other *** search
- /*
- File: EditrSet.cpp
-
- Contains: C++ Implementation for EditorSet and EditorSetIterator.
-
- Owned by: Eric House
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
-
- */
-
-
- #ifndef _EDITRSET_
- #include "EditrSet.h"
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _ISOSTR_
- #include "ISOStr.h"
- #endif
-
-
- //==============================================================================
- // Class EditorSet
- //==============================================================================
-
- EditorSet::EditorSet()
- {
- fSet = kODNULL;
- fEv = kODNULL;
- }
-
- void EditorSet::InitEditorSet()
- {
- fEv = somGetGlobalEnvironment ();
- fSet = new OrderedCollection();
- }
-
- EditorSet::~EditorSet()
- {
- fSet->DeleteAll();
- delete fSet;
- }
-
- void EditorSet::AddEditor(ODEditor editor)
- {
- if ( !this->ContainsEditor(editor) )
- {
- ODULong strLength = ODISOStrLength((const ODISOStr)editor);
- ElementType newEditor = ODNewPtrClear(strLength+1,0);
- ODISOStrNCopy((const ODISOStr)newEditor, (ODISOStr)editor, strLength );
- fSet->AddLast(newEditor);
- }
- }
-
- void EditorSet::AddEditorSet( EditorSet* editors )
- {
- EditorSetIterator* esi = editors->CreateIterator() ;
- for ( ODEditor editor = esi->First() ; esi->IsNotComplete() ;
- editor = esi->Next() )
- {
- this->AddEditor( editor ) ;
- }
- ODDeleteObject( esi );
- }
-
- void EditorSet::RemoveEditor(ODEditor editor)
- {
- if (fSet->Contains((ElementType)editor) != kODFalse)
- fSet->Remove((ElementType)editor);
- }
-
- void EditorSet::RemoveEditor(EditorSet* editors )
- {
- EditorSetIterator* esi = editors->CreateIterator() ;
- for ( ODEditor editor = esi->First() ; esi->IsNotComplete() ;
- editor = esi->Next() )
- {
- this->RemoveEditor(editor);
- }
- ODDeleteObject( esi );
- }
-
- void EditorSet::RemoveAllEditors()
- {
- if ( fSet->Count() > 0 )
- {
- fSet->DeleteAll();
- }
- }
-
- ODBoolean EditorSet::ContainsEditor(ODEditor editor)
- {
- ODBoolean rslt = kODFalse;
-
- if ( this->GetEditorCount() )
- {
- EditorSetIterator* editorIter = this->CreateIterator();
-
- for (ODEditor anEditor = editorIter->First();
- editorIter->IsNotComplete() && (rslt == kODFalse);
- anEditor = editorIter->Next())
- {
- rslt = (anEditor == editor) || ODISOStrEqual(anEditor, editor);
- }
-
- delete editorIter;
- }
-
- return rslt;
- }
-
- ODULong EditorSet::GetEditorCount()
- {
- return (fSet->Count());
- }
-
- EditorSetIterator* EditorSet::CreateIterator()
- {
- //return new EditorSetIterator(this);
- return new EditorSetIterator(this);
- }
-
- //==============================================================================
- // Class EditorSetIterator
- //==============================================================================
-
- EditorSetIterator::EditorSetIterator(EditorSet* set)
- {
- fIterator = new OrderedCollectionIterator(set->fSet);
- }
-
- EditorSetIterator::~EditorSetIterator()
- {
- delete fIterator;
- }
-
- ODEditor EditorSetIterator::First()
- {
- return (ODEditor)fIterator->First();
- }
-
- ODEditor EditorSetIterator::Next()
- {
- return (ODEditor)fIterator->Next();
- }
-
- ODBoolean EditorSetIterator::IsNotComplete()
- {
- return fIterator->IsNotComplete();
- }
-