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 / Bento / CMLkItr.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  5.8 KB  |  225 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        CMLkItr.cpp
  3.  
  4.     Contains:    Implementation of class CMLinkIterator
  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.          <8>    10/24/95    jpa        1293441: DM/VL: Bento memory reserve &
  14.                                     fatal container err.
  15.          <7>      8/3/95    RR        #1257260: Collapse B classes. Remove
  16.                                     somInit methods. Don't call IsInitialized
  17.                                     or SubclassResponsibility
  18.          <6>     5/26/95    VL        1251403: Multithreading naming support.
  19.          <5>     5/18/95    CC        1249197: Renamed InitODLinkIterator to
  20.                                     InitLinkIterator.
  21.          <4>     4/11/95    CC        1236452: InitCMLinkIterator: Added
  22.                                     SOM_CATCH and throw if underlying interator
  23.                                     can't be created.
  24.                                     Changed parent method calls from verbose to
  25.                                     simple form (parent_method).
  26.          <3>     10/4/94    CC        1190857 - Don't call CMReleaseObject() on
  27.                                     _fCurrent since its added to the draft's
  28.                                     list of objects.
  29.          <2>     9/23/94    VL        1182227: Includes BentoDef.h for Bento
  30.                                     Types.
  31.          <1>     8/11/94    CC        first checked in
  32.  
  33.     To Do:
  34.     In Progress:
  35.         
  36. */
  37.  
  38. #define VARIABLE_MACROS
  39.  
  40. #define CMLinkIterator_Class_Source
  41. #include <CMLkItr.xih>
  42.  
  43. #ifndef __CM_API__
  44. #include <CMAPI.h>
  45. #endif
  46.  
  47. #ifndef SOM_Module_OpenDoc_StdProps_defined
  48. #include <StdProps.xh>
  49. #endif
  50.  
  51. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  52. #include <StdTypes.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODObject_xh
  56. #include <ODObject.xh>
  57. #endif
  58.  
  59. #ifndef SOM_CMCtr_xh
  60. #include <CMCtr.xh>
  61. #endif
  62.  
  63. #ifndef SOM_CMDraft_xh
  64. #include <CMDraft.xh>
  65. #endif
  66.  
  67. #ifndef _DRAFPRIV_
  68. #include <DrafPriv.h>
  69. #endif
  70.  
  71. #ifndef _ODMEMORY_
  72. #include <ODMemory.h>
  73. #endif
  74.  
  75. #ifndef _ISOSTR_
  76. #include <ISOStr.h>
  77. #endif
  78.  
  79. #ifndef _BENTODEF_
  80. #include <BentoDef.h>
  81. #endif
  82.  
  83. #ifndef _SESSHDR_
  84. #include "SessHdr.h"
  85. #endif
  86.  
  87. #pragma segment CMLinkIterator
  88.  
  89. //==============================================================================
  90. // CMLinkIterator
  91. //==============================================================================
  92.  
  93. //------------------------------------------------------------------------------
  94. // CMLinkIterator: somUninit
  95. //------------------------------------------------------------------------------
  96.  
  97. SOM_Scope void  SOMLINK CMLinkIteratorsomUninit(CMLinkIterator *somSelf)
  98. {
  99.     CMLinkIteratorData *somThis = CMLinkIteratorGetData(somSelf);
  100.     CMLinkIteratorMethodDebug("CMLinkIterator","somUninit");
  101.  
  102.     if (_fBuffer != kODNULL)
  103.         ODDisposePtr(_fBuffer);
  104.  
  105.     parent_somUninit(somSelf);
  106. }
  107.  
  108. //------------------------------------------------------------------------------
  109. // CMLinkIterator: InitCMLinkIterator
  110. //------------------------------------------------------------------------------
  111.  
  112. SOM_Scope void  SOMLINK CMLinkIteratorInitCMLinkIterator(CMLinkIterator *somSelf, Environment *ev,
  113.         CMDraft* draft)
  114. {
  115.     CMLinkIteratorData *somThis = CMLinkIteratorGetData(somSelf);
  116.     CMLinkIteratorMethodDebug("CMLinkIterator","InitCMLinkIterator");
  117.  
  118.     SOM_TRY
  119.     
  120.     /* Moved from somInit. SOM itself sets fields to zero
  121.     _fDraft = kODNULL;
  122.     _fCurrent = kODNULL;
  123.     _fContainer = kODNULL;
  124.     _fProperty = kODNULL;
  125.     _fType = kODNULL;
  126.     _fBuffer = kODNULL;
  127.     _fSize = 0;
  128.     */
  129.     
  130.     somSelf->InitLinkIterator(ev);
  131.  
  132.     _fDraft = draft;
  133.     _fContainer = draft->GetCMContainer(ev);
  134.  
  135.     ODSessionMustHaveCMAllocReserve(_fContainer);
  136.     
  137.     _fProperty = CMRegisterProperty(_fContainer, kODPropStorageUnitType);
  138.     _fType = CMRegisterType(_fContainer, kODISOStr);
  139.  
  140.     ODSessionRestoreCMAllocReserve(_fContainer);
  141.  
  142.     _fSize = ODISOStrLength(kODLink) + 1;
  143.     _fBuffer = ODNewPtr(_fSize, kDefaultHeapID);
  144.  
  145.     THROW_IF_NULL(_fBuffer);
  146.  
  147.     SOM_CATCH_ALL
  148.     SOM_ENDTRY
  149. }
  150.  
  151. //------------------------------------------------------------------------------
  152. // CMLinkIterator: IsNotComplete
  153. //------------------------------------------------------------------------------
  154.  
  155. SOM_Scope ODBoolean  SOMLINK CMLinkIteratorIsNotComplete(CMLinkIterator *somSelf, Environment *ev)
  156. {
  157.     CMLinkIteratorData *somThis = CMLinkIteratorGetData(somSelf);
  158.     CMLinkIteratorMethodDebug("CMLinkIterator","IsNotComplete");
  159.  
  160.     return ( _fLink != kODNULL );
  161. }
  162.  
  163. //------------------------------------------------------------------------------
  164. // CMLinkIterator: First
  165. //------------------------------------------------------------------------------
  166.  
  167. SOM_Scope ODLink*  SOMLINK CMLinkIteratorFirst(CMLinkIterator *somSelf, Environment *ev)
  168. {
  169.     /* CMLinkIteratorData *somThis = CMLinkIteratorGetData(somSelf); */
  170.     CMLinkIteratorMethodDebug("CMLinkIterator","First");
  171.  
  172.     SOM_TRY
  173.  
  174.     return somSelf->Next(ev);
  175.  
  176.     SOM_CATCH_ALL
  177.     SOM_ENDTRY
  178.     return kODNULL;
  179. }
  180.  
  181. //------------------------------------------------------------------------------
  182. // CMLinkIterator: Next
  183. //------------------------------------------------------------------------------
  184.  
  185. SOM_Scope ODLink*  SOMLINK CMLinkIteratorNext(CMLinkIterator *somSelf, Environment *ev)
  186. {
  187.     CMLinkIteratorData *somThis = CMLinkIteratorGetData(somSelf);
  188.     CMLinkIteratorMethodDebug("CMLinkIterator","Next");
  189.  
  190.     CMObject    object = _fCurrent;
  191.     CMObject    oldObject = object;
  192.  
  193.     SOM_TRY
  194.  
  195.     _fLink = kODNULL;
  196.     do {    
  197.      
  198.         ODSessionMustHaveCMAllocReserve(_fContainer); // safest once per loop
  199.         
  200.         object = CMGetNextObjectWithProperty(_fContainer, object, _fProperty);
  201.         if (object != kODNULL) {
  202.             CMValue value = CMUseValue(object, _fProperty, _fType);            
  203.             if (value != kODNULL) {
  204.                 if ((CMReadValueData(value, _fBuffer, 0, _fSize) == _fSize) &&
  205.                     (ODISOStrCompare((const ODISOStr) _fBuffer, (const ODISOStr) kODLink) == 0)) {
  206.                     _fCurrent = object;
  207.                     ODStorageUnitID id = _fDraft->GetIDList(ev)->Add(_fCurrent);
  208.                     _fLink = _fDraft->AcquireLink(ev, id, kODNULL);
  209.                 }
  210.                 CMReleaseValue(value);
  211.             }
  212.             if (object != _fCurrent)
  213.                 CMReleaseObject(object);    /* we did not use it */
  214.         }
  215.     } while ((object != kODNULL) && (_fCurrent == oldObject));
  216.  
  217.     ODSessionRestoreCMAllocReserve(_fContainer);
  218.     
  219.     return _fLink;
  220.  
  221.     SOM_CATCH_ALL
  222.     SOM_ENDTRY
  223.     return kODNULL;
  224. }
  225.