home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / opendc12.zip / od124os2.exe / od12osp1.exe / src / utils / TempObj.cpp < prev    next >
C/C++ Source or Header  |  1997-04-02  |  10KB  |  435 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.7 com/src/utils/TempObj.cpp, odutils, od96os2, odos29712d 10/2/96 12:58:56 [ 3/21/97 17:21:04 ]
  28. /*
  29.     File:        TempObj.cpp
  30.  
  31.     Contains:    Template utilities for exception-safe temporary object references
  32.  
  33.     Owned by:    Jens Alfke
  34.  
  35.     Copyright:    ⌐ 1995 by Apple Computer, Inc., all rights reserved.
  36.  
  37. */
  38.  
  39. #define _OD_DONT_IMPORT_CPP_
  40.  
  41. #ifndef _TEMPOBJ_
  42. #include "TempObj.h"
  43. #endif
  44.  
  45.  
  46. #ifndef SOM_ODRefCntObject_xh
  47. #include <RefCtObj.xh>
  48. #endif
  49.  
  50. #ifndef SOM_ODExtension_xh
  51. #include <Extensn.xh>
  52. #endif
  53.  
  54. #ifndef SOM_ODSettingsExtension_xh
  55. #include <Settings.xh>
  56. #endif
  57.  
  58. #ifndef SOM_ODFrame_xh
  59. #include <Frame.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODShape_xh
  63. #include <Shape.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODTransform_xh
  67. #include <Trnsform.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODStorageUnit_xh
  71. #include <StorageU.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODPart_xh
  75. #include "Part.xh"
  76. #endif
  77.  
  78. #ifndef SOM_ODDraft_xh
  79. #include <Draft.xh>
  80. #endif
  81.  
  82. #ifndef SOM_ODDocument_xh
  83. #include <Document.xh>
  84. #endif
  85.  
  86.  
  87. #ifndef SOM_ODLink_xh
  88. #include <Link.xh>
  89. #endif
  90.  
  91. #ifndef SOM_ODLinkSource_xh
  92. #include <LinkSrc.xh>
  93. #endif
  94.  
  95. #ifndef SOM_ODContainer_xh
  96. #include <ODCtr.xh>
  97. #endif
  98.  
  99. #ifndef SOM_ODSession_xh
  100. #include <ODSessn.xh>
  101. #endif
  102.  
  103. #ifndef SOM_ODMenuBar_xh
  104. #include <MenuBar.xh>
  105. #endif
  106.  
  107. #ifndef SOM_ODStorageUnitView_xh
  108. #include <SUView.xh>
  109. #endif
  110.  
  111. #ifndef _ODDEBUG_
  112. #include "ODDebug.h"
  113. #endif
  114.  
  115. #ifdef _PLATFORM_MACINTOSH_
  116. #ifndef __APPLEEVENTS__
  117. #include <AppleEvents.h>
  118. #endif
  119. #endif
  120.  
  121. #ifndef _BARRAY_
  122. #include <BArray.h>
  123. #endif
  124.  
  125. #ifndef _ITEXT_
  126. #include "IText.h"
  127. #endif
  128.  
  129. #ifndef _ODMEMORY_
  130. #include "ODMemory.h"
  131. #endif
  132.  
  133.  
  134. #ifndef _UTILERRS_
  135. #include <UtilErrs.h>
  136. #endif
  137.  
  138. #ifndef _USE_TEMPLATES_
  139.  
  140.     #ifdef __MWERKS__
  141.     #pragma push
  142.     #pragma once off
  143.     #endif
  144.  
  145.     // Define the non-inline methods of the various template classes:
  146.  
  147.     #define _TMPL_IMPL_
  148.     
  149.     #define _T_        ODObject
  150.     #define _C_        TempODObject
  151.     #include "TempObj.th"
  152.     #define _T_        ODSession
  153.     #define _C_        TempODSession
  154.     #include "TempObj.th"
  155.     #define _T_        ODTypeList
  156.     #define _C_        TempODTypeList
  157.     #include "TempObj.th"
  158.     #define _T_        ODStorageUnitView
  159.     #define _C_        TempODStorageUnitView
  160.     #include "TempObj.th"
  161.     
  162.     #define _T_        ODRefCntObject
  163.     #define _C_        TempODRefCntObject
  164.     #include "TempRef.th"
  165.     #define _T_        ODWindow
  166.     #define _C_        TempODWindow
  167.     #include "TempRef.th"
  168.     #define _T_        ODFrame
  169.     #define _C_        TempODFrame
  170.     #include "TempRef.th"
  171.     #define _T_        ODPart
  172.     #define _C_        TempODPart
  173.     #include "TempRef.th"
  174.     #define _T_        ODShape
  175.     #define _C_        TempODShape
  176.     #include "TempRef.th"
  177.     #define _T_        ODTransform
  178.     #define _C_        TempODTransform
  179.     #include "TempRef.th"
  180.     #define _T_        ODStorageUnit
  181.     #define _C_        TempODStorageUnit
  182.     #include "TempRef.th"
  183.  
  184.     #define _T_        ODDraft
  185.     #define _C_        TempODDraft
  186.     #include "TempRef.th"
  187.     #define _T_        ODDocument
  188.     #define _C_        TempODDocument
  189.     #include "TempRef.th"
  190.     #define _T_        ODContainer
  191.     #define _C_        TempODContainer
  192.     #include "TempRef.th"
  193.     #define _T_        ODLink
  194.     #define _C_        TempODLink
  195.     #include "TempRef.th"
  196.     #define _T_        ODLinkSource
  197.     #define _C_        TempODLinkSource
  198.     #include "TempRef.th"
  199.     #define _T_        ODMenuBar
  200.     #define _C_        TempODMenuBar
  201.     #include "TempRef.th"
  202.  
  203. /*    #define _T_        ODExtension
  204.     #define _C_        TempODExtension
  205.     #include "TempRef.th"
  206.     #define _T_        ODSettingsExtension
  207.     #define _C_        TempODSettingsExtension
  208.     #include "TempRef.th"
  209. */
  210.  
  211.     #undef _TMPL_IMPL_
  212.  
  213.     #ifdef __MWERKS__
  214.     #pragma pop
  215.     #endif
  216.  
  217. #endif /*_USE_TEMPLATES_*/
  218.  
  219. WIN32_DLLEXPORT TempODPtr::TempODPtr( ) : fBlock(kODNULL)
  220. {
  221. }
  222.  
  223. WIN32_DLLEXPORT TempODPtr::TempODPtr( void *block ) : fBlock(block)
  224. {
  225. }
  226.  
  227. WIN32_DLLEXPORT TempODPtr::~TempODPtr( )
  228. {
  229.     delete fBlock;
  230.     fBlock = kODNULL;
  231. }
  232.  
  233. BaseTempObj::BaseTempObj( )
  234. {
  235.     fObj = kODNULL;
  236. }
  237.  
  238. WIN32_DLLEXPORT BaseTempObj::~BaseTempObj( )
  239. {
  240.     delete fObj;
  241.     fObj = kODNULL;
  242. }
  243.  
  244. BaseTempRef::BaseTempRef( )
  245. {
  246.     fObj = kODNULL;
  247. }
  248.  
  249. WIN32_DLLEXPORT void
  250. BaseTempRef::Release( )
  251. {
  252.     if( fObj ) {
  253.         ASSERT_IS_A(fObj,ODRefCntObject);
  254.         fObj->Release(somGetGlobalEnvironment());
  255.         fObj = kODNULL;
  256.     }
  257. }
  258.  
  259. WIN32_DLLEXPORT BaseTempRef::~BaseTempRef( )
  260. {
  261.     if( fObj ) {
  262.  
  263.         // In case the destructor is being called because a C++
  264.         // exception was thrown - clear any SOM exceptions errors
  265.         // that exist in the ev, release the object, then reset
  266.         // the SOM errors.
  267.         Environment *ev = somGetGlobalEnvironment();
  268.         exception_type   nonOpenDocSOMExceptionType;
  269.         string           nonOpenDocSOMExceptionID;
  270.         somToken         nonOpenDocSOMExceptionValue;
  271.         ODError savedExistingError = ODGetSOMException(ev);
  272.  
  273.         // If there is a non-OpenDoc SOM exception, save the data.
  274.         if (savedExistingError == kODErrSOMException) {
  275.             nonOpenDocSOMExceptionType = ev->_major;
  276.             nonOpenDocSOMExceptionID = somExceptionId(ev);
  277.             nonOpenDocSOMExceptionValue = somExceptionValue(ev);
  278.  
  279.             // now clear the non-OpenDoc SOM exception
  280.             ev->_major = NO_EXCEPTION;
  281.         }
  282.         // else, if there is an OpenDoc SOM exception, clear it.
  283.         else if (savedExistingError != kODNoError)
  284.             ODSetSOMException(ev, kODNoError);
  285.  
  286.         //  If a previous error occurred, don't let a new C++
  287.         //  error prevent us from re-setting the SOM exception
  288.         try {
  289.  
  290.             ASSERT_IS_A(fObj,ODRefCntObject);
  291.             fObj->Release(ev);
  292.             fObj = kODNULL;
  293.  
  294.         } catch (...) {
  295.  
  296.             // If there was an original SOM Exception, return
  297.             // that instead of the new C++ exception.
  298.             if (savedExistingError == kODNoError)
  299.                 throw;
  300.         }
  301.  
  302.         // If we originally had a non-OpenDoc SOM exception,
  303.         // restore it.
  304.         if (savedExistingError == kODErrSOMException)
  305.             somSetException(ev,
  306.                     nonOpenDocSOMExceptionType,
  307.                     nonOpenDocSOMExceptionID,
  308.                     nonOpenDocSOMExceptionValue);
  309.  
  310.         // else, if we originally had an OpenDoc SOM exception,
  311.         // restore it. 
  312.         else if (savedExistingError != kODNoError)
  313.             ODSetSOMException(ev, savedExistingError);
  314.         
  315.     }
  316. }
  317.  
  318. //===========================================================================
  319. //    Temp strings.
  320. //===========================================================================
  321.  
  322. WIN32_DLLEXPORT TempODString::TempODString( char* s ) : fStr(s)
  323. {
  324. }
  325.  
  326. WIN32_DLLEXPORT TempODString::~TempODString( )
  327. {
  328.     char* s = fStr;
  329.     fStr = kODNULL;
  330.     delete s;
  331. }
  332.  
  333. //===========================================================================
  334. //    Temp ODPasteAsResult.
  335. //===========================================================================
  336.  
  337.  
  338. WIN32_DLLEXPORT TempODPasteAsResult::TempODPasteAsResult( ODPasteAsResult* r ) : fResult(r)
  339. {
  340. }
  341.  
  342. WIN32_DLLEXPORT TempODPasteAsResult::~TempODPasteAsResult( )
  343. {
  344.     ODPasteAsResult* r = fResult;
  345.     fResult = kODNULL;
  346.     if ( r )
  347.     {
  348.         if  ( r->selectedKind ) 
  349.         {
  350.             delete r->selectedKind;
  351.             r->selectedKind = kODNULL;
  352.         }
  353.         if  ( r->translateKind ) 
  354.         {
  355.             delete r->translateKind;
  356.             r->translateKind = kODNULL;
  357.         }
  358.         if  ( r->editor ) 
  359.         {
  360.             delete r->editor;
  361.             r->editor = kODNULL;
  362.         }
  363.     }
  364. }
  365.  
  366. #ifdef _PLATFORM_MACINTOSH_
  367. //===========================================================================
  368. //    Temp AEDescs.
  369. //===========================================================================
  370.  
  371.  
  372. TempAEDesc::TempAEDesc( AEDesc* d ) : fDesc(d)
  373. {
  374. }
  375.  
  376. TempAEDesc::~TempAEDesc( )
  377. {
  378.     AEDesc* d = fDesc;
  379.     fDesc = kODNULL;
  380.     if ( d )
  381.         AEDisposeDesc(d);
  382. }
  383. #endif
  384.  
  385. //===========================================================================
  386. //    Temp ODIText.
  387. //===========================================================================
  388.  
  389. WIN32_DLLEXPORT TempODIText::TempODIText( ODIText* t ) : fText(t)
  390. {
  391. }
  392.  
  393. WIN32_DLLEXPORT TempODIText::~TempODIText( )
  394. {
  395.     ODIText* t = fText;
  396.     fText = kODNULL;
  397.     if ( t )
  398.         DisposeIText(t);
  399. }
  400.  
  401. //===========================================================================
  402. //    Temp byte arrays.
  403. //===========================================================================
  404.  
  405.  
  406. WIN32_DLLEXPORT TempODByteArray::TempODByteArray( ODByteArray* ba ) : fBA(ba)
  407. {
  408. }
  409.  
  410. WIN32_DLLEXPORT TempODByteArray::~TempODByteArray( )
  411. {
  412.     ODByteArray* ba = fBA;
  413.     fBA = kODNULL;
  414.     if ( ba )
  415.     {
  416.         if ( ba->_buffer )
  417.             ODDisposePtr(ba->_buffer);
  418.         ODDisposePtr(ba);
  419.     }
  420. }
  421.  
  422. WIN32_DLLEXPORT TempODByteArrayStruct::TempODByteArrayStruct( )
  423. {
  424.     fBA._buffer = kODNULL;
  425. }
  426.  
  427. WIN32_DLLEXPORT TempODByteArrayStruct::TempODByteArrayStruct( ODByteArray ba ) : fBA(ba)
  428. {
  429. }
  430.  
  431. WIN32_DLLEXPORT TempODByteArrayStruct::~TempODByteArrayStruct( )
  432. {
  433.     ODDisposePtr(fBA._buffer);
  434. }
  435.