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

  1. /* @(#)Z 1.8 com/src/bento/CMLkSItr.cpp, odstorage, od96os2, odos29712d 97/03/21 17:19:10 (96/10/29 09:11:27) */
  2. //====START_GENERATED_PROLOG======================================
  3. //
  4. //
  5. //   COMPONENT_NAME: odstorage
  6. //
  7. //   CLASSES: none
  8. //
  9. //   ORIGINS: 82,27
  10. //
  11. //
  12. //   (C) COPYRIGHT International Business Machines Corp. 1995,1996
  13. //   All Rights Reserved
  14. //   Licensed Materials - Property of IBM
  15. //   US Government Users Restricted Rights - Use, duplication or
  16. //   disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
  17. //       
  18. //   IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
  19. //   ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  20. //   PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  21. //   CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  22. //   USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  23. //   OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE
  24. //   OR PERFORMANCE OF THIS SOFTWARE.
  25. //
  26. //====END_GENERATED_PROLOG========================================
  27. //
  28.  
  29. /*
  30.         File:           CMLkSItr.cpp
  31.  
  32.         Contains:       Implementation of class CMLinkSourceIterator
  33.  
  34.         Owned by:       Craig Carper
  35.  
  36.         Copyright:      ⌐ 1994, 1995 by Apple Computer, Inc., all rights reserved.
  37.  
  38.         Change History (most recent first):
  39.  
  40.                  <8>    10/24/95        jpa             1293441: DM/VL: Bento memory reserve &
  41.                                                                         fatal container err.
  42.                  <7>      8/3/95        RR              #1257260: Collapse B classes. Remove
  43.                                                                         somInit methods. Don't call IsInitialized
  44.                                                                         or SubclassResponsibility
  45.                  <6>     5/26/95        VL              1251403: Multithreading naming support.
  46.                  <5>     5/18/95        CC              1249197: Renamed InitODLinkSourceIterator
  47.                                                                         to InitLinkSourceIterator.
  48.                  <4>     4/11/95        CC              1236452: InitCMLinkSourceIterator: Added
  49.                                                                         SOM_CATCH and throw if underlying interator
  50.                                                                         can't be created.
  51.                                                                         Changed parent method calls from verbose to
  52.                                                                         simple form (parent_method).
  53.                  <3>     10/4/94        CC              1190857 - Don't call CMReleaseObject() on
  54.                                                                         _fCurrent since its added to the draft's
  55.                                                                         list of objects.
  56.                  <2>     9/23/94        VL              1182227: Includes BentoDef.h for Bento
  57.                                                                         Types.
  58.                  <1>     8/11/94        CC              first checked in
  59.  
  60.         To Do:
  61.         In Progress:
  62.  
  63. */
  64.  
  65. #define VARIABLE_MACROS
  66.  
  67. #define CMLinkSourceIterator_Class_Source
  68.  
  69. #ifdef _PLATFORM_OS2_
  70. #include <ODTypesB.xh>
  71.  
  72. typedef struct CMItrNode
  73. {
  74.     ODStorageUnitID linkSourceSUID;
  75.     CMItrNode*    next;
  76. } CMItrNode;
  77.  
  78. #endif /*_PLATFORM_OS2_*/
  79.  
  80. #include <CMLkSItr.xih>
  81.  
  82. #ifndef __CM_API__
  83. #include <CMAPI.h>
  84. #endif
  85.  
  86. #ifndef SOM_Module_OpenDoc_StdProps_defined
  87. #include <StdProps.xh>
  88. #endif
  89.  
  90. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  91. #include <StdTypes.xh>
  92. #endif
  93.  
  94. #ifndef SOM_ODObject_xh
  95. #include <ODObject.xh>
  96. #endif
  97.  
  98. #ifndef SOM_CMCtr_xh
  99. #include <CMCtr.xh>
  100. #endif
  101.  
  102. #ifndef SOM_CMDraft_xh
  103. #include <CMDraft.xh>
  104. #endif
  105.  
  106. #ifndef _DRAFPRIV_
  107. #include <DrafPriv.h>
  108. #endif
  109.  
  110. #ifndef _ODMEMORY_
  111. #include <ODMemory.h>
  112. #endif
  113.  
  114. #ifndef _ISOSTR_
  115. #include <ISOStr.h>
  116. #endif
  117.  
  118. #ifndef _BENTODEF_
  119. #include <BentoDef.h>
  120. #endif
  121.  
  122. #ifndef _SESSHDR_
  123. #include "SessHdr.h"
  124. #endif
  125.  
  126. #pragma segment CMLinkSourceIterator
  127.  
  128. //==============================================================================
  129. // CMLinkSourceIterator
  130. //==============================================================================
  131.  
  132. //------------------------------------------------------------------------------
  133. // CMLinkSourceIterator: somUninit
  134. //------------------------------------------------------------------------------
  135.  
  136. SOM_Scope void  SOMLINK CMLinkSourceIteratorsomUninit(CMLinkSourceIterator *somSelf)
  137. {
  138.     CMLinkSourceIteratorData *somThis = CMLinkSourceIteratorGetData(somSelf);
  139.     CMLinkSourceIteratorMethodDebug("CMLinkSourceIterator","somUninit");
  140.  
  141. #ifdef _PLATFORM_OS2_
  142.     while(_fCurrentNode = _fCMItrList)
  143.     {
  144.       _fCMItrList = _fCurrentNode->next;
  145.       _fCurrentNode->next = (CMItrNode*)kODNULL;
  146.       delete _fCurrentNode;
  147.     }
  148. #else /* _PLATFORM_OS2_*/
  149.  
  150.         if (_fBuffer != kODNULL)
  151.                 ODDisposePtr(_fBuffer);
  152.  
  153.     parent_somUninit(somSelf);
  154. #endif /* _PLATFORM_OS2_*/
  155. }
  156.  
  157. //------------------------------------------------------------------------------
  158. // CMLinkSourceIterator: InitCMLinkSourceIterator
  159. //------------------------------------------------------------------------------
  160.  
  161. SOM_Scope void  SOMLINK CMLinkSourceIteratorInitCMLinkSourceIterator(CMLinkSourceIterator *somSelf, Environment *ev,
  162.                 CMDraft* draft)
  163. {
  164.     CMLinkSourceIteratorData *somThis = CMLinkSourceIteratorGetData(somSelf);
  165.     CMLinkSourceIteratorMethodDebug("CMLinkSourceIterator","InitCMLinkSourceIterator");
  166.  
  167. #ifdef _NATIVE_EXCEPTIONS_
  168. //      Use C++ native exception
  169.         SOM_TRY
  170. #else
  171.         SOM_CATCH return;
  172. #endif
  173.  
  174.         /* Moved from somInit. SOM itself sets fields to zero
  175.         _fDraft = kODNULL;
  176.         _fCurrent = kODNULL;
  177.         _fContainer = kODNULL;
  178.         _fProperty = kODNULL;
  179.         _fType = kODNULL;
  180.         _fBuffer = kODNULL;
  181.         _fSize = 0;
  182.         */
  183.  
  184.         somSelf->InitLinkSourceIterator(ev);
  185.  
  186.         _fDraft = draft;
  187.         _fContainer = draft->GetCMContainer(ev);
  188.  
  189.         ODSessionMustHaveCMAllocReserve(_fContainer);
  190.  
  191.         _fProperty = CMRegisterProperty(_fContainer, kODPropStorageUnitType);
  192.         _fType = CMRegisterType(_fContainer, kODISOStr);
  193.  
  194.         ODSessionRestoreCMAllocReserve(_fContainer);
  195.  
  196.         _fSize = ODISOStrLength(kODLinkSource) + 1;
  197.         _fBuffer = ODNewPtr(_fSize, kDefaultHeapID);
  198.  
  199.         THROW_IF_NULL(_fBuffer);
  200.  
  201. #ifdef _NATIVE_EXCEPTIONS_
  202. //      Use C++ native exception
  203.         SOM_CATCH_ALL
  204.         SOM_ENDTRY
  205. #endif
  206. }
  207.  
  208. //------------------------------------------------------------------------------
  209. // CMLinkSourceIterator: IsNotComplete
  210. //------------------------------------------------------------------------------
  211.  
  212. SOM_Scope ODBoolean  SOMLINK CMLinkSourceIteratorIsNotComplete(CMLinkSourceIterator *somSelf, Environment *ev)
  213. {
  214.     CMLinkSourceIteratorData *somThis = CMLinkSourceIteratorGetData(somSelf);
  215.     CMLinkSourceIteratorMethodDebug("CMLinkSourceIterator","IsNotComplete");
  216.  
  217. #ifdef _PLATFORM_OS2_
  218.    if (_fCurrentNode != (CMItrNode*)kODNULL)
  219.    {
  220.       return kODTrue;
  221.    }
  222.    else
  223.    {
  224.       return kODFalse;
  225.    }
  226. #else /*_PLATFORM_OS2_*/
  227.         return ( _fLinkSource != kODNULL );
  228. #endif /* _PLATFORM_OS2_ */
  229. }
  230.  
  231. //------------------------------------------------------------------------------
  232. // CMLinkSourceIterator: First
  233. //------------------------------------------------------------------------------
  234.  
  235. SOM_Scope ODLinkSource*  SOMLINK CMLinkSourceIteratorFirst(CMLinkSourceIterator *somSelf, Environment *ev)
  236. {
  237.     /* CMLinkSourceIteratorData *somThis = CMLinkSourceIteratorGetData(somSelf); */
  238.     CMLinkSourceIteratorMethodDebug("CMLinkSourceIterator","First");
  239.  
  240. #ifdef _NATIVE_EXCEPTIONS_
  241. //      Use C++ native exception
  242.         ODLinkSource *retLinkSource = kODNULL;
  243.  
  244.         SOM_TRY
  245. #ifdef _PLATFORM_OS2_
  246.         retLinkSource = somSelf->AcquireFirst(ev);
  247. #else /*_PLATFORM_OS2_*/
  248.         retLinkSource = somSelf->Next(ev);
  249. #endif /* _PLATFORM_OS2_ */
  250.  
  251.         SOM_CATCH_ALL
  252.         SOM_ENDTRY
  253.  
  254.         return retLinkSource;
  255. #else
  256.         SOM_CATCH return kODNULL;
  257.         return somSelf->Next(ev);
  258. #endif
  259.  
  260. }
  261.  
  262. //------------------------------------------------------------------------------
  263. // CMLinkSourceIterator: Next
  264. //------------------------------------------------------------------------------
  265.  
  266. SOM_Scope ODLinkSource*  SOMLINK CMLinkSourceIteratorNext(CMLinkSourceIterator *somSelf, Environment *ev)
  267. {
  268.     CMLinkSourceIteratorData *somThis = CMLinkSourceIteratorGetData(somSelf);
  269.     CMLinkSourceIteratorMethodDebug("CMLinkSourceIterator","Next");
  270.  
  271. #ifdef _PLATFORM_OS2_
  272.         return somSelf->AcquireNext(ev);
  273. #else /*_PLATFORM_OS2_*/
  274.         CMObject        object = _fCurrent;
  275.         CMObject        oldObject = object;
  276.  
  277. #ifdef _NATIVE_EXCEPTIONS_
  278. //      Use C++ native exception
  279.         ODLinkSource    *retLinkSource = kODNULL;
  280.  
  281.         SOM_TRY
  282. #else
  283.         SOM_CATCH return kODNULL;
  284. #endif
  285.  
  286.         _fLinkSource = kODNULL;
  287.         do {
  288.                 ODSessionMustHaveCMAllocReserve(_fContainer); // safest once per loop
  289.  
  290.                 object = CMGetNextObjectWithProperty(_fContainer, object, _fProperty);
  291.                 if (object != kODNULL) {
  292.                         CMValue value = CMUseValue(object, _fProperty, _fType);
  293.                         if (value != kODNULL) {
  294.                                 if ((CMReadValueData(value, _fBuffer, 0, _fSize) == _fSize) &&
  295.                                         (ODISOStrCompare((const ODISOStr) _fBuffer, (const ODISOStr) kODLinkSource) == 0)) {
  296.                                         _fCurrent = object;
  297.                                         ODStorageUnitID id = _fDraft->GetIDList(ev)->Add(_fCurrent);
  298.                                         _fLinkSource = _fDraft->AcquireLinkSource(ev, id);
  299.                                 }
  300.                                 CMReleaseValue(value);
  301.                         }
  302.                         if (object != _fCurrent)
  303.                                 CMReleaseObject(object);        /* we did not use it */
  304.                 }
  305.         } while ((object != kODNULL) && (_fCurrent == oldObject));
  306.  
  307.         ODSessionRestoreCMAllocReserve(_fContainer);
  308.  
  309. #ifdef _NATIVE_EXCEPTIONS_
  310. //      Use C++ native exception
  311.         retLinkSource = _fLinkSource;
  312.  
  313.         SOM_CATCH_ALL
  314.         SOM_ENDTRY
  315.         return retLinkSource;
  316. #else
  317.         return _fLinkSource;
  318. #endif
  319. #endif /* _PLATFORM_OS2_ */
  320. }
  321. #ifdef _PLATFORM_OS2_
  322. /*
  323.  *=============================================================================
  324. // LSVCLinkSourceIterator: AcquireFirst
  325.  *=============================================================================
  326.  */
  327. SOM_Scope ODLinkSource*
  328. SOMLINK CMLinkSourceIteratorAcquireFirst(CMLinkSourceIterator *somSelf,
  329.                                          Environment *ev)
  330. {
  331.     CMLinkSourceIteratorData *somThis = CMLinkSourceIteratorGetData(somSelf);
  332.     CMLinkSourceIteratorMethodDebug("CMLinkSourceIterator","First");
  333.  
  334.     if ((_fCurrentNode = _fCMItrList) != (CMItrNode*)kODNULL)
  335.     {
  336.       ODLinkSource* linkSource =
  337.                   _fDraft->AcquireLinkSource(ev, _fCurrentNode->linkSourceSUID);
  338.       return linkSource;
  339.     }
  340.     else
  341.     {
  342.       return kODNULL;
  343.     }
  344. }
  345.  
  346. /*
  347.  *=============================================================================
  348. // LSVCLinkSourceIterator: AcquireNext
  349.  *=============================================================================
  350.  */
  351.  
  352. SOM_Scope ODLinkSource*
  353. SOMLINK CMLinkSourceIteratorAcquireNext(CMLinkSourceIterator *somSelf,
  354.                                         Environment *ev)
  355. {
  356.     CMLinkSourceIteratorData *somThis = CMLinkSourceIteratorGetData(somSelf);
  357.     CMLinkSourceIteratorMethodDebug("CMLinkSourceIterator","Next");
  358.  
  359.     if (_fCurrentNode != (CMItrNode*)kODNULL)
  360.     {
  361.       _fCurrentNode = _fCurrentNode->next;
  362.       if (_fCurrentNode != (CMItrNode*)kODNULL)
  363.       {
  364.         ODLinkSource* linkSource =
  365.                     _fDraft->AcquireLinkSource(ev, _fCurrentNode->linkSourceSUID);
  366.         return linkSource;
  367.       }
  368.     }
  369.     return kODNULL;
  370. }
  371.  
  372. /*
  373.  *=============================================================================
  374. // LSVCLinkSourceIterator: Add
  375.  *=============================================================================
  376.  */
  377.  
  378. SOM_Scope void
  379. SOMLINK CMLinkSourceIteratorAdd(CMLinkSourceIterator *somSelf,
  380.                                 Environment *ev,
  381.                                 ODStorageUnitID linkSourceSUID)
  382. {
  383.     CMLinkSourceIteratorData *somThis = CMLinkSourceIteratorGetData(somSelf);
  384.     CMLinkSourceIteratorMethodDebug("CMLinkSourceIterator","Add");
  385.  
  386.     CMItrNode* entry = new CMItrNode;
  387.     THROW_IF_NULL(entry);
  388.  
  389.     entry->linkSourceSUID = linkSourceSUID;
  390.     if (_fCMItrList != (CMItrNode*)kODNULL)
  391.     {
  392.       entry->next = _fCMItrList;
  393.     }
  394.     else
  395.     {
  396.       entry->next = (CMItrNode*)kODNULL;
  397.     }
  398.     _fCMItrList = entry;
  399. }
  400.  
  401. #endif /* _PLATFORM_OS2_*/
  402.