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 / Utilities / TempObj.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  7.4 KB  |  420 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        TempObj.cpp
  3.  
  4.     Contains:    Template utilities for exception-safe temporary object references
  5.  
  6.     Owned by:    Jens Alfke
  7.  
  8.     Copyright:    © 1995-96 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>     6/19/96    jpa        1359377: Native exception compatibility
  13.                                     [comment out TempAEDescStruct methods]
  14.          <3>     5/31/96    jpa        T10012: Added TempAEDescStruct.
  15.          <2>     5/24/96    jpa        1246074: Native-exception optimizations.
  16.  
  17.     To Do:
  18.     In Progress:
  19.         
  20. */
  21.  
  22.  
  23. #ifndef _TEMPOBJ_
  24. #include "TempObj.h"
  25. #endif
  26.  
  27. #ifndef SOM_ODRefCntObject_xh
  28. #include <RefCtObj.xh>
  29. #endif
  30.  
  31. #ifndef SOM_ODExtension_xh
  32. #include <Extensn.xh>
  33. #endif
  34.  
  35. #ifndef SOM_ODSettingsExtension_xh
  36. #include <Settings.xh>
  37. #endif
  38.  
  39. #ifndef SOM_ODFrame_xh
  40. #include <Frame.xh>
  41. #endif
  42.  
  43. #ifndef SOM_ODShape_xh
  44. #include <Shape.xh>
  45. #endif
  46.  
  47. #ifndef SOM_ODTransform_xh
  48. #include <Trnsform.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODStorageUnit_xh
  52. #include <StorageU.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODPart_xh
  56. #include "Part.xh"
  57. #endif
  58.  
  59. #ifndef SOM_ODDraft_xh
  60. #include <Draft.xh>
  61. #endif
  62.  
  63. #ifndef SOM_ODDocument_xh
  64. #include <Document.xh>
  65. #endif
  66.  
  67.  
  68. #ifndef SOM_ODDocument_xh
  69. #include <Document.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODLink_xh
  73. #include <Link.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODLinkSource_xh
  77. #include <LinkSrc.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODContainer_xh
  81. #include <ODCtr.xh>
  82. #endif
  83.  
  84. #ifndef SOM_ODSession_xh
  85. #include <ODSessn.xh>
  86. #endif
  87.  
  88. #ifndef SOM_ODMenuBar_xh
  89. #include <MenuBar.xh>
  90. #endif
  91.  
  92. #ifndef SOM_ODStorageUnitView_xh
  93. #include <SUView.xh>
  94. #endif
  95.  
  96. #ifndef _ODDEBUG_
  97. #include "ODDebug.h"
  98. #endif
  99.  
  100. #ifndef __APPLEEVENTS__
  101. #include <AppleEvents.h>
  102. #endif
  103.  
  104. #ifndef _BARRAY_
  105. #include <BArray.h>
  106. #endif
  107.  
  108. #ifndef _ITEXT_
  109. #include "IText.h"
  110. #endif
  111.  
  112. #ifndef _ODMEMORY_
  113. #include "ODMemory.h"
  114. #endif
  115.  
  116. #ifndef _PLFMFILE_
  117. #include "PlfmFile.h"
  118. #endif
  119.  
  120.  
  121. #ifndef _USE_TEMPLATES_
  122. #ifndef _NATIVE_EXCEPTIONS_        // c/dtors are inline w/native exceptions
  123.  
  124.     #ifdef __MWERKS__
  125.     #pragma push
  126.     #pragma once off
  127.     #endif
  128.  
  129.     // Define the non-inline methods of the various template classes:
  130.  
  131.     #define _TMPL_IMPL_
  132.     
  133.     #define _T_        ODObject
  134.     #define _C_        TempODObject
  135.     #include "TempObj.th"
  136.     #define _T_        ODSession
  137.     #define _C_        TempODSession
  138.     #include "TempObj.th"
  139.     #define _T_        ODTypeList
  140.     #define _C_        TempODTypeList
  141.     #include "TempObj.th"
  142.     #define _T_        ODStorageUnitView
  143.     #define _C_        TempODStorageUnitView
  144.     #include "TempObj.th"
  145.     
  146.     #define _T_        ODRefCntObject
  147.     #define _C_        TempODRefCntObject
  148.     #include "TempRef.th"
  149.     #define _T_        ODWindow
  150.     #define _C_        TempODWindow
  151.     #include "TempRef.th"
  152.     #define _T_        ODFrame
  153.     #define _C_        TempODFrame
  154.     #include "TempRef.th"
  155.     #define _T_        ODPart
  156.     #define _C_        TempODPart
  157.     #include "TempRef.th"
  158.     #define _T_        ODShape
  159.     #define _C_        TempODShape
  160.     #include "TempRef.th"
  161.     #define _T_        ODTransform
  162.     #define _C_        TempODTransform
  163.     #include "TempRef.th"
  164.     #define _T_        ODStorageUnit
  165.     #define _C_        TempODStorageUnit
  166.     #include "TempRef.th"
  167.  
  168.     #define _T_        ODDraft
  169.     #define _C_        TempODDraft
  170.     #include "TempRef.th"
  171.     #define _T_        ODDocument
  172.     #define _C_        TempODDocument
  173.     #include "TempRef.th"
  174.     #define _T_        ODContainer
  175.     #define _C_        TempODContainer
  176.     #include "TempRef.th"
  177.     #define _T_        ODLink
  178.     #define _C_        TempODLink
  179.     #include "TempRef.th"
  180.     #define _T_        ODLinkSource
  181.     #define _C_        TempODLinkSource
  182.     #include "TempRef.th"
  183.     #define _T_        ODMenuBar
  184.     #define _C_        TempODMenuBar
  185.     #include "TempRef.th"
  186.  
  187. /*    #define _T_        ODExtension
  188.     #define _C_        TempODExtension
  189.     #include "TempRef.th"
  190.     #define _T_        ODSettingsExtension
  191.     #define _C_        TempODSettingsExtension
  192.     #include "TempRef.th"
  193. */
  194.  
  195.     #undef _TMPL_IMPL_
  196.  
  197.     #ifdef __MWERKS__
  198.     #pragma pop
  199.     #endif
  200.  
  201. #endif /*_NATIVE_EXCEPTIONS_*/
  202. #endif /*_USE_TEMPLATES_*/
  203.  
  204. TempODPtr::TempODPtr( ) : fBlock(kODNULL)
  205. {
  206. }
  207.  
  208. TempODPtr::TempODPtr( void *block ) : fBlock(block)
  209. {
  210. }
  211.  
  212. TempODPtr::~TempODPtr( )
  213. {
  214.     delete fBlock;
  215.     fBlock = kODNULL;
  216. }
  217.  
  218. BaseTempObj::~BaseTempObj( )
  219. {
  220.     delete fObj;
  221.     fObj = kODNULL;
  222. }
  223.  
  224. void
  225. BaseTempRef::Release( )
  226. {
  227.     if( fObj ) {
  228.         ASSERT_IS_A(fObj,ODRefCntObject);
  229.         fObj->Release(somGetGlobalEnvironment());
  230.         fObj = kODNULL;
  231.     }
  232. }
  233.  
  234. BaseTempRef::~BaseTempRef( )
  235. {
  236.     if( fObj ) {
  237.         ASSERT_IS_A(fObj,ODRefCntObject);
  238.         fObj->Release(somGetGlobalEnvironment());
  239.         fObj = kODNULL;
  240.     }
  241. }
  242.  
  243. //===========================================================================
  244. //    Temp strings.
  245. //===========================================================================
  246.  
  247. TempODString::TempODString( char* s ) : fStr(s)
  248. {
  249. }
  250.  
  251. TempODString::~TempODString( )
  252. {
  253.     char* s = fStr;
  254.     fStr = kODNULL;
  255.     delete s;
  256. }
  257.  
  258. //===========================================================================
  259. //    Temp handles.
  260. //===========================================================================
  261.  
  262.  
  263. TempODHandle::TempODHandle( ODHandle h ) : fHandle(h)
  264. {
  265. }
  266.  
  267. TempODHandle::~TempODHandle( )
  268. {
  269.     ODHandle h = fHandle;
  270.     fHandle = kODNULL;
  271.     if ( h )
  272.         ODDisposeHandle( h );
  273. }
  274.  
  275. TempODHandleLock::TempODHandleLock( ODHandle h ) : fHandle(h)
  276. {
  277.     if ( h )
  278.         ODLockHandle( h );
  279. }
  280.  
  281. TempODHandleLock::~TempODHandleLock( )
  282. {
  283.     ODHandle h = fHandle;
  284.     fHandle = (ODHandle) kODNULL;
  285.     if ( h )
  286.         ODUnlockHandle( h );
  287. }
  288.  
  289. //===========================================================================
  290. //    Temp platform files.
  291. //===========================================================================
  292.  
  293.  
  294. TempPlatformFile::TempPlatformFile( PlatformFile* f ) : fFile(f)
  295. {
  296. }
  297.  
  298. TempPlatformFile::~TempPlatformFile( )
  299. {
  300.     PlatformFile* f = fFile;
  301.     fFile = kODNULL;
  302.     if ( f )
  303.         delete f;
  304. }
  305.  
  306. //===========================================================================
  307. //    Temp ODPasteAsResult.
  308. //===========================================================================
  309.  
  310.  
  311. TempODPasteAsResult::TempODPasteAsResult( ODPasteAsResult* r ) : fResult(r)
  312. {
  313. }
  314.  
  315. TempODPasteAsResult::~TempODPasteAsResult( )
  316. {
  317.     ODPasteAsResult* r = fResult;
  318.     fResult = kODNULL;
  319.     if ( r )
  320.     {
  321.         if  ( r->selectedKind ) 
  322.         {
  323.             delete r->selectedKind;
  324.             r->selectedKind = kODNULL;
  325.         }
  326.         if  ( r->translateKind ) 
  327.         {
  328.             delete r->translateKind;
  329.             r->translateKind = kODNULL;
  330.         }
  331.         if  ( r->editor ) 
  332.         {
  333.             delete r->editor;
  334.             r->editor = kODNULL;
  335.         }
  336.     }
  337. }
  338.  
  339. //===========================================================================
  340. //    Temp AEDescs.
  341. //===========================================================================
  342.  
  343.  
  344. TempAEDesc::TempAEDesc( AEDesc* d ) : fDesc(d)
  345. {
  346. }
  347.  
  348. TempAEDesc::~TempAEDesc( )
  349. {
  350.     AEDesc* d = fDesc;
  351.     fDesc = kODNULL;
  352.     if ( d )
  353.         AEDisposeDesc(d);
  354. }
  355.  
  356.  
  357. #ifndef _NATIVE_EXCEPTIONS_
  358. TempAEDescStruct::TempAEDescStruct( )
  359. {
  360.     dataHandle = kODNULL;
  361. }
  362.  
  363. TempAEDescStruct::~TempAEDescStruct( )
  364. {
  365.     AEDisposeDesc(this);
  366. }
  367. #endif
  368.  
  369.  
  370. //===========================================================================
  371. //    Temp ODIText.
  372. //===========================================================================
  373.  
  374. TempODIText::TempODIText( ODIText* t ) : fText(t)
  375. {
  376. }
  377.  
  378. TempODIText::~TempODIText( )
  379. {
  380.     ODIText* t = fText;
  381.     fText = kODNULL;
  382.     if ( t )
  383.         DisposeIText(t);
  384. }
  385.  
  386. //===========================================================================
  387. //    Temp byte arrays.
  388. //===========================================================================
  389.  
  390.  
  391. TempODByteArray::TempODByteArray( ODByteArray* ba ) : fBA(ba)
  392. {
  393. }
  394.  
  395. TempODByteArray::~TempODByteArray( )
  396. {
  397.     ODByteArray* ba = fBA;
  398.     fBA = kODNULL;
  399.     if ( ba )
  400.     {
  401.         if ( ba->_buffer )
  402.             ODDisposePtr(ba->_buffer);
  403.         ODDisposePtr(ba);
  404.     }
  405. }
  406.  
  407. TempODByteArrayStruct::TempODByteArrayStruct( )
  408. {
  409.     fBA._buffer = kODNULL;
  410. }
  411.  
  412. TempODByteArrayStruct::TempODByteArrayStruct( ODByteArray ba ) : fBA(ba)
  413. {
  414. }
  415.  
  416. TempODByteArrayStruct::~TempODByteArrayStruct( )
  417. {
  418.     ODDisposePtr(fBA._buffer);
  419. }
  420.