home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / PowerPlant / Multi-Panel Dialogs 1.1 / MPD Sources / UResourcePlus.h < prev   
Encoding:
C/C++ Source or Header  |  1996-09-09  |  2.1 KB  |  113 lines  |  [TEXT/R*ch]

  1. // ===========================================================================
  2. //    File:                        UResourcePlus.h
  3. // Version:                    1.0 - Feb 1, 1996
  4. //    Author:                    Mike Shields (mshields@inconnect.com)
  5. //                            
  6. //    Copyright ©1996 Mike Shields. All rights reserved.
  7. // ===========================================================================
  8. //
  9.  
  10. #pragma once
  11.  
  12. #ifndef __RESOURCES__
  13. #include <Resources.h>
  14. #endif
  15.  
  16. template <class T>
  17. class    TResource 
  18. {
  19. public:
  20.     TResource()
  21.         : mResourceH(nil)
  22.     {
  23.     };
  24.     
  25.     TResource(ResType inResType, ResIDT inResID, Boolean inThrowFail = true,
  26.                 Boolean inCurrResOnly = false)
  27.         : mResourceH(nil)
  28.     {
  29.         Load(inResType, inResID, inThrowFail, inCurrResOnly);
  30.     };
  31.     
  32.     TResource(ResType inResType, ConstStr255Param inResName,
  33.                 Boolean inThrowFail = true, Boolean inCurrResOnly = false)
  34.         : mResourceH(nil)
  35.     {
  36.         Load(inResType, inResName, inThrowFail, inCurrResOnly);
  37.     };
  38.     
  39.     ~TResource()
  40.     {
  41.         if ( mResourceH != nil ) 
  42.         {
  43.             ::DisposeHandle((Handle)mResourceH);
  44.         }
  45.     };
  46.     
  47.     void Load(ResType inResType, ConstStr255Param inResName,
  48.             Boolean inThrowFail = true, Boolean inCurrResOnly = false)
  49.     {
  50.         if ( inCurrResOnly )
  51.         {
  52.             mResourceH = (T)::Get1NamedResource(inResType, inResName);
  53.         } 
  54.         else 
  55.         {
  56.             mResourceH = (T)::GetNamedResource(inResType, inResName);
  57.         }
  58.         
  59.         if ( inThrowFail ) 
  60.         {
  61.             ThrowIfResFail_(mResourceH);
  62.         }
  63.         
  64.         ::HNoPurge((Handle)mResourceH);
  65.         if ( inThrowFail ) 
  66.         {
  67.             ThrowIfResError_();
  68.         }
  69.  
  70.         ::DetachResource((Handle)mResourceH);
  71.         if ( inThrowFail ) 
  72.         {
  73.             ThrowIfResError_();
  74.         }
  75.     };
  76.             
  77.     void Load(ResType inResType, ResIDT inResID, Boolean inThrowFail = true, 
  78.             Boolean inCurrResOnly = false)
  79.     {
  80.         if ( inCurrResOnly ) 
  81.         {
  82.             mResourceH = (T)::Get1Resource(inResType, inResID);
  83.         } 
  84.         else 
  85.         {
  86.             mResourceH = (T)::GetResource(inResType, inResID);
  87.         }
  88.         
  89.         if ( inThrowFail ) 
  90.         {
  91.             ThrowIfResFail_(mResourceH);
  92.         }
  93.  
  94.         ::HNoPurge((Handle)mResourceH);
  95.         if ( inThrowFail ) 
  96.         {
  97.             ThrowIfResError_();
  98.         }
  99.  
  100.         ::DetachResource((Handle)mResourceH);
  101.         if ( inThrowFail ) 
  102.         {
  103.             ThrowIfResError_();
  104.         }
  105.     };
  106.             
  107.     operator Handle()    { return (Handle)mResourceH; }
  108.     operator T()    { return mResourceH; }
  109.     
  110. private:
  111.     T    mResourceH;
  112. };
  113.