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 / FWODMisc / FWSUSink.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.1 KB  |  194 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWSUSink.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWSUSINK_H
  11. #define FWSUSINK_H
  12.  
  13. #ifndef SOM_FW_OStorageUnitSink_xh
  14. #include "SLSUSink.xh"
  15. #endif
  16.  
  17. #ifndef FWRANSIN_H
  18. #include "FWRanSin.h"
  19. #endif
  20.  
  21. #ifndef FWFILESP_H
  22. #include "FWFileSp.h"
  23. #endif
  24.  
  25. #ifndef FWFILESY_H
  26. #include "FWFileSy.h"
  27. #endif
  28.  
  29. #ifndef FWFILREP_H
  30. #include "FWFilRep.h"
  31. #endif
  32.  
  33. #ifndef FWFILEAC_H
  34. #include "FWFileAc.h"
  35. #endif
  36.  
  37. #ifndef SOM_Module_OpenDoc_StdProps_defined
  38. #include <StdProps.xh>
  39. #endif
  40.  
  41. //========================================================================================
  42. //    Forward Class Declarations
  43. //========================================================================================
  44.  
  45. class FW_OFileSink;
  46.  
  47. //========================================================================================
  48. //    CLASS FW_PStorageUnitSink
  49. //========================================================================================
  50. //    Smart pointer for FW_OStorageUnitSink
  51. //
  52. //        Inherited API for operator->()
  53. //            long GetReadableBytes();
  54. //            void Read(in void * destination, in long count);
  55. //            long GetWritableBytes();
  56. //            void Write(in void* source, in long count);
  57. //
  58. //            long GetLength();
  59. //            void SetLength(in long length);
  60. //            long GetPosition();
  61. //            void SetPosition(in long position);
  62. //
  63. //        New API for operator->()
  64. //            ODStorageUnitView GetStorageUnitView();
  65. //
  66.  
  67. class FW_PStorageUnitSink : public FW_PRandomAccessSink
  68. {
  69. public:
  70.     FW_PStorageUnitSink(Environment* ev, FW_OStorageUnitSink* theStorageUnitSink);
  71.         // The sink assumes ownership of theStorageUnitSink
  72.  
  73.     FW_PStorageUnitSink(Environment* ev, ODStorageUnitView* storageUnitView);
  74.         // Create a sink attached to the storage unit view.
  75.         // The sink does not assume ownership of the view.
  76.          
  77.     FW_PStorageUnitSink(Environment* ev, 
  78.                         ODStorageUnit* storageUnit, 
  79.                         ODPropertyName propertyName, 
  80.                         ODValueType valueType);
  81.         // Create a sink attached to the given (storageUnit, propertyName, valueType).
  82.         // The "bufferCapacity" is for buffering reads from the storage unit
  83.  
  84.     virtual ~FW_PStorageUnitSink();
  85.  
  86. public:
  87.     // Covariant overrides
  88.     FW_OStorageUnitSink*     GetRep()                const;
  89.     FW_OStorageUnitSink*     operator->()            const;
  90.     operator                 FW_OStorageUnitSink*()    const;
  91.  
  92.     FW_OStorageUnitSink* GetStorageUnitSink() const;
  93.  
  94. private:
  95.     FW_PStorageUnitSink(const FW_PStorageUnitSink&);
  96.     FW_PStorageUnitSink& operator=(const FW_PStorageUnitSink&);
  97. };
  98.  
  99. //----------------------------------------------------------------------------------------
  100. //    FW_PStorageUnitSink::GetRep
  101. //----------------------------------------------------------------------------------------
  102. inline FW_OStorageUnitSink* FW_PStorageUnitSink::GetRep() const
  103. {
  104.     return (FW_OStorageUnitSink*)FW_PRandomAccessSink::GetRep();
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    FW_PStorageUnitSink::operator->
  109. //----------------------------------------------------------------------------------------
  110. inline FW_OStorageUnitSink* FW_PStorageUnitSink::operator->() const
  111. {
  112.     return GetRep();
  113. }
  114.  
  115. //----------------------------------------------------------------------------------------
  116. //    FW_PStorageUnitSink::operator FW_OStorageUnitSink*
  117. //----------------------------------------------------------------------------------------
  118. inline FW_PStorageUnitSink::operator FW_OStorageUnitSink*() const
  119. {
  120.     return GetRep();
  121. }
  122.  
  123. //----------------------------------------------------------------------------------------
  124. //    FW_PStorageUnitSink::GetStorageUnitSink
  125. //----------------------------------------------------------------------------------------
  126. inline FW_OStorageUnitSink* FW_PStorageUnitSink::GetStorageUnitSink() const
  127. {
  128.     return GetRep();
  129. }
  130.  
  131. //========================================================================================
  132. //    class FW_PFileValueSink
  133. //========================================================================================
  134. //    Use this class to simplify reading data from files dragged into parts.
  135. //    OpenDoc *doesn't* give you the data in a storageunit; it only gives you
  136. //    an FSSpec. This code extracts the FSSpec and creates a sink from it.
  137.  
  138. class FW_PFileValueSink 
  139. {
  140. public:
  141.     FW_DECLARE_AUTO (FW_PFileValueSink)
  142.     
  143. public:
  144.     FW_PFileValueSink (Environment* ev, ODStorageUnit* storageUnit, ODPropertyName propertyName = kODPropContents);
  145.     ~FW_PFileValueSink();
  146.     
  147.     FW_OFileSink* operator->() const;
  148.     operator FW_OFileSink*() const;
  149.  
  150.     FW_OFileSink* GetFileSink() const;
  151.  
  152. protected:
  153.     static HFSFlavor         PrivMacGetHFSFlavor(Environment* ev, ODStorageUnit* storageUnit, ODPropertyName propertyName);
  154.     
  155. private:
  156.     FW_PFileValueSink(const FW_PFileValueSink&);
  157.     FW_PFileValueSink& operator=(const FW_PFileValueSink&);
  158.  
  159. private:
  160.     // The order if very important because the constructor relies on it
  161.     HFSFlavor                 fHfsInfo;
  162.     FW_PFileSpecification     fSpecification;
  163.     FW_CAccessPermission     fPermission;
  164.     FW_PFile                 fFile;
  165.     FW_PFileSink            fSink;
  166. };
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    FW_PFileValueSink::operator FW_OFileSink*
  170. //----------------------------------------------------------------------------------------
  171. inline FW_PFileValueSink::operator FW_OFileSink*() const
  172. {
  173.     return (FW_OFileSink*)fSink.operator->();
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_OFileSink::operator->
  178. //----------------------------------------------------------------------------------------
  179. inline FW_OFileSink* FW_PFileValueSink::operator->() const
  180. {
  181.     return (FW_OFileSink*)fSink.operator->();
  182. }
  183.  
  184. //----------------------------------------------------------------------------------------
  185. //    FW_PFileValueSink::GetFileSink
  186. //----------------------------------------------------------------------------------------
  187. inline FW_OFileSink* FW_PFileValueSink::GetFileSink() const
  188. {
  189.     return (FW_OFileSink*)fSink.operator->();
  190. }
  191.  
  192.  
  193. #endif
  194.