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 / SLResSin.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  6.9 KB  |  248 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                SLResSin.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWRESACC_H
  13. #include "FWResAcc.h"
  14. #endif
  15.  
  16. #ifndef FWEXCEPT_H
  17. #include "FWExcept.h"
  18. #endif
  19.  
  20. #ifdef FW_BUILD_MAC
  21. #pragma segment fwresour
  22. #endif
  23.  
  24. #include "SLMemSin.xh"
  25.  
  26. /*
  27.  *  This file was generated by the SOM Compiler.
  28.  *  Generated using: 
  29.  *      SOM Emitter emitxtm.dll: 2.33
  30.  */
  31.  
  32. #define FW_OResourceSink_Class_Source
  33. #include "SLResSin.xih"
  34.  
  35.  
  36. //========================================================================================
  37. // class FW_CPrivResSinRep
  38. //========================================================================================
  39.  
  40. class FW_CPrivResSinRep
  41. {
  42. public:
  43.     FW_DECLARE_AUTO(FW_CPrivResSinRep)
  44.  
  45.     FW_CAcquireResourceData fResource;
  46.     FW_OMemorySink*            fMemorySink;
  47.  
  48.     FW_CPrivResSinRep(Environment* ev, FW_OResource* theResource);
  49.     ~FW_CPrivResSinRep();
  50. };
  51.  
  52.  
  53. FW_DEFINE_AUTO(FW_CPrivResSinRep)
  54.  
  55. //----------------------------------------------------------------------------------------
  56. // FW_CPrivResSinRep::FW_CPrivResSinRep
  57. //----------------------------------------------------------------------------------------
  58.  
  59. inline FW_CPrivResSinRep::FW_CPrivResSinRep(Environment* ev, FW_OResource* theResource) :
  60.     fResource(ev, theResource)
  61. {
  62.     long resourceSize = fResource.GetSize();
  63.  
  64.     fMemorySink = new FW_OMemorySink;
  65.     fMemorySink->InitFromBuffer(ev, fResource.GetData(), resourceSize, resourceSize);
  66.  
  67.     FW_END_CONSTRUCTOR
  68. }
  69.  
  70.  
  71. //----------------------------------------------------------------------------------------
  72. // FW_CPrivResSinRep::~FW_CPrivResSinRep
  73. //----------------------------------------------------------------------------------------
  74.  
  75. inline FW_CPrivResSinRep::~FW_CPrivResSinRep()
  76. {
  77.     FW_START_DESTRUCTOR
  78.     delete fMemorySink;
  79. }
  80.  
  81.  
  82. //----------------------------------------------------------------------------------------
  83. // FW_OResourceSink__InitFromOResource
  84. //----------------------------------------------------------------------------------------
  85.  
  86. SOM_Scope void  SOMLINK FW_OResourceSink__InitFromOResource(FW_OResourceSink *somSelf, Environment *ev,
  87.         FW_OResource* theResource)
  88. {
  89.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  90.  
  91.     FW_SOM_TRY
  92.     {
  93.         somThis->fRep = FW_NEW(FW_CPrivResSinRep, (ev, theResource));
  94.     }
  95.     FW_SOM_CATCH
  96. }
  97.  
  98.  
  99. //----------------------------------------------------------------------------------------
  100. // FW_OResourceSink__somInit
  101. //----------------------------------------------------------------------------------------
  102.  
  103. SOM_Scope void  SOMLINK FW_OResourceSink__somInit(FW_OResourceSink *somSelf)
  104. {
  105.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  106.  
  107.     FW_OResourceSink_parent_FW_ORandomAccessSink_somInit(somSelf);
  108. }
  109.  
  110.  
  111. //----------------------------------------------------------------------------------------
  112. // FW_OResourceSink__somUninit
  113. //----------------------------------------------------------------------------------------
  114.  
  115. SOM_Scope void  SOMLINK FW_OResourceSink__somUninit(FW_OResourceSink *somSelf)
  116. {
  117.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  118.  
  119.     FW_SOM_UNINIT_TRY
  120.     {
  121.         delete somThis->fRep;
  122.         FW_OResourceSink_parent_FW_ORandomAccessSink_somUninit(somSelf);
  123.     }
  124.     FW_SOM_UNINIT_CATCH
  125. }
  126.  
  127.  
  128. //----------------------------------------------------------------------------------------
  129. // FW_OResourceSink__Read
  130. //----------------------------------------------------------------------------------------
  131.  
  132. SOM_Scope void  SOMLINK FW_OResourceSink__Read(FW_OResourceSink *somSelf, Environment *ev,
  133.         void* destination,
  134.         long count)
  135. {
  136.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  137.     FW_CPrivResSinRep& rep = *somThis->fRep;
  138.  
  139.     FW_SOM_TRY
  140.     {
  141.         rep.fMemorySink->Read(ev, destination, count);
  142.     }
  143.     FW_SOM_CATCH
  144. }
  145.  
  146.  
  147. //----------------------------------------------------------------------------------------
  148. // FW_OResourceSink__GetWritableBytes
  149. //----------------------------------------------------------------------------------------
  150.  
  151. SOM_Scope long  SOMLINK FW_OResourceSink__GetWritableBytes(FW_OResourceSink *somSelf, Environment *ev)
  152. {
  153. FW_UNUSED(ev);
  154.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  155.  
  156.     // Resource sinks are read-only
  157.     return 0;
  158. }
  159.  
  160.  
  161. //----------------------------------------------------------------------------------------
  162. // FW_OResourceSink__Write
  163. //----------------------------------------------------------------------------------------
  164.  
  165. SOM_Scope void  SOMLINK FW_OResourceSink__Write(FW_OResourceSink *somSelf, Environment *ev,
  166.         void* source,
  167.         long count)
  168. {
  169. FW_UNUSED(ev);
  170. FW_UNUSED(source);
  171. FW_UNUSED(count);
  172.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  173.  
  174.     FW_ASSERT(("Resource sinks are read-only", FALSE));
  175. }
  176.  
  177.  
  178. //----------------------------------------------------------------------------------------
  179. // FW_OResourceSink__GetLength
  180. //----------------------------------------------------------------------------------------
  181.  
  182. SOM_Scope long  SOMLINK FW_OResourceSink__GetLength(FW_OResourceSink *somSelf, Environment *ev)
  183. {
  184.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  185.     FW_CPrivResSinRep& rep = *somThis->fRep;
  186.  
  187.     FW_SOM_TRY
  188.     {
  189.         return rep.fMemorySink->GetLength(ev);
  190.     }
  191.     FW_SOM_CATCH
  192.     return 0;
  193. }
  194.  
  195.  
  196. //----------------------------------------------------------------------------------------
  197. // FW_OResourceSink__SetLength
  198. //----------------------------------------------------------------------------------------
  199.  
  200. SOM_Scope void  SOMLINK FW_OResourceSink__SetLength(FW_OResourceSink *somSelf, Environment *ev,
  201.         long length)
  202. {
  203.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  204.     FW_CPrivResSinRep& rep = *somThis->fRep;
  205.  
  206.     FW_SOM_TRY
  207.     {
  208.         rep.fMemorySink->SetLength(ev, length);
  209.     }
  210.     FW_SOM_CATCH
  211. }
  212.  
  213.  
  214. //----------------------------------------------------------------------------------------
  215. // FW_OResourceSink__GetPosition
  216. //----------------------------------------------------------------------------------------
  217.  
  218. SOM_Scope long  SOMLINK FW_OResourceSink__GetPosition(FW_OResourceSink *somSelf, Environment *ev)
  219. {
  220.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  221.     FW_CPrivResSinRep& rep = *somThis->fRep;
  222.  
  223.     FW_SOM_TRY
  224.     {
  225.         return rep.fMemorySink->GetPosition(ev);
  226.     }
  227.     FW_SOM_CATCH
  228.     return 0;
  229. }
  230.  
  231.  
  232. //----------------------------------------------------------------------------------------
  233. // FW_OResourceSink__SetPosition
  234. //----------------------------------------------------------------------------------------
  235.  
  236. SOM_Scope void  SOMLINK FW_OResourceSink__SetPosition(FW_OResourceSink *somSelf, Environment *ev,
  237.         long position)
  238. {
  239.     FW_OResourceSinkData *somThis = FW_OResourceSinkGetData(somSelf);
  240.     FW_CPrivResSinRep& rep = *somThis->fRep;
  241.  
  242.     FW_SOM_TRY
  243.     {
  244.         rep.fMemorySink->SetPosition(ev, position);
  245.     }
  246.     FW_SOM_CATCH
  247. }
  248.