home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 February: Technology Seed / Mac Tech Seed Feb '97.toast / OpenDoc 1.2b2c1 / Implementation / Utilities / EditrSet.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1997-02-13  |  3.3 KB  |  175 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        EditrSet.cpp
  3.  
  4.     Contains:    C++ Implementation for EditorSet and EditorSetIterator.
  5.  
  6.     Owned by:    Reggie Adkins
  7.  
  8.     Copyright:    © 1993-1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     12/9/96    EL        1602726: Fix RemoveEditor by Adding
  13.                                     FindEditor.
  14.  
  15.     To Do:
  16. */
  17.  
  18.  
  19. #ifndef _EDITRSET_
  20. #include "EditrSet.h"
  21. #endif
  22.  
  23. #ifndef _ORDCOLL_
  24. #include "OrdColl.h"
  25. #endif
  26.  
  27. #ifndef _ODUTILS_
  28. #include <ODUtils.h>
  29. #endif
  30.  
  31. #ifndef _ISOSTR_
  32. #include "ISOStr.h"
  33. #endif
  34.  
  35.  
  36. //==============================================================================
  37. // Class EditorSet
  38. //==============================================================================
  39.  
  40. EditorSet::EditorSet()
  41. {
  42.     fSet = kODNULL;
  43.     fEv = kODNULL;
  44. }
  45.  
  46. void EditorSet::InitEditorSet()
  47. {
  48.     fEv = somGetGlobalEnvironment ();
  49.     fSet = new OrderedCollection();
  50. }
  51.  
  52. EditorSet::~EditorSet()
  53. {
  54.     fSet->DeleteAll();
  55.     delete fSet;
  56. }
  57.     
  58. void EditorSet::AddEditor(ODEditor editor)
  59. {
  60.     if ( !this->ContainsEditor(editor) )
  61.     {
  62.         ODULong strLength = ODISOStrLength((const ODISOStr)editor);
  63.         ElementType newEditor = ODNewPtrClear(strLength+1,0);
  64.         ODISOStrNCopy((const ODISOStr)newEditor, (ODISOStr)editor, strLength );
  65.         fSet->AddLast(newEditor);
  66.     }
  67. }
  68.  
  69. void EditorSet::AddEditorSet( EditorSet* editors )
  70. {
  71.     EditorSetIterator* esi = editors->CreateIterator() ;
  72.     for ( ODEditor editor = esi->First() ; esi->IsNotComplete() ;
  73.             editor = esi->Next() )
  74.     {
  75.         this->AddEditor( editor ) ;
  76.     }
  77.     ODDeleteObject( esi );
  78. }
  79.  
  80. void EditorSet::RemoveEditor(ODEditor editor)
  81. {
  82.     ODEditor rslt = this->FindEditor(editor);
  83.     if (rslt)
  84.         fSet->Remove((ElementType)rslt);
  85. }
  86.     
  87. void EditorSet::RemoveEditor(EditorSet* editors )
  88. {
  89.     EditorSetIterator* esi = editors->CreateIterator() ;
  90.     for ( ODEditor editor = esi->First() ; esi->IsNotComplete() ;
  91.             editor = esi->Next() )
  92.     {
  93.         this->RemoveEditor(editor);
  94.     }
  95.     ODDeleteObject( esi );
  96. }
  97.  
  98. void EditorSet::RemoveAllEditors()
  99. {
  100.     if ( fSet->Count() > 0 )
  101.     {
  102.         fSet->DeleteAll();
  103.     }
  104. }
  105.  
  106. ODEditor EditorSet::FindEditor(ODEditor editor)
  107. {
  108.     ODEditor rslt = kODNULL;
  109.     
  110.     if ( this->GetEditorCount() )
  111.     {
  112.         EditorSetIterator* editorIter = this->CreateIterator();
  113.         
  114.         for (ODEditor anEditor = editorIter->First();
  115.             editorIter->IsNotComplete() && (rslt == kODFalse);
  116.             anEditor = editorIter->Next())
  117.         {
  118.             if ((anEditor == editor) || ODISOStrEqual(anEditor, editor))
  119.             {
  120.                 rslt = anEditor;
  121.                 break;
  122.             }
  123.         }
  124.  
  125.         delete editorIter;
  126.     }
  127.     
  128.     return rslt;
  129. }
  130.  
  131. ODBoolean EditorSet::ContainsEditor(ODEditor editor)
  132. {
  133.     return (this->FindEditor(editor) != kODNULL);
  134. }
  135.  
  136. ODULong EditorSet::GetEditorCount()
  137. {
  138.     return (fSet->Count());
  139. }
  140.  
  141. EditorSetIterator* EditorSet::CreateIterator()
  142. {
  143.     //return new EditorSetIterator(this);
  144.     return new EditorSetIterator(this);
  145. }
  146.  
  147. //==============================================================================
  148. // Class EditorSetIterator
  149. //==============================================================================
  150.  
  151. EditorSetIterator::EditorSetIterator(EditorSet* set)
  152. {
  153.     fIterator = new OrderedCollectionIterator(set->fSet);
  154. }
  155.  
  156. EditorSetIterator::~EditorSetIterator()
  157. {
  158.     delete fIterator;
  159. }
  160.     
  161. ODEditor EditorSetIterator::First()
  162. {
  163.     return (ODEditor)fIterator->First();
  164. }
  165.  
  166. ODEditor EditorSetIterator::Next()
  167. {
  168.     return (ODEditor)fIterator->Next();
  169. }
  170.  
  171. ODBoolean EditorSetIterator::IsNotComplete()
  172. {
  173.     return fIterator->IsNotComplete();
  174. }
  175.