#include <ByteOutputStream.h>
Inheritance diagram for ByteOutputStream:
Public Member Functions | |
void | writeBytes (void const *pData, uint cbRequested) |
Writes bytes to the stream. | |
PBuffer | getWritePointer (uint cbRequested, uint *pcbActual=NULL) |
Copyless alternative for writing bytes to the stream. | |
void | consumeWritePointer (uint cbUsed) |
Advances stream position after a call to getWritePointer. | |
void | hardPageBreak () |
Marks the current buffer as complete regardless of how much data it contains. | |
virtual void | setWriteLatency (WriteLatency writeLatency) |
Changes the write latency. | |
template<class T> | |
void | writeValue (T const &value) |
Writes a fixed-size type to the stream. | |
FileSize | getOffset () const |
| |
bool | isClosed () const |
| |
void | close () |
Closes this object, releasing any unallocated resources. | |
Protected Member Functions | |
ByteOutputStream () | |
virtual void | flushBuffer (uint cbRequested)=0 |
Must be implemented by derived class to flush buffered data. | |
virtual void | closeImpl () |
Must be implemented by derived class to release any resources. | |
void | setBuffer (PBuffer pBuffer, uint cbBuffer) |
Sets the current buffer to be written. | |
uint | getBytesAvailable () const |
| |
Protected Attributes | |
WriteLatency | writeLatency |
Current write latency mode. | |
FileSize | cbOffset |
Byte position in stream. | |
bool | needsClose |
Private Attributes | |
PBuffer | pNextByte |
Next position to write in output buffer. | |
uint | cbWritable |
Number of writable bytes remaining in output buffer. |
Definition at line 35 of file ByteOutputStream.h.
ByteOutputStream::ByteOutputStream | ( | ) | [explicit, protected] |
Definition at line 29 of file ByteOutputStream.cpp.
References cbWritable, and pNextByte.
00030 { 00031 pNextByte = NULL; 00032 cbWritable = 0; 00033 }
virtual void ByteOutputStream::flushBuffer | ( | uint | cbRequested | ) | [protected, pure virtual] |
Must be implemented by derived class to flush buffered data.
cbRequested | if non-zero, the derived class should allocate a new buffer with at least the requested size and call setBuffer |
Implemented in ByteArrayOutputStream, SegOutputStream, and SpillOutputStream.
Referenced by closeImpl(), getWritePointer(), hardPageBreak(), and writeBytes().
void ByteOutputStream::closeImpl | ( | ) | [protected, virtual] |
Must be implemented by derived class to release any resources.
Implements ClosableObject.
Reimplemented in ByteArrayOutputStream, SegOutputStream, and SpillOutputStream.
Definition at line 57 of file ByteOutputStream.cpp.
References flushBuffer().
Referenced by SegOutputStream::closeImpl().
00058 { 00059 flushBuffer(0); 00060 }
Sets the current buffer to be written.
pBuffer | receives start address of new buffer | |
cbBuffer | number of bytes in buffer |
Definition at line 162 of file ByteOutputStream.h.
References cbWritable, and pNextByte.
Referenced by ByteArrayOutputStream::ByteArrayOutputStream(), ByteArrayOutputStream::clear(), SpillOutputStream::flushBuffer(), SegOutputStream::flushBuffer(), and SpillOutputStream::SpillOutputStream().
00163 { 00164 pNextByte = pBuffer; 00165 cbWritable = cbBuffer; 00166 }
uint ByteOutputStream::getBytesAvailable | ( | ) | const [inline, protected] |
Definition at line 168 of file ByteOutputStream.h.
References cbWritable.
Referenced by SpillOutputStream::closeImpl(), SpillOutputStream::flushBuffer(), SegOutputStream::getBytesWrittenThisPage(), SegOutputStream::getSegPos(), SpillOutputStream::spill(), and SpillOutputStream::updatePage().
00169 { 00170 return cbWritable; 00171 }
void ByteOutputStream::writeBytes | ( | void const * | pData, | |
uint | cbRequested | |||
) |
Writes bytes to the stream.
pData | source buffer containing bytes to be written | |
cbRequested | number of bytes to write |
Definition at line 35 of file ByteOutputStream.cpp.
References ByteStream::cbOffset, cbWritable, flushBuffer(), and pNextByte.
Referenced by FtrsTableWriter::execute().
00036 { 00037 cbOffset += cb; 00038 if (!cbWritable) { 00039 flushBuffer(1); 00040 } 00041 for (;;) { 00042 assert(cbWritable); 00043 if (cb <= cbWritable) { 00044 memcpy(pNextByte,pData,cb); 00045 cbWritable -= cb; 00046 pNextByte += cb; 00047 return; 00048 } 00049 memcpy(pNextByte,pData,cbWritable); 00050 pData = static_cast<char const *>(pData) + cbWritable; 00051 cb -= cbWritable; 00052 cbWritable = 0; 00053 flushBuffer(1); 00054 } 00055 }
Copyless alternative for writing bytes to the stream.
Provides direct access to the stream's internal buffer, but doesn't move the stream position (see consumeWritePointer).
cbRequested | number of contiguous bytes to access; if fewer bytes are currently available in the buffer, the buffer is flushed and a new buffer is returned | |
pcbActual | if non-NULL, receives actual number of contiguous writable bytes, which will always be greater than or equal to cbRequested |
Definition at line 141 of file ByteOutputStream.h.
References cbWritable, flushBuffer(), and pNextByte.
Referenced by BTreeWriter::deleteCurrent(), BTreeWriter::insertTupleFromBuffer(), and SegOutputStream::SegOutputStream().
00143 { 00144 if (cbWritable < cbRequested) { 00145 flushBuffer(cbRequested); 00146 assert(cbWritable >= cbRequested); 00147 } 00148 if (pcbActual) { 00149 *pcbActual = cbWritable; 00150 } 00151 return pNextByte; 00152 }
void ByteOutputStream::consumeWritePointer | ( | uint | cbUsed | ) | [inline] |
Advances stream position after a call to getWritePointer.
cbUsed | number of bytes to advance; must be less than or equal to the value of cbActual returned by the last call to getWritePointer |
Definition at line 154 of file ByteOutputStream.h.
References ByteStream::cbOffset, cbWritable, and pNextByte.
Referenced by BTreeWriter::deleteCurrent(), and BTreeWriter::insertTupleFromBuffer().
00155 { 00156 assert(cbUsed <= cbWritable); 00157 cbWritable -= cbUsed; 00158 pNextByte += cbUsed; 00159 cbOffset += cbUsed; 00160 }
void ByteOutputStream::hardPageBreak | ( | ) |
Marks the current buffer as complete regardless of how much data it contains.
The exact semantics are dependent on the buffering implementation.
Definition at line 62 of file ByteOutputStream.cpp.
References cbWritable, flushBuffer(), and pNextByte.
00063 { 00064 flushBuffer(0); 00065 cbWritable = 0; 00066 pNextByte = NULL; 00067 }
void ByteOutputStream::setWriteLatency | ( | WriteLatency | writeLatency | ) | [virtual] |
Changes the write latency.
May not be meaningful for all stream implementations.
writeLatency | new WriteLatency setting |
Reimplemented in SpillOutputStream.
Definition at line 69 of file ByteOutputStream.cpp.
References writeLatency.
Referenced by SpillOutputStream::setWriteLatency().
00070 { 00071 writeLatency = writeLatencyInit; 00072 }
void ByteOutputStream::writeValue | ( | T const & | value | ) | [inline] |
Writes a fixed-size type to the stream.
value | value to read; type must be memcpy-safe |
Definition at line 135 of file ByteOutputStream.h.
Referenced by FtrsTableWriter::describeIndex(), LogicalTxnTest::describeParticipant(), FtrsTableWriter::describeParticipant(), BTreeWriter::describeParticipant(), DatabaseTest::executeIncrementAction(), TupleProjection::writePersistent(), and TupleDescriptor::writePersistent().
00136 { 00137 writeBytes(&value,sizeof(value)); 00138 }
FileSize ByteStream::getOffset | ( | ) | const [inline, inherited] |
Definition at line 110 of file ByteStream.h.
References ByteStream::cbOffset.
Referenced by SpillOutputStream::getInputStream(), and ByteInputStream::mark().
00111 { 00112 return cbOffset; 00113 }
bool ClosableObject::isClosed | ( | ) | const [inline, inherited] |
Definition at line 58 of file ClosableObject.h.
00059 { 00060 return !needsClose; 00061 }
void ClosableObject::close | ( | ) | [inherited] |
Closes this object, releasing any unallocated resources.
Reimplemented in CollectExecStream, CorrelationJoinExecStream, LcsClusterAppendExecStream, and LcsClusterReplaceExecStream.
Definition at line 39 of file ClosableObject.cpp.
References ClosableObject::closeImpl(), and ClosableObject::needsClose.
Referenced by CacheImpl< PageT, VictimPolicyT >::allocatePages(), LcsRowScanBaseExecStream::closeImpl(), ExecStreamGraphImpl::closeImpl(), FlatFileBuffer::open(), ClosableObjectDestructor::operator()(), and Segment::~Segment().
00040 { 00041 if (!needsClose) { 00042 return; 00043 } 00044 needsClose = false; 00045 closeImpl(); 00046 }
PBuffer ByteOutputStream::pNextByte [private] |
Next position to write in output buffer.
Definition at line 40 of file ByteOutputStream.h.
Referenced by ByteOutputStream(), consumeWritePointer(), getWritePointer(), hardPageBreak(), setBuffer(), and writeBytes().
uint ByteOutputStream::cbWritable [private] |
Number of writable bytes remaining in output buffer.
Definition at line 45 of file ByteOutputStream.h.
Referenced by ByteOutputStream(), consumeWritePointer(), getBytesAvailable(), getWritePointer(), hardPageBreak(), setBuffer(), and writeBytes().
WriteLatency ByteOutputStream::writeLatency [protected] |
Current write latency mode.
Definition at line 51 of file ByteOutputStream.h.
Referenced by SegOutputStream::flushBuffer(), SegOutputStream::SegOutputStream(), setWriteLatency(), and SpillOutputStream::spill().
FileSize ByteStream::cbOffset [protected, inherited] |
Byte position in stream.
Definition at line 41 of file ByteStream.h.
Referenced by ByteStream::ByteStream(), ByteInputStream::consumeReadPointer(), consumeWritePointer(), ByteStream::getOffset(), SegOutputStream::getSegPos(), SegInputStream::getSegPos(), ByteInputStream::readBytes(), ByteInputStream::reset(), ByteArrayInputStream::resetArray(), ByteInputStream::seekBackward(), SegInputStream::seekSegPos(), and writeBytes().
bool ClosableObject::needsClose [protected, inherited] |
Definition at line 44 of file ClosableObject.h.
Referenced by SegStreamAllocation::beginWrite(), ExecStreamGraphImpl::clear(), ClosableObject::ClosableObject(), ClosableObject::close(), FlatFileBuffer::open(), ExecStreamGraphImpl::open(), ExecStream::open(), and ClosableObject::~ClosableObject().