home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / utils / ODUtils.cpp < prev    next >
C/C++ Source or Header  |  1997-04-02  |  5KB  |  231 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.6 com/src/utils/ODUtils.cpp, odutils, od96os2, odos29712d 8/19/96 11:49:39 [ 3/21/97 17:20:55 ]
  28. /*
  29.     File:        ODUtils.cpp
  30.  
  31.     Contains:    Utility functions for objects
  32.  
  33.     Owned by:    Jens Alfke
  34.  
  35.     Copyright:    ⌐ 1994 - 1995 by Apple Computer, Inc., all rights reserved.
  36.         
  37. */
  38.  
  39. #define _OD_DONT_IMPORT_CPP_
  40.  
  41. #ifndef _ODUTILS_
  42. #include "ODUtils.h"
  43. #endif
  44.  
  45. #ifndef SOM_ODFrame_xh
  46. #include <Frame.xh>
  47. #endif
  48.  
  49. #ifndef SOM_ODShape_xh
  50. #include <Shape.xh>
  51. #endif
  52.  
  53. #ifndef SOM_ODTransform_xh
  54. #include <Trnsform.xh>
  55. #endif
  56.  
  57. #ifndef SOM_Module_OpenDoc_Errors_defined
  58. #include <ErrorDef.xh>
  59. #endif
  60.  
  61. #ifndef SOM_ODDocument_xh
  62. #include <Document.xh>
  63. #endif
  64.  
  65. #ifndef SOM_ODContainer_xh
  66. #include <ODCtr.xh>
  67. #endif
  68.  
  69. #ifndef SOM_ODStorageSystem_xh
  70. #include <ODStor.xh>
  71. #endif
  72.  
  73. #ifndef _ODEXCEPT_
  74. #include <ODExcept.h>
  75. #endif
  76.  
  77. #ifndef _ODDEBUG_
  78. #include <ODDebug.h>
  79. #endif
  80.  
  81. #ifndef SOM_ODFacet_xh
  82. #include <Facet.xh>
  83. #endif
  84.  
  85. #ifndef SOM_ODWindow_xh
  86. #include <Window.xh>
  87. #endif
  88.  
  89. #ifndef SOM_ODDraft_xh
  90. #include <Draft.xh>
  91. #endif
  92.  
  93. #ifndef SOM_ODStorageUnit_xh
  94. #include "StorageU.xh"
  95. #endif
  96.  
  97. #ifndef _TEMPOBJ_
  98. #include <TempObj.h>
  99. #endif
  100.  
  101.  
  102. WIN32_DLLEXPORT void ODAcquireObject(Environment* ev, ODRefCntObject* object)
  103. {
  104.     if (object != kODNULL) 
  105.     {
  106.         object->Acquire(ev);
  107.     }
  108. }
  109.  
  110.  
  111. WIN32_DLLEXPORT void ODRelease( Environment *ev, ODRefCntObject* obj )
  112. {
  113.     if( obj )
  114.         obj->Release(ev);
  115. }
  116.  
  117.  
  118. WIN32_DLLEXPORT void ODFinalRelease( Environment *ev, ODRefCntObject* obj )
  119. {
  120.     if( obj ) {
  121. #if ODDebug
  122.         ODULong ref = obj->GetRefCount(ev);
  123.         if( ref != 1 ) {
  124.             WARNMSG(WARN_INDEX(0),"%s %p's refcount is %ld, not 1",
  125.                     obj->somGetClassName(),obj,ref);
  126.         }
  127. #endif
  128.         obj->Release(ev);
  129.     }
  130. }
  131.  
  132.  
  133. WIN32_DLLEXPORT void ODSafeReleaseObject( ODRefCntObject *obj )
  134. {
  135.     if( obj ) {
  136.            try {
  137.             obj->Release(somGetGlobalEnvironment());
  138.        } catch (ODException _exception) {
  139.             // do nothing
  140.        }
  141.     }
  142. }
  143.  
  144.  
  145. WIN32_DLLEXPORT void ODTransferReference( Environment *ev, ODRefCntObject *oldObj, ODRefCntObject *newObj )
  146. {
  147.     if( oldObj != newObj ) {
  148.         if( newObj )
  149.             newObj->Acquire(ev);
  150.         if( oldObj ) {
  151.             try {
  152.                 oldObj->Release(ev);
  153.             } catch (ODException _exception) {
  154.                 if( newObj ) newObj->Release(ev);
  155.                 throw;
  156.             }
  157.         }
  158.     }
  159. }
  160.  
  161.  
  162. WIN32_DLLEXPORT ODShape* ODCopyAndRelease( Environment *ev, ODShape *s )
  163. {
  164.     ASSERT(s!=kODNULL, kODErrIllegalNullInput);
  165.     if( s->GetRefCount(ev) == 1 )
  166.         return s;
  167.     TempODShape tempS = s;        // Ensures that s gets released
  168.     ODShape *copy = s->Copy(ev);
  169.     return copy;
  170. }
  171.  
  172. WIN32_DLLEXPORT ODTransform* ODCopyAndRelease( Environment *ev, ODTransform *t )
  173. {
  174.     ASSERT(t!=kODNULL, kODErrIllegalNullInput);
  175.     if( t->GetRefCount(ev) == 1 )
  176.         return t;
  177.     TempODTransform tempT = t;        // Ensures that t gets released
  178.     ODTransform *copy = t->Copy(ev);
  179.     return copy;
  180. }
  181.  
  182. #if ODDebug || !defined(_OD_IMPL_)
  183. ODBoolean ODObjectsAreEqual(Environment* ev, ODObject* a, ODObject* b)
  184. {
  185.     return (a == b) || (a && a->IsEqualTo(ev,b));
  186. }
  187. #endif
  188.  
  189.  
  190. WIN32_DLLEXPORT ODPart* ODAcquirePart( Environment *ev, ODFrame *f )
  191. {
  192.     return f ?f->AcquirePart(ev) :kODNULL;
  193. }
  194.  
  195. WIN32_DLLEXPORT ODPart* ODAcquirePart( Environment *ev, ODFacet *f )
  196. {
  197.     return f ?f->GetFrame(ev)->AcquirePart(ev) :kODNULL;
  198. }
  199.  
  200.  
  201. WIN32_DLLEXPORT ODDraft* ODGetDraft( Environment *ev, ODStorageUnit *su )
  202. {
  203.     return su ?su->GetDraft(ev) :kODNULL;
  204. }
  205.  
  206. WIN32_DLLEXPORT ODDraft* ODGetDraft( Environment *ev, ODPersistentObject *po )
  207. {
  208.     return po ?po->GetStorageUnit(ev)->GetDraft(ev) :kODNULL;
  209. }
  210.  
  211.  
  212. WIN32_DLLEXPORT ODSession* ODGetSession( Environment *ev, ODStorageUnit *su )
  213. {
  214.     return su ?su->GetSession(ev) :kODNULL;
  215. }
  216.  
  217. WIN32_DLLEXPORT ODSession* ODGetSession( Environment *ev, ODPersistentObject *po )
  218. {
  219.     return po ?po->GetStorageUnit(ev)->GetSession(ev) :kODNULL;
  220. }
  221.  
  222. WIN32_DLLEXPORT ODSession* ODGetSession( Environment *ev, ODDocument *d )
  223. {
  224.     return d ?d->GetContainer(ev)->GetStorageSystem(ev)->GetSession(ev) :kODNULL;
  225. }
  226.  
  227. WIN32_DLLEXPORT ODSession* ODGetSession( Environment *ev, ODDraft *d )
  228. {
  229.     return d ?d->GetDocument(ev)->GetContainer(ev)->GetStorageSystem(ev)->GetSession(ev) :kODNULL;
  230. }
  231.