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 / Found / FWStream / Sources / FWASinks.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  9.4 KB  |  304 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWASinks.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFound.hpp"
  11.  
  12. #ifndef FWASINKS_H
  13. #include "FWASinks.h"
  14. #endif
  15.  
  16. #ifndef FWPRIMEM_H
  17. #include "FWPriMem.h"
  18. #endif
  19.  
  20. #ifndef   FWPRIDEB_H
  21. #include "FWPriDeb.h"
  22. #endif
  23.  
  24. #if FW_LIB_EXPORT_PRAGMAS
  25. #pragma lib_export on
  26. #endif
  27.  
  28. #pragma segment FWStream
  29.  
  30. //========================================================================================
  31. //    CLASS FW_CSink
  32. //========================================================================================
  33.  
  34. //----------------------------------------------------------------------------------------
  35. // FW_CSink::FW_CSink
  36. //----------------------------------------------------------------------------------------
  37.  
  38. FW_CSink::FW_CSink()
  39. {
  40. }
  41.  
  42. //----------------------------------------------------------------------------------------
  43. // FW_CSink::FW_CSink
  44. //----------------------------------------------------------------------------------------
  45.  
  46. FW_CSink::FW_CSink(const FW_CSink& sink)
  47. {
  48. FW_UNUSED(sink);
  49. }
  50.  
  51. //----------------------------------------------------------------------------------------
  52. // FW_CSink::~FW_CSink
  53. //----------------------------------------------------------------------------------------
  54.  
  55. FW_CSink::~FW_CSink()
  56. {
  57. }
  58.  
  59. //----------------------------------------------------------------------------------------
  60. // FW_CSink::operator=
  61. //----------------------------------------------------------------------------------------
  62.  
  63. FW_CSink& FW_CSink::operator=(const FW_CSink& sink)
  64. {
  65. FW_UNUSED(sink);
  66.     return (*this);
  67. }
  68.  
  69. //----------------------------------------------------------------------------------------
  70. // FW_CSink::ReadPeek
  71. //----------------------------------------------------------------------------------------
  72.  
  73. const void* FW_CSink::ReadPeek(long& availableReadBytes)
  74. {
  75.     availableReadBytes = 0;
  76.     return 0;
  77. }
  78.  
  79. //----------------------------------------------------------------------------------------
  80. // FW_CSink::ReadPeekAdvance
  81. //----------------------------------------------------------------------------------------
  82.  
  83. void FW_CSink::ReadPeekAdvance(long bytesRead)
  84. {
  85. FW_UNUSED(bytesRead);
  86.     FW_ASSERT(FALSE);
  87. }
  88.  
  89. //----------------------------------------------------------------------------------------
  90. // FW_CSink::WritePeek
  91. //----------------------------------------------------------------------------------------
  92.  
  93. void* FW_CSink::WritePeek(long& availableWriteBytes)
  94. {
  95.     availableWriteBytes = 0;
  96.     return 0;
  97. }
  98.  
  99. //----------------------------------------------------------------------------------------
  100. // FW_CSink::WritePeekAdvance
  101. //----------------------------------------------------------------------------------------
  102.  
  103. void FW_CSink::WritePeekAdvance(long bytesWritten)
  104. {
  105. FW_UNUSED(bytesWritten);
  106.     FW_ASSERT(FALSE);
  107. }
  108.  
  109. //========================================================================================
  110. // CLASS FW_CRandomAccessSink
  111. //========================================================================================
  112.  
  113. //----------------------------------------------------------------------------------------
  114. //    FW_CRandomAccessSink::FW_CRandomAccessSink
  115. //----------------------------------------------------------------------------------------
  116.  
  117. FW_CRandomAccessSink::FW_CRandomAccessSink() :
  118.     FW_CSink()
  119. {
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    FW_CRandomAccessSink::FW_CRandomAccessSink
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_CRandomAccessSink::FW_CRandomAccessSink(const FW_CRandomAccessSink& sink) :
  127.     FW_CSink(sink)
  128. {
  129. }
  130.  
  131. //----------------------------------------------------------------------------------------
  132. //    FW_CRandomAccessSink::~FW_CRandomAccessSink
  133. //----------------------------------------------------------------------------------------
  134.  
  135. FW_CRandomAccessSink::~FW_CRandomAccessSink()
  136. {
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. // FW_CRandomAccessSink::GetReadableBytes
  141. //----------------------------------------------------------------------------------------
  142.  
  143. long FW_CRandomAccessSink::GetReadableBytes() const
  144. {
  145.     return GetLength() - GetPosition();
  146. }
  147.  
  148. //----------------------------------------------------------------------------------------
  149. // FW_CRandomAccessSink::operator=
  150. //----------------------------------------------------------------------------------------
  151.  
  152. FW_CRandomAccessSink& FW_CRandomAccessSink::operator=(const FW_CRandomAccessSink& sink)
  153. {
  154. FW_UNUSED(sink);
  155.     return (*this);
  156. }
  157.  
  158.  
  159. //========================================================================================
  160. //    CLASS FW_CMemorySink
  161. //========================================================================================
  162.  
  163. //----------------------------------------------------------------------------------------
  164. // FW_CMemorySink::FW_CMemorySink
  165. //----------------------------------------------------------------------------------------
  166.  
  167. FW_CMemorySink::FW_CMemorySink(void* buffer, long capacity, long length) :
  168.     FW_CRandomAccessSink(),
  169.     fBuffer((char*)buffer),
  170.     fCapacity(capacity),
  171.     fLength(length),
  172.     fPosition(0)
  173. {
  174.     FW_ASSERT(fLength <= fCapacity);
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. // FW_CMemorySink::~FW_CMemorySink
  179. //----------------------------------------------------------------------------------------
  180.  
  181. FW_CMemorySink::~FW_CMemorySink()
  182. {
  183. }
  184.  
  185. //----------------------------------------------------------------------------------------
  186. // FW_CMemorySink::Read
  187. //----------------------------------------------------------------------------------------
  188.  
  189. void FW_CMemorySink::Read(void* destination,
  190.                           long count)
  191. {
  192.     FW_ASSERT(count >= 0);
  193.     FW_ASSERT(fPosition + count <= fLength);
  194.     FW_PrimitiveCopyMemory(fBuffer + fPosition, destination, count);
  195.     fPosition += count;
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. // FW_CMemorySink::ReadPeek
  200. //----------------------------------------------------------------------------------------
  201.  
  202. const void * FW_CMemorySink::ReadPeek(long & availableReadBytes)
  203. {
  204.     availableReadBytes = fLength - fPosition;
  205.     return fBuffer + fPosition;
  206. }
  207.  
  208. //----------------------------------------------------------------------------------------
  209. // FW_CMemorySink::ReadPeekAdvance
  210. //----------------------------------------------------------------------------------------
  211.  
  212. void FW_CMemorySink::ReadPeekAdvance(long bytesRead)
  213. {
  214.     FW_ASSERT(bytesRead >= 0);
  215.     FW_ASSERT(fPosition + bytesRead <= fLength);
  216.     fPosition += bytesRead;
  217. }
  218.  
  219. //----------------------------------------------------------------------------------------
  220. // FW_CMemorySink::GetWritableBytes
  221. //----------------------------------------------------------------------------------------
  222.  
  223. long FW_CMemorySink::GetWritableBytes() const
  224. {
  225.     return fCapacity-GetPosition();
  226. }
  227.  
  228. //----------------------------------------------------------------------------------------
  229. // FW_CMemorySink::Write
  230. //----------------------------------------------------------------------------------------
  231.  
  232. void FW_CMemorySink::Write(const void* source,
  233.                            long count)
  234. {
  235.     FW_ASSERT(count >= 0);
  236.     FW_ASSERT(fPosition + count <= fCapacity);
  237.     FW_PrimitiveCopyMemory(source, fBuffer + fPosition, count);
  238.     fPosition += count;
  239.     if (fLength < fPosition)
  240.         fLength = fPosition;
  241. }
  242.  
  243. //----------------------------------------------------------------------------------------
  244. // FW_CMemorySink::WritePeek
  245. //----------------------------------------------------------------------------------------
  246.  
  247. void * FW_CMemorySink::WritePeek(long& availableWriteBytes)
  248. {
  249.     availableWriteBytes = fCapacity - fPosition;
  250.     return fBuffer + fPosition;
  251. }
  252.  
  253. //----------------------------------------------------------------------------------------
  254. // FW_CMemorySink::WritePeekAdvance
  255. //----------------------------------------------------------------------------------------
  256.  
  257. void FW_CMemorySink::WritePeekAdvance(long bytesWritten)
  258. {
  259.     FW_ASSERT(bytesWritten >= 0);
  260.     FW_ASSERT(fPosition + bytesWritten <= fCapacity);
  261.     fPosition += bytesWritten;
  262.     if (fLength < fPosition)
  263.         fLength = fPosition;
  264. }
  265.  
  266. //----------------------------------------------------------------------------------------
  267. // FW_CMemorySink::GetLength
  268. //----------------------------------------------------------------------------------------
  269.  
  270. long FW_CMemorySink::GetLength() const
  271. {
  272.     return fLength;
  273. }
  274.  
  275. //----------------------------------------------------------------------------------------
  276. // FW_CMemorySink::SetLength
  277. //----------------------------------------------------------------------------------------
  278.  
  279. void FW_CMemorySink::SetLength(long length)
  280. {
  281.     FW_ASSERT(length <= fCapacity);
  282.     fLength = length;
  283. }
  284.  
  285. //----------------------------------------------------------------------------------------
  286. // FW_CMemorySink::GetPosition
  287. //----------------------------------------------------------------------------------------
  288.  
  289. long FW_CMemorySink::GetPosition() const
  290. {
  291.     return fPosition;
  292. }
  293.  
  294. //----------------------------------------------------------------------------------------
  295. // FW_CMemorySink::SetPosition
  296. //----------------------------------------------------------------------------------------
  297.  
  298. void FW_CMemorySink::SetPosition(long position)
  299. {
  300.     FW_ASSERT(position >= 0);
  301.     FW_ASSERT(position <= fLength);
  302.     fPosition = position;
  303. }
  304.