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 Development Framework / ODFDev / ODF / Found / FWMemory / FWMemHlp.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.9 KB  |  185 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWMemHlp.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWMEMHLP_H
  11. #define FWMEMHLP_H
  12.  
  13. #ifndef FWCOMMON_H
  14. #include "FWCommon.h"
  15. #endif
  16.  
  17. #ifndef FWEXCLIB_H
  18. #include "FWExcLib.h"
  19. #endif
  20.  
  21. //========================================================================================
  22. // CLASS FW_CAcquireLockedSystemHandle
  23. //
  24. //    A resource acquisition helper object for locking a system handle within a scope.
  25. //========================================================================================
  26.  
  27. class FW_CAcquireLockedSystemHandle
  28. {
  29. public:
  30.     FW_DECLARE_AUTO(FW_CAcquireLockedSystemHandle)
  31.  
  32.     FW_CAcquireLockedSystemHandle(FW_PlatformHandle aSystemHandle);
  33.     ~FW_CAcquireLockedSystemHandle();
  34.     
  35.     void* GetPointer() const;
  36.  
  37. private:
  38.     FW_PlatformHandle    fLockedSystemHandle;
  39.     void*                 fLockedPointer;
  40.  
  41. #ifdef FW_BUILD_MAC
  42.     SignedByte            fLockState;
  43. #endif
  44.  
  45. private:
  46.     FW_CAcquireLockedSystemHandle(const FW_CAcquireLockedSystemHandle& acquireObject);
  47.     FW_CAcquireLockedSystemHandle& operator=(const FW_CAcquireLockedSystemHandle& acquireObject);
  48.         // Copy constructor and assignment operator not valid for this class.
  49. };
  50.  
  51. //----------------------------------------------------------------------------------------
  52. // FW_CAcquireLockedSystemHandle::GetPointer
  53. //----------------------------------------------------------------------------------------
  54.  
  55. inline void* FW_CAcquireLockedSystemHandle::GetPointer() const
  56. {
  57.     return fLockedPointer;
  58. }
  59.  
  60. //========================================================================================
  61. // CLASS FW_CAcquireTemporarySystemHandle
  62. //
  63. //    A resource acquisition helper object for allocating and locking a system handle
  64. //  within a scope.  You can transfer ownership of the handle by calling OrphanPointer.
  65. //========================================================================================
  66.  
  67. class FW_CAcquireTemporarySystemHandle
  68. {
  69. public:
  70.     FW_DECLARE_AUTO(FW_CAcquireTemporarySystemHandle)
  71.  
  72.     FW_CAcquireTemporarySystemHandle(unsigned long size);
  73.     ~FW_CAcquireTemporarySystemHandle();
  74.     
  75.     void*                 Resize(unsigned long newSize);
  76.     
  77.     FW_PlatformHandle    Orphan();
  78.     FW_Boolean             IsOrphan() const;
  79.     
  80.     FW_PlatformHandle    GetPlatformHandle() const;
  81.     void*                 GetPointer() const;
  82.     
  83. private:    
  84.     FW_PlatformHandle     fTemporarySystemHandle;
  85.     void*                 fMemoryPointer;
  86.     FW_Boolean             fFree;                        // If TRUE, the dtor will free the fMemory
  87.  
  88. private:
  89.     FW_CAcquireTemporarySystemHandle(const FW_CAcquireTemporarySystemHandle& acquireObject);
  90.     FW_CAcquireTemporarySystemHandle& operator=(const FW_CAcquireTemporarySystemHandle& acquireObject);
  91.         // Copy constructor and assignment operator not valid for this class.
  92. };
  93.  
  94. //----------------------------------------------------------------------------------------
  95. // FW_CAcquireTemporarySystemHandle::GetPointer
  96. //----------------------------------------------------------------------------------------
  97.  
  98. inline void* FW_CAcquireTemporarySystemHandle::GetPointer() const
  99. {
  100.     return fMemoryPointer;
  101. }
  102.  
  103. //----------------------------------------------------------------------------------------
  104. // FW_CAcquireTemporarySystemHandle::GetPlatformHandle
  105. //----------------------------------------------------------------------------------------
  106.  
  107. inline FW_PlatformHandle FW_CAcquireTemporarySystemHandle::GetPlatformHandle() const
  108. {
  109.     return fTemporarySystemHandle;
  110. }
  111.  
  112. //----------------------------------------------------------------------------------------
  113. // FW_CAcquireTemporarySystemHandle::IsOrphan
  114. //----------------------------------------------------------------------------------------
  115.  
  116. inline FW_Boolean FW_CAcquireTemporarySystemHandle::IsOrphan() const
  117. {
  118.     return !fFree;
  119. }
  120.  
  121. //========================================================================================
  122. // CLASS FW_CAcquireTemporaryMemory
  123. //
  124. //    A resource acquisition helper object for allocating a temporary memory block.
  125. //    You can transfer ownership of the handle by calling OrphanPointer.
  126. //========================================================================================
  127.  
  128. class FW_CAcquireTemporaryMemory
  129. {
  130. public:
  131.     FW_DECLARE_AUTO(FW_CAcquireTemporaryMemory)
  132.  
  133.     FW_CAcquireTemporaryMemory(unsigned long size);
  134.     ~FW_CAcquireTemporaryMemory();
  135.     
  136.     void*     GetPointer() const;
  137.         
  138.     void*    OrphanPointer();
  139.         
  140. private:
  141.     void*    fPointer;
  142.  
  143. private:
  144.     FW_CAcquireTemporaryMemory(const FW_CAcquireTemporaryMemory& acquireObject);
  145.     FW_CAcquireTemporaryMemory& operator=(const FW_CAcquireTemporaryMemory& acquireObject);
  146.         // Copy constructor and assignment operator not valid for this class.
  147. };
  148.  
  149. //----------------------------------------------------------------------------------------
  150. // FW_CAcquireTemporaryMemory::GetPointer
  151. //----------------------------------------------------------------------------------------
  152.  
  153. inline void* FW_CAcquireTemporaryMemory::GetPointer() const
  154. {
  155.     return fPointer;
  156. }
  157.  
  158. #ifdef FW_BUILD_MAC
  159. //========================================================================================
  160. // CLASS FW_CMacAcquireMultiFinderHeapZone
  161. //
  162. //    A resource acquisition helper object to set the current heap zone to be the multifinder
  163. //    heap zone. This is very useful for example with QuickTime.
  164. //========================================================================================
  165.  
  166. class FW_CMacAcquireMultiFinderHeapZone
  167. {
  168. public:
  169.     FW_DECLARE_AUTO(FW_CMacAcquireMultiFinderHeapZone)
  170.  
  171.     FW_CMacAcquireMultiFinderHeapZone();
  172.     ~FW_CMacAcquireMultiFinderHeapZone();
  173.     
  174. private:    
  175.     THz                 fOldHeap;
  176.  
  177. private:
  178.     FW_CMacAcquireMultiFinderHeapZone(const FW_CMacAcquireMultiFinderHeapZone& acquireObject);
  179.     FW_CMacAcquireMultiFinderHeapZone& operator=(const FW_CMacAcquireMultiFinderHeapZone& acquireObject);
  180.         // Copy constructor and assignment operator not valid for this class.
  181. };
  182. #endif
  183.  
  184. #endif
  185.