nrEngine::IStream Class Reference

Stream is an interface for stream objects (files, urls, ...). More...

Inheritance diagram for nrEngine::IStream:

nrEngine::FileStream nrEngine::EmptyFileStream

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>
IStreamoperator>> (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 bytegetData (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.
bytemBuffer
 Buffer to hold the data.

Detailed Description

Stream is an interface for stream objects (files, urls, ...).

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.


Member Enumeration Documentation

anonymous enum

Start position for the seeking.

Enumerator:
START  Compute new cursor position from the beginning.
CURRENT  Seek from the current position.
END  NEw position is computed from the end of file.

Definition at line 43 of file IStream.h.


Constructor & Destructor Documentation

nrEngine::IStream::IStream ( uint32  streamBufSize = STREAM_BUFFER_SIZE  ) 

Empty default constructor.

Parameters:
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

Parameters:
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.


Member Function Documentation

virtual const std::string& nrEngine::IStream::getName (  )  [virtual]

Return the name of the stream

Definition at line 76 of file IStream.h.

template<typename T>
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

Get the size of the buffer (only for buffered streams)

Definition at line 86 of file IStream.h.

size_t nrEngine::IStream::read ( void *  buf,
size_t  count 
)

Read data from the stream (like read from stdio.h).

Parameters:
buf Here the readed data will be stored
count Number of bytes to be readed
Returns:
Count fo readed bytes.
Note:
buf should have at least size count

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.

Parameters:
buf Buffer where to store the readed data
size Size of each element to be readed
nmemb Count of elements
Returns:
Number of successfully readed elements (not bytes)

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.

Parameters:
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.

References mSize, and read().

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().

virtual bool nrEngine::IStream::seek ( int32  offset,
int32  whence = CURRENT 
) [pure virtual]

Seek the read pointer to specified position.

Parameters:
offset Number of bytes to jump
whence From where we should compute the new position CURRENT, START, END
Returns:
false if error occurs (e.g. eof or wrong whence position)

Implemented in nrEngine::FileStream, and nrEngine::EmptyFileStream.

size_t nrEngine::IStream::size (  )  const

Returns the size of the stream (ength of the data in the stream) If size could not be determined, so return 0

Definition at line 161 of file IStream.h.

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.


The documentation for this class was generated from the following files:
Generated on Wed Sep 12 23:19:43 2007 for nrEngine by  doxygen 1.5.1