Inheritance diagram for nrEngine::IStream:
Public Types | |
enum | { START, CURRENT, END } |
Start position for the seeking. More... | |
Public Member Functions | |
IStream (uint32 streamBufSize=STREAM_BUFFER_SIZE) | |
IStream (const std::string &name, uint32 streamBufSize=STREAM_BUFFER_SIZE) | |
virtual | ~IStream () |
virtual const std::string & | getName () |
template<typename T> | |
IStream & | operator>> (T &val) |
NR_FORCEINLINE int32 | getBufferSize () const |
size_t | read (void *buf, size_t count) |
virtual size_t | read (void *buf, size_t size, size_t nmemb)=0 |
virtual size_t | readDelim (void *buf, size_t count, const std::string &delim=std::string("\n"))=0 |
virtual size_t | tell () const=0 |
virtual bool | eof () const=0 |
virtual byte * | getData (size_t &count) const =0 |
virtual std::string | getAsString () |
virtual std::string | getLine () |
virtual bool | seek (int32 offset, int32 whence=CURRENT)=0 |
size_t | size () const |
virtual void | close ()=0 |
Static Public Attributes | |
static const uint32 | STREAM_BUFFER_SIZE = 256 |
Default size of the buffer. | |
Protected Attributes | |
std::string | mName |
Name of the stream. | |
size_t | mSize |
Size of the stream in bytes. If size could not be determined so 0. | |
uint32 | mStreamBufSize |
Our stream buffer should be of this size. | |
byte * | mBuffer |
Buffer to hold the data. |
IStream represents an interface for every kind of stream objects. Stream objects should be able to pass the data from somewhere else to the requester (e.g. engine). The interface is similar to the std::istream object so you can think it is like a wrapper.
Good example for such stream objects could be a file stream. In the standard c++ library you already have got the ifstream which can be reimplemented for this interface.
Definition at line 39 of file IStream.h.
anonymous enum |
nrEngine::IStream::IStream | ( | uint32 | streamBufSize = STREAM_BUFFER_SIZE |
) |
Empty default constructor.
streamBufSize | Size of the buffer for this stream. Only buffered streams. |
Definition at line 22 of file IStream.cpp.
References mBuffer, and mStreamBufSize.
nrEngine::IStream::IStream | ( | const std::string & | name, | |
uint32 | streamBufSize = STREAM_BUFFER_SIZE | |||
) |
Constructor allows specify a name for the stream
name | Name of the stream | |
streamBufSize | Size of the buffer for this stream. Only buffered streams. |
Definition at line 34 of file IStream.cpp.
References mBuffer, and mStreamBufSize.
nrEngine::IStream::~IStream | ( | ) | [virtual] |
Virtual destructor allows to derive new classes from this interface
Definition at line 45 of file IStream.cpp.
References mBuffer.
virtual const std::string& nrEngine::IStream::getName | ( | ) | [virtual] |
IStream & nrEngine::IStream::operator>> | ( | T & | val | ) |
Streaming operator to stream the data to the variable
Definition at line 53 of file IStream.cpp.
References read().
NR_FORCEINLINE int32 nrEngine::IStream::getBufferSize | ( | ) | const |
size_t nrEngine::IStream::read | ( | void * | buf, | |
size_t | count | |||
) |
Read data from the stream (like read from stdio.h).
buf | Here the readed data will be stored | |
count | Number of bytes to be readed |
Definition at line 102 of file IStream.cpp.
Referenced by getAsString(), and operator>>().
virtual size_t nrEngine::IStream::read | ( | void * | buf, | |
size_t | size, | |||
size_t | nmemb | |||
) | [pure virtual] |
Same as read but allows reading of specified count of elements instead of bytes.
buf | Buffer where to store the readed data | |
size | Size of each element to be readed | |
nmemb | Count of elements |
Implemented in nrEngine::FileStream, and nrEngine::EmptyFileStream.
virtual size_t nrEngine::IStream::readDelim | ( | void * | buf, | |
size_t | count, | |||
const std::string & | delim = std::string("\n") | |||
) | [pure virtual] |
Same as read, but reads the line until it found the delimiter string in the data
Implemented in nrEngine::FileStream, and nrEngine::EmptyFileStream.
Referenced by getLine().
virtual size_t nrEngine::IStream::tell | ( | ) | const [pure virtual] |
Returns the current byte offset from the beginning in other words position of the stream cursor
Implemented in nrEngine::FileStream, and nrEngine::EmptyFileStream.
virtual bool nrEngine::IStream::eof | ( | ) | const [pure virtual] |
Returns true if end of the stream is reached
Implemented in nrEngine::FileStream, and nrEngine::EmptyFileStream.
virtual byte* nrEngine::IStream::getData | ( | size_t & | count | ) | const [pure virtual] |
Return the full data containing in the stream only if we were able to retrieve the data. If the stream is buffered, so it should return the content of the whole buffer and retrieve new data.
count | Return count of bytes returned by the function |
Implemented in nrEngine::FileStream, and nrEngine::EmptyFileStream.
std::string nrEngine::IStream::getAsString | ( | ) | [virtual] |
Only for text-only streams. You have the abbility to return the whole stream content as a string
Definition at line 83 of file IStream.cpp.
std::string nrEngine::IStream::getLine | ( | ) | [virtual] |
Read a line from the stream. Only usefull for text-only-streams
Definition at line 61 of file IStream.cpp.
References mBuffer, mStreamBufSize, and readDelim().
Seek the read pointer to specified position.
offset | Number of bytes to jump | |
whence | From where we should compute the new position CURRENT, START, END |
Implemented in nrEngine::FileStream, and nrEngine::EmptyFileStream.
size_t nrEngine::IStream::size | ( | ) | const |
virtual void nrEngine::IStream::close | ( | ) | [pure virtual] |
Close the stream. After you close it no operations like seek, or read are valid anymore. The stream is also automaticly closed if you call the destructor.
Implemented in nrEngine::FileStream, and nrEngine::EmptyFileStream.