home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 9.4 KB | 304 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWASinks.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: (c) 1993, 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFound.hpp"
-
- #ifndef FWASINKS_H
- #include "FWASinks.h"
- #endif
-
- #ifndef FWPRIMEM_H
- #include "FWPriMem.h"
- #endif
-
- #ifndef FWPRIDEB_H
- #include "FWPriDeb.h"
- #endif
-
- #if FW_LIB_EXPORT_PRAGMAS
- #pragma lib_export on
- #endif
-
- #pragma segment FWStream
-
- //========================================================================================
- // CLASS FW_CSink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::FW_CSink
- //----------------------------------------------------------------------------------------
-
- FW_CSink::FW_CSink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::FW_CSink
- //----------------------------------------------------------------------------------------
-
- FW_CSink::FW_CSink(const FW_CSink& sink)
- {
- FW_UNUSED(sink);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::~FW_CSink
- //----------------------------------------------------------------------------------------
-
- FW_CSink::~FW_CSink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CSink& FW_CSink::operator=(const FW_CSink& sink)
- {
- FW_UNUSED(sink);
- return (*this);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::ReadPeek
- //----------------------------------------------------------------------------------------
-
- const void* FW_CSink::ReadPeek(long& availableReadBytes)
- {
- availableReadBytes = 0;
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::ReadPeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CSink::ReadPeekAdvance(long bytesRead)
- {
- FW_UNUSED(bytesRead);
- FW_ASSERT(FALSE);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::WritePeek
- //----------------------------------------------------------------------------------------
-
- void* FW_CSink::WritePeek(long& availableWriteBytes)
- {
- availableWriteBytes = 0;
- return 0;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CSink::WritePeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CSink::WritePeekAdvance(long bytesWritten)
- {
- FW_UNUSED(bytesWritten);
- FW_ASSERT(FALSE);
- }
-
- //========================================================================================
- // CLASS FW_CRandomAccessSink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::FW_CRandomAccessSink
- //----------------------------------------------------------------------------------------
-
- FW_CRandomAccessSink::FW_CRandomAccessSink() :
- FW_CSink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::FW_CRandomAccessSink
- //----------------------------------------------------------------------------------------
-
- FW_CRandomAccessSink::FW_CRandomAccessSink(const FW_CRandomAccessSink& sink) :
- FW_CSink(sink)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::~FW_CRandomAccessSink
- //----------------------------------------------------------------------------------------
-
- FW_CRandomAccessSink::~FW_CRandomAccessSink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::GetReadableBytes
- //----------------------------------------------------------------------------------------
-
- long FW_CRandomAccessSink::GetReadableBytes() const
- {
- return GetLength() - GetPosition();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CRandomAccessSink::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CRandomAccessSink& FW_CRandomAccessSink::operator=(const FW_CRandomAccessSink& sink)
- {
- FW_UNUSED(sink);
- return (*this);
- }
-
-
- //========================================================================================
- // CLASS FW_CMemorySink
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::FW_CMemorySink
- //----------------------------------------------------------------------------------------
-
- FW_CMemorySink::FW_CMemorySink(void* buffer, long capacity, long length) :
- FW_CRandomAccessSink(),
- fBuffer((char*)buffer),
- fCapacity(capacity),
- fLength(length),
- fPosition(0)
- {
- FW_ASSERT(fLength <= fCapacity);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::~FW_CMemorySink
- //----------------------------------------------------------------------------------------
-
- FW_CMemorySink::~FW_CMemorySink()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::Read
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::Read(void* destination,
- long count)
- {
- FW_ASSERT(count >= 0);
- FW_ASSERT(fPosition + count <= fLength);
- FW_PrimitiveCopyMemory(fBuffer + fPosition, destination, count);
- fPosition += count;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::ReadPeek
- //----------------------------------------------------------------------------------------
-
- const void * FW_CMemorySink::ReadPeek(long & availableReadBytes)
- {
- availableReadBytes = fLength - fPosition;
- return fBuffer + fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::ReadPeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::ReadPeekAdvance(long bytesRead)
- {
- FW_ASSERT(bytesRead >= 0);
- FW_ASSERT(fPosition + bytesRead <= fLength);
- fPosition += bytesRead;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::GetWritableBytes
- //----------------------------------------------------------------------------------------
-
- long FW_CMemorySink::GetWritableBytes() const
- {
- return fCapacity-GetPosition();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::Write
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::Write(const void* source,
- long count)
- {
- FW_ASSERT(count >= 0);
- FW_ASSERT(fPosition + count <= fCapacity);
- FW_PrimitiveCopyMemory(source, fBuffer + fPosition, count);
- fPosition += count;
- if (fLength < fPosition)
- fLength = fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::WritePeek
- //----------------------------------------------------------------------------------------
-
- void * FW_CMemorySink::WritePeek(long& availableWriteBytes)
- {
- availableWriteBytes = fCapacity - fPosition;
- return fBuffer + fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::WritePeekAdvance
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::WritePeekAdvance(long bytesWritten)
- {
- FW_ASSERT(bytesWritten >= 0);
- FW_ASSERT(fPosition + bytesWritten <= fCapacity);
- fPosition += bytesWritten;
- if (fLength < fPosition)
- fLength = fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::GetLength
- //----------------------------------------------------------------------------------------
-
- long FW_CMemorySink::GetLength() const
- {
- return fLength;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::SetLength
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::SetLength(long length)
- {
- FW_ASSERT(length <= fCapacity);
- fLength = length;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::GetPosition
- //----------------------------------------------------------------------------------------
-
- long FW_CMemorySink::GetPosition() const
- {
- return fPosition;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CMemorySink::SetPosition
- //----------------------------------------------------------------------------------------
-
- void FW_CMemorySink::SetPosition(long position)
- {
- FW_ASSERT(position >= 0);
- FW_ASSERT(position <= fLength);
- fPosition = position;
- }
-