nrEngine::FileStream Class Reference
[Engine's filesystem]

Derived class from IStream to provide streaming from files. More...

Inheritance diagram for nrEngine::FileStream:

nrEngine::IStream nrEngine::IResource nrEngine::EmptyFileStream

Public Member Functions

 FileStream ()
virtual ~FileStream ()
virtual Result open (const std::string &fileName)
const std::string & getName () const
virtual size_t read (void *buf, size_t size, size_t nmemb)
virtual size_t readDelim (void *buf, size_t count, const std::string &delim=std::string("\n"))
virtual size_t tell () const
virtual bool eof () const
virtual bytegetData (size_t &count) const
virtual bool seek (int32 offset, int32 whence=IStream::CURRENT)
virtual void close ()

Friends

class FileStreamLoader
 The file stream loader should be able to change the data of this object.

Detailed Description

Derived class from IStream to provide streaming from files.

FileStream is derived class from IStream and IResource. It provides the functionality of streaming the files from the disk. We use the std::ifstream class to do this work.

This class is a simple file class which provide the user only with nessary methods. You should use plugins to extend the functionality for working with compressed, encrypted etc. file archives.

Because each file is also a resource, so you can open the files through the resource manager. This will call the appropriate resource loader (in our case file loader) to provide you with the file you requested. The type of such a resource is "File" Plugins can add new types like "ZipFile", "ZipArchive", ...

Definition at line 45 of file FileStream.h.


Constructor & Destructor Documentation

nrEngine::FileStream::FileStream (  ) 

Constructor of the file stream. The loader should specify all neccessary properties of this object to allow opening of the file.

Definition at line 23 of file FileStream.cpp.

nrEngine::FileStream::~FileStream (  )  [virtual]

Virtual destructor allows to derive new classes from this interface

Definition at line 28 of file FileStream.cpp.


Member Function Documentation

Result nrEngine::FileStream::open ( const std::string &  fileName  )  [virtual]

Open a file as a stream without using of underlying resource system.

Definition at line 48 of file FileStream.cpp.

References nrEngine::FILE_NOT_FOUND, nrEngine::Log::LL_ERROR, nrEngine::Log::LOG_ENGINE, nrEngine::IStream::mSize, and nrEngine::OK.

const std::string& nrEngine::FileStream::getName (  )  const

Return the name of the stream. The name of the stream is the same as the name of the underlying resource used for the file storing.

Definition at line 74 of file FileStream.h.

size_t nrEngine::FileStream::read ( void *  buf,
size_t  size,
size_t  nmemb 
) [virtual]

See also:
IStream::read()
Parameters:
nmemb Number of element to read in
buf Buffer to read from
size Size of one element

Implements nrEngine::IStream.

Reimplemented in nrEngine::EmptyFileStream.

Definition at line 78 of file FileStream.cpp.

size_t nrEngine::FileStream::readDelim ( void *  buf,
size_t  count,
const std::string &  delim = std::string("\n") 
) [virtual]

Same as read, but reads the line until it found the delimiter string in the data

Implements nrEngine::IStream.

Reimplemented in nrEngine::EmptyFileStream.

Definition at line 86 of file FileStream.cpp.

References nrEngine::Log::LL_ERROR, nrEngine::Log::LL_WARNING, and nrEngine::Log::LOG_ENGINE.

size_t nrEngine::FileStream::tell (  )  const [virtual]

Returns the current byte offset from the beginning in other words position of the stream cursor

Implements nrEngine::IStream.

Reimplemented in nrEngine::EmptyFileStream.

Definition at line 133 of file FileStream.cpp.

bool nrEngine::FileStream::eof (  )  const [virtual]

Returns true if end of the stream is reached

Implements nrEngine::IStream.

Reimplemented in nrEngine::EmptyFileStream.

Definition at line 141 of file FileStream.cpp.

byte * nrEngine::FileStream::getData ( size_t &  count  )  const [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

Implements nrEngine::IStream.

Reimplemented in nrEngine::EmptyFileStream.

Definition at line 148 of file FileStream.cpp.

References nrEngine::IStream::mSize.

bool nrEngine::FileStream::seek ( int32  offset,
int32  whence = IStream::CURRENT 
) [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)

Implements nrEngine::IStream.

Reimplemented in nrEngine::EmptyFileStream.

Definition at line 169 of file FileStream.cpp.

References nrEngine::IStream::END, and nrEngine::IStream::START.

void nrEngine::FileStream::close (  )  [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.

Implements nrEngine::IStream.

Reimplemented in nrEngine::EmptyFileStream.

Definition at line 69 of file FileStream.cpp.

References nrEngine::IStream::mSize.


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