home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / OS / FWResour / Include / FWResFil.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  8.0 KB  |  234 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:        FWResFil.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #if !defined(FWRESFIL_H) && !defined(__ODFRC__)
  11. #define FWRESFIL_H
  12.  
  13. #ifndef FWPRVRFL_H
  14. #include "FWPrvRFl.h"
  15. #endif
  16.  
  17. #ifndef FWEXCDEF_H
  18. #include "FWExcDef.h"
  19. #endif
  20.  
  21. #if FW_LIB_EXPORT_PRAGMAS
  22. #pragma lib_export on
  23. #endif
  24.  
  25. //========================================================================================
  26. // CLASS FW_CResourceFile
  27. //========================================================================================
  28.  
  29. class FW_CLASS_ATTR FW_CResourceFile FW_AUTO_DESTRUCT_OBJECT
  30. {
  31. public:
  32.  
  33.     ~ FW_CResourceFile();
  34.         // Decrements the reference count
  35.         // Delete the resources file rep if count goes to zero.
  36.  
  37.     FW_CResourceFile(const FW_CFileSpecification& newFileSpec);
  38.         //     Open a resources file by name.
  39.         //     This instance assumes responsibility for closing the file.
  40.         
  41.     FW_CResourceFile(FW_ResourceFileID resFileID);
  42.         // Attach to an already opened resource file.
  43.         // This instance does not assume responsibility for closing the file.
  44.  
  45.     FW_CResourceFile(const FW_CResourceFile& other);
  46.         // Copy constructor, attach to same file as other.
  47.     
  48.     FW_CResourceFile& operator=(const FW_CResourceFile& other);
  49.         // Assignment operator.
  50.  
  51.     const FW_CFileSpecification* GetFileSpecification() const;
  52.         // Get the file specificaiton for the resourcesFile.
  53.     
  54.     FW_Boolean HasResource(FW_ResourceId resourceId,
  55.                            FW_ResourceType resourceType) const;
  56.         // Returns TRUE if the resource exists in the file, FALSE if it doesn't.
  57.     
  58.     static FW_ResourceFileID GetSysResourceFileID();
  59.         // Return the FileID for the "system" resources.
  60.         // Can be used to construct a FW_CResourceFile for loading system resources.
  61.  
  62. //    [HLX] Doesn't make much sens in an OpenDoc World        
  63. //    static FW_ResourceFileID GetAppResourceFileID();
  64. //        // Return the FileID for the "application" resources.
  65. //        // Can be used to construct a FW_CResourceFile for loading application resources.
  66.     
  67.     FW_ResourceHandle GetResourceHandle(FW_ResourceId resourceId,
  68.                                         FW_ResourceType resourceType) const;
  69.         // Low level method. Clients should generally use FW_CResource objects.
  70.         // Gets the resource handle.  Resource data may still be purgeable or unloaded.
  71.         // Client assumes responsibility to call ReleaseResourceHandle when done.
  72.  
  73.     void ReleaseResourceHandle(FW_ResourceHandle handle) const;
  74.         // Low level method. Clients should generally use FW_CResource objects.
  75.         // Releases the resource handle.  All memory is released.
  76.  
  77. protected:
  78.     FW_CResourceFile();
  79.         // For sub-class
  80.         // This instance does not assume responsibility for closing the file.
  81.             
  82.     void    SetRep(const FW_PPrivResourceFile& privResourceFile);
  83.         // For sub-class    
  84.     
  85. private:
  86.  
  87. #ifdef FW_BUILD_MAC
  88. //    [HLX] Doesn't make much sens in an OpenDoc World        
  89. //    static const FW_ResourceFileID gMacAppResFileID;
  90. #endif
  91.  
  92.     FW_PPrivResourceFile fRep;
  93.  
  94. public:
  95.  
  96.     // ----- Internal methods
  97.     
  98.     FW_CResourceFile(FW_CPrivResourceFileRep *rep);
  99.         // Attach to the given resources file rep.
  100.  
  101.     FW_Boolean PrivHasSpecialResource(FW_ResourceId resourceId,
  102.                                        FW_ResourceType resourceType) const;
  103.         // Returns TRUE if the resource exists in the file, FALSE if it doesn't.
  104.     
  105.     FW_PlatformHandle PrivGetSpecialResource(FW_ResourceId resourceId,
  106.                                                    FW_ResourceType resourceType) const;
  107.         // Gets the special resource handle.
  108.         // It is the clients reponsibility to release the handle if necessary,
  109.         // using whatever platform specific code is required.
  110.  
  111.     FW_ResourceFileID    PrivGetResourceFileID();
  112.         // Return the platforms's "file ID" for this resources file.
  113. };
  114.  
  115. //----------------------------------------------------------------------------------------
  116. // FW_CResourceFile::SetRep
  117. //----------------------------------------------------------------------------------------
  118.  
  119. inline void FW_CResourceFile::SetRep(const FW_PPrivResourceFile& privResourceFile)
  120. {
  121.     fRep = privResourceFile;
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. // FW_CResourceFile::operator= 
  126. //----------------------------------------------------------------------------------------
  127.  
  128. inline FW_CResourceFile& FW_CResourceFile::operator=(const FW_CResourceFile& other)
  129. {
  130.     fRep = other.fRep;
  131.     return *this;
  132. }
  133.  
  134. //----------------------------------------------------------------------------------------
  135. // FW_CResourceFile::GetFileSpecification
  136. //----------------------------------------------------------------------------------------
  137.  
  138. inline const FW_CFileSpecification* FW_CResourceFile::GetFileSpecification() const
  139. {
  140.     return(fRep->GetFileSpecification());
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. // FW_CResourceFile::HasResource
  145. //----------------------------------------------------------------------------------------
  146.  
  147. inline FW_Boolean FW_CResourceFile::HasResource(FW_ResourceId resourceId,
  148.                                                  FW_ResourceType resourceType) const
  149. {
  150.     return fRep->HasResource(resourceId, resourceType);
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154. // FW_CResourceFile::GetSysResourceFileID
  155. //----------------------------------------------------------------------------------------
  156.  
  157. inline FW_ResourceFileID FW_CResourceFile::GetSysResourceFileID()
  158. {
  159.     return 0; // System res file ID is 0 on both mac and windows
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. // FW_CResourceFile::GetResourceHandle
  164. //----------------------------------------------------------------------------------------
  165.  
  166. inline FW_ResourceHandle FW_CResourceFile::GetResourceHandle(FW_ResourceId resourceId,
  167.                                                               FW_ResourceType resourceType) const
  168. {
  169.     return fRep->GetResourceHandle(resourceId, resourceType);
  170. }
  171.  
  172. //----------------------------------------------------------------------------------------
  173. // FW_CResourceFile::ReleaseResourceHandle
  174. //----------------------------------------------------------------------------------------
  175.  
  176. inline void FW_CResourceFile::ReleaseResourceHandle(FW_ResourceHandle handle) const
  177. {
  178.     fRep->ReleaseResourceHandle(handle);
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. // FW_CResourceFile::PrivHasSpecialResource
  183. //----------------------------------------------------------------------------------------
  184.  
  185. inline FW_Boolean FW_CResourceFile::PrivHasSpecialResource(FW_ResourceId resourceId,
  186.                                                            FW_ResourceType resourceType) const
  187. {
  188.     return fRep->PrivHasSpecialResource(resourceId, resourceType);
  189. }
  190.  
  191. //----------------------------------------------------------------------------------------
  192. // FW_CResourceFile::PrivGetSpecialResource
  193. //----------------------------------------------------------------------------------------
  194.  
  195. inline FW_PlatformHandle FW_CResourceFile::PrivGetSpecialResource(FW_ResourceId resourceId,
  196.                                                                   FW_ResourceType resourceType) const
  197. {
  198.     return fRep->PrivGetSpecialResource(resourceId, resourceType);
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. // FW_CResourceFile::PrivGetResourceFileID
  203. //----------------------------------------------------------------------------------------
  204.  
  205. inline FW_ResourceFileID FW_CResourceFile::PrivGetResourceFileID()
  206. {
  207.     return fRep->PrivGetResourceFileID();
  208. }
  209.  
  210.  
  211. #if defined FW_BUILD_MAC
  212. //========================================================================================
  213. // CLASS FW_CMacResLoadFalse
  214. //========================================================================================
  215. // This utility class provides a mechanism to ::SetResLoad(false) and then be
  216. // assured that ::SetResLoad(true) is executed even in the presend of an FW_THROW
  217.  
  218. class FW_CLASS_ATTR FW_CMacResLoadFalse FW_AUTO_DESTRUCT_OBJECT
  219. {
  220. public:
  221.     FW_CMacResLoadFalse();
  222.         // Sets ResLoad false
  223.  
  224.     virtual ~FW_CMacResLoadFalse();
  225.         // Sets ResLoad true
  226. };
  227. #endif
  228.  
  229. #if FW_LIB_EXPORT_PRAGMAS
  230. #pragma lib_export off
  231. #endif
  232.  
  233. #endif
  234.