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 / OS / FWResour / FWResAcc.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  5.3 KB  |  192 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWResAcc.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWRESACC_H
  11. #define FWRESACC_H
  12.  
  13. #ifndef FWSTDDEF_H
  14. #include "FWStdDef.h"
  15. #endif
  16.  
  17. #ifndef FWEXCDEF_H
  18. #include "FWExcDef.h"
  19. #endif
  20.  
  21. #ifndef FWFILESP_H
  22. #include "FWFileSp.h"
  23. #endif
  24.  
  25. #ifndef FWRESFI_K
  26. #include "FWResFil.k"
  27. #endif
  28.  
  29. #ifndef FWRESFI_H
  30. #include "FWResFil.h"
  31. #endif
  32.  
  33. #include "SLResour.xh"
  34.  
  35. #if defined(FW_BUILD_WIN) && !defined(__WINDOWS_H)
  36. #include <windows.h>
  37. #endif
  38.  
  39. #if defined(FW_BUILD_MAC) && !defined(__TYPES__)
  40. #include <Types.h>
  41. #endif
  42.  
  43. //========================================================================================
  44. // CLASS FW_OResource
  45. //
  46. // This internal class is the reference counted representation class used by the
  47. // FW_CResource class defined below.
  48. //========================================================================================
  49.  
  50.  
  51. //========================================================================================
  52. // CLASS FW_CResource
  53. //========================================================================================
  54.  
  55. class FW_PResource : public FW_TCountedSOMPtr<FW_OResource>
  56. {
  57. public:
  58.     FW_DECLARE_AUTO(FW_PResource)
  59.  
  60. public:
  61.     ~FW_PResource();
  62.         // Decrements the reference count.
  63.         // Delete the resource access ref if count goes to zero.
  64.  
  65.     FW_PResource(Environment* ev,
  66.                  FW_OResourceFile* file,
  67.                  FW_ResourceID resourceID,
  68.                  FW_ResourceType resourceType);
  69.         // Creates a new FW_CPrivResourceRep attached to the given resource.
  70.  
  71.     FW_PResource(const FW_PResource& other);
  72.     FW_PResource& operator=(const FW_PResource& other);
  73.  
  74.     FW_PResource(Environment* ev, FW_OResource* rep);
  75.     FW_PResource& operator=(FW_OResource* rep);
  76.  
  77. };
  78.  
  79. //----------------------------------------------------------------------------------------
  80. // FW_PResource::operator= 
  81. //----------------------------------------------------------------------------------------
  82.  
  83. inline FW_PResource& FW_PResource::operator=(const FW_PResource& other)
  84. {
  85.     FW_TCountedSOMPtr<FW_OResource>::operator=(other);
  86.     return *this;
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. // FW_PResource::operator= 
  91. //----------------------------------------------------------------------------------------
  92.  
  93. inline FW_PResource& FW_PResource::operator=(FW_OResource* rep)
  94. {
  95.     FW_TCountedSOMPtr<FW_OResource>::operator=(rep);
  96.     return *this;
  97. }
  98.  
  99.  
  100. //========================================================================================
  101. // CLASS FW_CAcquireResourceData
  102. //========================================================================================
  103.  
  104. class FW_CAcquireResourceData
  105. {
  106. public:
  107.     FW_DECLARE_AUTO(FW_CAcquireResourceData)
  108.  
  109.     FW_CAcquireResourceData(Environment *ev, FW_OResource* resource);
  110.         // Acquires the data using resource->AcquireData().
  111.         
  112.     ~FW_CAcquireResourceData();
  113.         // Releases the data using resource->ReleaseData().
  114.         
  115.     void *GetData() const;
  116.         // Returns a void* pointer to the data.
  117.         
  118.     unsigned long GetSize() const;
  119.         // Returns the size of the resource, in bytes.
  120.     
  121. private:
  122.     FW_PResource fResource;
  123.         // The resource.
  124.         
  125.     void* fData;
  126.         // The acquired data.
  127.  
  128.     unsigned long fSize;
  129.         // The size of the acquire data.
  130. };
  131.  
  132. //----------------------------------------------------------------------------------------
  133. // FW_CAcquireResourceData::GetData
  134. //----------------------------------------------------------------------------------------
  135.  
  136. inline void* FW_CAcquireResourceData::GetData() const
  137. {
  138.     return fData;
  139. }
  140.  
  141. //----------------------------------------------------------------------------------------
  142. // FW_CAcquireResourceData::GetSize
  143. //----------------------------------------------------------------------------------------
  144.  
  145. inline unsigned long FW_CAcquireResourceData::GetSize() const
  146. {
  147.     return fSize;
  148. }
  149.  
  150. //========================================================================================
  151. //    Global Utility Functions
  152. //========================================================================================
  153.  
  154. // These functions will probably be moved into the Strings component.
  155. // To do so, we will make Strings be dependent on the Streams component,
  156. // and then provide "load string from sink" functions.
  157.  
  158. FW_Boolean FW_HasStringByPosition(Environment *ev,
  159.                               FW_PResourceFile &file,
  160.                               FW_ResourceID resourceID,
  161.                               FW_ResourceType resourceType,
  162.                               unsigned short position);
  163.  
  164. FW_Boolean FW_HasStringByID(Environment *ev,
  165.                               FW_PResourceFile &file,
  166.                               FW_ResourceID resourceID,
  167.                               FW_ResourceType resourceType,
  168.                               unsigned short id);
  169.  
  170. void FW_LoadStringByPosition(Environment *ev,
  171.                               FW_PResourceFile &file,
  172.                               FW_ResourceID resourceID,
  173.                               FW_ResourceType resourceType,
  174.                               unsigned short position,
  175.                                           FW_CString &string);
  176.                     
  177. void FW_LoadStringByID(Environment *ev,
  178.                         FW_PResourceFile &file,
  179.                         FW_ResourceID resourceID,
  180.                         FW_ResourceType resourceType,
  181.                         unsigned short id,
  182.                         FW_CString &string);
  183.  
  184. FW_Boolean FW_LoadStringByIDNoFail(Environment *ev,
  185.                                 FW_PResourceFile &file,
  186.                                 FW_ResourceID resourceID,
  187.                                 FW_ResourceType resourceType,
  188.                                 unsigned short id,
  189.                                 FW_CString &string);
  190.  
  191. #endif
  192.