home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osr1.exe / src / EditrSet.cpp < prev    next >
C/C++ Source or Header  |  1997-03-21  |  5KB  |  195 lines

  1. //====START_GENERATED_PROLOG======================================
  2. //
  3. //
  4. //   COMPONENT_NAME: odutils
  5. //
  6. //   CLASSES: none
  7. //
  8. //   ORIGINS: 82,27
  9. //
  10. //
  11. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  12. //   All Rights Reserved
  13. //   Licensed Materials - Property of IBM
  14. //   US Government Users Restricted Rights - Use, duplication or
  15. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  16. //       
  17. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  18. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  19. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  20. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  21. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  22. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  23. //   OR PERFORMANCE OF THIS SOFTWARE.
  24. //
  25. //====END_GENERATED_PROLOG========================================
  26. //
  27. // @(#) 1.5 com/src/utils/EditrSet.cpp, odutils, od96os2, odos29712d 7/15/96 17:57:52 [ 3/21/97 17:20:51 ]
  28. /*
  29.     File:        EditrSet.cpp
  30.  
  31.     Contains:    C++ Implementation for EditorSet and EditorSetIterator.
  32.  
  33.     Owned by:    Eric House
  34.  
  35.     Copyright:    ⌐ 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  36.  
  37.     
  38. */
  39.  
  40.  
  41. #ifndef _EDITRSET_
  42. #include "EditrSet.h"
  43. #endif
  44.  
  45. #ifndef _ORDCOLL_
  46. #include "OrdColl.h"
  47. #endif
  48.  
  49. #ifndef _ODUTILS_
  50. #include <ODUtils.h>
  51. #endif
  52.  
  53. #ifndef _ISOSTR_
  54. #include "ISOStr.h"
  55. #endif
  56.  
  57.  
  58. //==============================================================================
  59. // Class EditorSet
  60. //==============================================================================
  61.  
  62. EditorSet::EditorSet()
  63. {
  64.     fSet = kODNULL;
  65.     fEv = kODNULL;
  66. }
  67.  
  68. void EditorSet::InitEditorSet()
  69. {
  70.     fEv = somGetGlobalEnvironment ();
  71.     fSet = new OrderedCollection();
  72. }
  73.  
  74. EditorSet::~EditorSet()
  75. {
  76. #ifdef OD_BUG
  77.     if (fSet != kODNULL) {
  78. #endif
  79.     fSet->DeleteAll();
  80.     delete fSet;
  81. #ifdef OD_BUG
  82.     }
  83. #endif
  84. }
  85.     
  86. void EditorSet::AddEditor(ODEditor editor)
  87. {
  88.     if ( !this->ContainsEditor(editor) )
  89.     {
  90.         ODULong strLength = ODISOStrLength((const ODISOStr)editor);
  91.         ElementType newEditor = ODNewPtrClear(strLength+1,0);
  92.         ODISOStrNCopy((const ODISOStr)newEditor, (ODISOStr)editor, strLength );
  93.         fSet->AddLast(newEditor);
  94.     }
  95. }
  96.  
  97. void EditorSet::AddEditorSet( EditorSet* editors )
  98. {
  99.     EditorSetIterator* esi = editors->CreateIterator() ;
  100.     for ( ODEditor editor = esi->First() ; esi->IsNotComplete() ;
  101.             editor = esi->Next() )
  102.     {
  103.         this->AddEditor( editor ) ;
  104.     }
  105.     ODDeleteObject( esi );
  106. }
  107.  
  108. #ifndef OD_BUG  // Method doesn't work, and no one in DR4 uses it.
  109. void EditorSet::RemoveEditor(ODEditor editor)
  110. {
  111.     if (fSet->Contains((ElementType)editor) != kODFalse)
  112.         fSet->Remove((ElementType)editor);
  113. }
  114.     
  115. void EditorSet::RemoveEditor(EditorSet* editors )
  116. {
  117.     EditorSetIterator* esi = editors->CreateIterator() ;
  118.     for ( ODEditor editor = esi->First() ; esi->IsNotComplete() ;
  119.             editor = esi->Next() )
  120.     {
  121.         this->RemoveEditor(editor);
  122.     }
  123.     ODDeleteObject( esi );
  124. }
  125. #endif
  126.  
  127. void EditorSet::RemoveAllEditors()
  128. {
  129.     if ( fSet->Count() > 0 )
  130.     {
  131.         fSet->DeleteAll();
  132.     }
  133. }
  134.  
  135. ODBoolean EditorSet::ContainsEditor(ODEditor editor)
  136. {
  137.     ODBoolean rslt = kODFalse;
  138.     
  139.     if ( this->GetEditorCount() )
  140.     {
  141.         EditorSetIterator* editorIter = this->CreateIterator();
  142.         
  143.         for (ODEditor anEditor = editorIter->First();
  144.             editorIter->IsNotComplete() && (rslt == kODFalse);
  145.             anEditor = editorIter->Next())
  146.         {
  147.             rslt = (anEditor == editor) || ODISOStrEqual(anEditor, editor);
  148.         }
  149.  
  150.         delete editorIter;
  151.     }
  152.     
  153.     return rslt;
  154. }
  155.  
  156. ODULong EditorSet::GetEditorCount()
  157. {
  158.     return (fSet->Count());
  159. }
  160.  
  161. EditorSetIterator* EditorSet::CreateIterator()
  162. {
  163.     //return new EditorSetIterator(this);
  164.     return new EditorSetIterator(this);
  165. }
  166.  
  167. //==============================================================================
  168. // Class EditorSetIterator
  169. //==============================================================================
  170.  
  171. EditorSetIterator::EditorSetIterator(EditorSet* set)
  172. {
  173.     fIterator = new OrderedCollectionIterator(set->fSet);
  174. }
  175.  
  176. EditorSetIterator::~EditorSetIterator()
  177. {
  178.     delete fIterator;
  179. }
  180.     
  181. ODEditor EditorSetIterator::First()
  182. {
  183.     return (ODEditor)fIterator->First();
  184. }
  185.  
  186. ODEditor EditorSetIterator::Next()
  187. {
  188.     return (ODEditor)fIterator->Next();
  189. }
  190.  
  191. ODBoolean EditorSetIterator::IsNotComplete()
  192. {
  193.     return fIterator->IsNotComplete();
  194. }
  195.