home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Storage / TypLsItr.cpp < prev   
Encoding:
C/C++ Source or Header  |  1996-08-28  |  4.7 KB  |  188 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TypeLsItr.cpp
  3.  
  4.     Contains:    Implementation of class ODTypeListIterator
  5.  
  6.     Owned by:    Craig Carper
  7.  
  8.     Copyright:    © 1994, 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <2>     5/24/96    jpa        1246074: SOM_CATCH --> SOM_TRY..SOM_ENDTRY
  13.  
  14.     To Do:
  15.     In Progress:
  16.         
  17. */
  18.  
  19. #define VARIABLE_MACROS
  20.  
  21. #define ODTypeListIterator_Class_Source
  22. #include <TypLsItr.xih>
  23.  
  24. #ifndef SOM_ODTypeList_xh
  25. #include <TypeList.xh>
  26. #endif
  27.  
  28. #ifndef SOM_ODObject_xh
  29. #include <ODObject.xh>
  30. #endif
  31.  
  32. #ifndef SOM_Module_OpenDoc_Errors_defined
  33. #include <ErrorDef.xh>
  34. #endif
  35.  
  36. #ifndef _ORDCOLL_
  37. #include <OrdColl.h>
  38. #endif
  39.  
  40. #ifndef _EXCEPT_
  41. #include <Except.h>
  42. #endif
  43.  
  44. #ifndef _ISOSTR_
  45. #include <ISOStr.h>
  46. #endif
  47.  
  48. #ifndef _ODMEMORY_
  49. #include <ODMemory.h>
  50. #endif
  51.  
  52. #ifndef _ODNew_
  53. #include <ODNew.h>
  54. #endif
  55.  
  56. #pragma segment ODTypeListIterator
  57.  
  58. //==============================================================================
  59. // ODTypeListIterator
  60. //==============================================================================
  61.  
  62. //------------------------------------------------------------------------------
  63. // ODTypeListIterator: somUninit
  64. //------------------------------------------------------------------------------
  65.  
  66. SOM_Scope void  SOMLINK ODTypeListIteratorsomUninit(ODTypeListIterator *somSelf)
  67. {
  68.     ODTypeListIteratorData *somThis = ODTypeListIteratorGetData(somSelf);
  69.     ODTypeListIteratorMethodDebug("ODTypeListIterator","ODTypeListIteratorsomUninit");
  70.  
  71.     delete _fIterator;
  72.  
  73.     parent_somUninit(somSelf);
  74. }
  75.  
  76. //------------------------------------------------------------------------------
  77. // ODTypeListIterator: InitODTypeListIterator
  78. //------------------------------------------------------------------------------
  79.  
  80. SOM_Scope void  SOMLINK ODTypeListIteratorInitODTypeListIterator(ODTypeListIterator *somSelf, Environment *ev,
  81.         ODTypeList* typeList)
  82. {
  83.     ODTypeListIteratorData *somThis = ODTypeListIteratorGetData(somSelf);
  84.     ODTypeListIteratorMethodDebug("ODTypeListIterator","InitODTypeListIterator");
  85.  
  86.     SOM_TRY
  87.  
  88.     /* Moved from somInit. SOM itself sets fields to 0
  89.     _fTypeList = kODNULL;
  90.     _fIterator = kODNULL;
  91.     _fFirstCalled = kODFalse;
  92.     */
  93.     
  94.     somSelf->InitObject(ev);
  95.     
  96.     _fTypeList = typeList;
  97.     OrderedCollection* ordColl = _fTypeList->GetImplementation(ev);
  98.     _fIterator = ordColl->CreateIterator();
  99.  
  100.     THROW_IF_NULL(_fIterator);
  101.  
  102.     SOM_CATCH_ALL
  103.     SOM_ENDTRY
  104. }
  105.  
  106. //------------------------------------------------------------------------------
  107. // ODTypeListIterator: IsNotComplete
  108. //------------------------------------------------------------------------------
  109.  
  110. SOM_Scope ODBoolean  SOMLINK ODTypeListIteratorIsNotComplete(ODTypeListIterator *somSelf, Environment *ev)
  111. {
  112.     ODTypeListIteratorData *somThis = ODTypeListIteratorGetData(somSelf);
  113.     ODTypeListIteratorMethodDebug("ODTypeListIterator","IsNotComplete");
  114.  
  115.     if ( !_fFirstCalled )
  116.     {
  117.         ODSetSOMException(ev, kODErrIteratorNotInitialized);
  118.         return kODFalse;
  119.     }
  120.  
  121.     return _fIterator->IsNotComplete();
  122. }
  123.  
  124. //------------------------------------------------------------------------------
  125. // ODTypeListIterator: First
  126. //------------------------------------------------------------------------------
  127.  
  128. SOM_Scope ODType  SOMLINK ODTypeListIteratorFirst(ODTypeListIterator *somSelf, Environment *ev)
  129. {
  130.     ODTypeListIteratorData *somThis = ODTypeListIteratorGetData(somSelf);
  131.     ODTypeListIteratorMethodDebug("ODTypeListIterator","First");
  132.  
  133.     ODType resultType = kODNULL;    ODVolatile(resultType);
  134.  
  135.     SOM_TRY
  136.     
  137.         _fFirstCalled = kODTrue;
  138.     
  139.         ODType firstType = (ODType) _fIterator->First();
  140.     
  141.         if ( firstType )
  142.         {
  143.             ODULong strLength = ODISOStrLength((const ODISOStr) firstType);
  144.             resultType = (ODType) ODNewPtrClear(strLength+1, kDefaultHeapID);
  145.             ODISOStrNCopy((const ODISOStr) resultType, (ODISOStr) firstType, strLength);
  146.         }
  147.     SOM_CATCH_ALL
  148.  
  149.         ODDisposePtr(resultType);
  150.  
  151.     SOM_ENDTRY
  152.     
  153.     return resultType;
  154. }
  155.  
  156. //------------------------------------------------------------------------------
  157. // ODTypeListIterator: Next
  158. //------------------------------------------------------------------------------
  159.  
  160. SOM_Scope ODType  SOMLINK ODTypeListIteratorNext(ODTypeListIterator *somSelf, Environment *ev)
  161. {
  162.     ODTypeListIteratorData *somThis = ODTypeListIteratorGetData(somSelf);
  163.     ODTypeListIteratorMethodDebug("ODTypeListIterator","Next");
  164.  
  165.     ODType resultType = kODNULL;    ODVolatile(resultType);
  166.     
  167.     SOM_TRY
  168.     
  169.         _fFirstCalled = kODTrue;
  170.     
  171.         ODType nextType = (ODType) _fIterator->Next();
  172.     
  173.         if ( nextType )
  174.         {
  175.             ODULong strLength = ODISOStrLength((const ODISOStr) nextType);
  176.             resultType = (ODType) ODNewPtrClear(strLength+1, kDefaultHeapID);
  177.             ODISOStrNCopy((const ODISOStr) resultType, (ODISOStr) nextType, strLength);
  178.         }
  179.         
  180.     SOM_CATCH_ALL
  181.     
  182.         ODDisposePtr(resultType);
  183.         
  184.     SOM_ENDTRY
  185.  
  186.     return resultType;
  187. }
  188.