#include <DaqFromFStream.h>
Inheritance diagram for DybDaq::DaqFromFStream:
Public Member Functions | |
DaqFromFStream () | |
Creates an instance of this class. | |
virtual | ~DaqFromFStream () |
Destroys this instance. | |
const bool | openFile (const char *const fileName) |
Opens the specified file for reading. | |
bool | close () |
Closes the current Stream being read. | |
const FileBuffer * | nextRecord () |
Returns the next record in the file of NULL is the end of the file has been reached. | |
Protected Member Functions | |
virtual void | closeStream (std::istream &stream) |
Used to close the istream that is backing this class. | |
virtual std::istream * | openStream () |
Used to open a new stream that is used as the backing of this class. | |
bool | hasIStream () const |
Returns true when this object has a valid ostream. | |
bool | open () |
Opens this object for reading. | |
Private Member Functions | |
DaqFromFStream (DaqFromFStream &rhs) | |
Suppress default. | |
DaqFromFStream & | operator= (DaqFromFStream &rhs) |
Suppress default. | |
Private Attributes | |
std::string * | m_fileName |
The name of the file to open. | |
std::ifstream * | m_ifstream |
The file being read. |
Definition at line 18 of file DaqFromFStream.h.
DaqFromFStream::DaqFromFStream | ( | ) |
Creates an instance of this class.
Definition at line 20 of file DaqFromFStream.cc.
00020 : 00021 m_fileName(0), 00022 m_ifstream(0) { 00023 }
DaqFromFStream::~DaqFromFStream | ( | ) | [virtual] |
Destroys this instance.
Definition at line 25 of file DaqFromFStream.cc.
00025 { 00026 if (0 != m_fileName) { 00027 delete m_fileName; 00028 } 00029 if (hasIStream()) { 00030 if (m_ifstream->is_open()) { 00031 m_ifstream->close(); 00032 } 00033 } 00034 }
DybDaq::DaqFromFStream::DaqFromFStream | ( | DaqFromFStream & | rhs | ) | [private] |
Suppress default.
const bool DaqFromFStream::openFile | ( | const char *const | fileName | ) |
Opens the specified file for reading.
Definition at line 48 of file DaqFromFStream.cc.
00048 { 00049 if (0 != m_fileName) { 00050 delete m_fileName; 00051 } 00052 m_fileName = new string(fileName); 00053 return open(); 00054 }
void DaqFromFStream::closeStream | ( | std::istream & | stream | ) | [protected, virtual] |
Used to close the istream that is backing this class.
Implements DybDaq::DaqFromIStream.
Definition at line 42 of file DaqFromFStream.cc.
00042 { 00043 ifstream& fileStream = dynamic_cast<ifstream&> (stream); 00044 fileStream.close(); 00045 m_ifstream = 0; 00046 }
std::istream * DaqFromFStream::openStream | ( | ) | [protected, virtual] |
Used to open a new stream that is used as the backing of this class.
Implements DybDaq::DaqFromIStream.
Definition at line 36 of file DaqFromFStream.cc.
00036 { 00037 m_ifstream = new ifstream(m_fileName->c_str(), 00038 istream::in | istream::binary); 00039 return m_ifstream; 00040 }
DaqFromFStream& DybDaq::DaqFromFStream::operator= | ( | DaqFromFStream & | rhs | ) | [private] |
Suppress default.
bool DaqFromIStream::close | ( | ) | [inherited] |
Closes the current Stream being read.
Definition at line 40 of file DaqFromIStream.cc.
00040 { 00041 if (0 != m_istream) { 00042 closeStream(*m_istream); 00043 delete m_istream; 00044 m_istream = 0; 00045 } 00046 return true; 00047 }
const FileBuffer * DaqFromIStream::nextRecord | ( | ) | [inherited] |
Returns the next record in the file of NULL is the end of the file has been reached.
Definition at line 58 of file DaqFromIStream.cc.
00058 { 00059 ByteBuffer* buffer = new ByteBuffer(new char[DEFAULT_BUFFER_SIZE], 00060 DEFAULT_BUFFER_SIZE); 00061 m_istream->read(buffer->cursor(), 00062 2 * ByteBuffer::BYTES_IN_INT); 00063 if (m_istream->eof()) { 00064 return 0; 00065 } 00066 00067 unsigned int size = buffer->readUnsignedInt(4); 00068 unsigned int lengthInBytes = size * ByteBuffer::BYTES_IN_INT; 00069 const FileBuffer* result = 0; 00070 unsigned int begin = 0; 00071 while (0 == result && buffer->capacity() != lengthInBytes) { 00072 if (lengthInBytes > buffer->capacity()) { 00073 ByteBuffer* previousBuffer = buffer; 00074 buffer = new ByteBuffer(new char[lengthInBytes], 00075 lengthInBytes); 00076 unsigned int bytesRead = previousBuffer->limit(); 00077 previousBuffer->position(begin); 00078 memcpy(buffer->cursor(), 00079 previousBuffer->cursor(), 00080 bytesRead); 00081 buffer->limit(bytesRead); 00082 previousBuffer->release(); 00083 } 00084 unsigned int bytesRead = buffer->limit(); 00085 m_istream->read(buffer->cursor() + bytesRead, 00086 buffer->capacity() - bytesRead); 00087 buffer->limit(buffer->capacity()); 00088 begin = buffer->position(); 00089 result = m_daqFromBytes->createFileBuffer(buffer); 00090 if (0 == result) { 00091 lengthInBytes = m_daqFromBytes->additionalCapacity() + buffer->capacity(); 00092 } 00093 } 00094 return result; 00095 }
bool DaqFromIStream::hasIStream | ( | ) | const [protected, inherited] |
Returns true when this object has a valid ostream.
Definition at line 49 of file DaqFromIStream.cc.
00049 { 00050 return 0 != m_istream; 00051 }
bool DaqFromIStream::open | ( | ) | [protected, inherited] |
Opens this object for reading.
Definition at line 53 of file DaqFromIStream.cc.
00053 { 00054 m_istream = openStream(); 00055 return hasIStream(); 00056 }
std::string* DybDaq::DaqFromFStream::m_fileName [private] |
std::ifstream* DybDaq::DaqFromFStream::m_ifstream [private] |