Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | Related Pages

BufferFile Class Reference

#include <file.h>

Inheritance diagram for BufferFile:

Inheritance graph
[legend]
Collaboration diagram for BufferFile:

Collaboration graph
[legend]
List of all members.

Detailed Description

Emulate File object on data buffer A buffer file implements file operations on an arbitrary memory buffer. This can be useful if you want to load resources from data embedded in your application, you can then create a BufferFile object and pass to all classes and methods accepting a File object for loading (all classes that are derived LoadableEntity supports loading from a File object).

Author:
Mattias Jansson (mattias@realityrift.com)


Public Member Functions

 BufferFile (unsigned char *pucBuffer=0, int iSize=0, const std::string &rstrPath="", const std::string &rstrFilename="", std::ios_base::openmode uiOpenMode=(std::ios_base::in|std::ios_base::binary), bool bOpen=false, Directory *pkDirectory=0)
virtual ~BufferFile ()
virtual void Close ()
void SetBuffer (unsigned char *pucBuffer, int iSize)
virtual bool Open (const std::string &rstrPath="", const std::string &rstrFilename="", std::ios_base::openmode uiOpenMode=(std::ios_base::openmode) 0)
virtual bool IsValid () const
void SetByteOrder (Core::BYTEORDER eByteOrder)
virtual int GetSize ()
std::streampos Tellg () const
std::streampos Tellp () const
virtual FileRead (void *pBuffer, int iNumBytes)
virtual FileWrite (const void *pBuffer, int iNumBytes)
virtual FileGetLine (char *pcDest, unsigned int uiCount, char cDelimiter= '\n')
FileSeekg (std::streamoff uiOffset, std::ios_base::seekdir uiDirection)
FileSeekp (std::streamoff uiOffset, std::ios_base::seekdir uiDirection)
const std::string & GetPath () const
const std::string & GetName () const
DirectoryGetDirectory ()
virtual Core::BYTEORDER GetByteOrder () const
bool DetermineByteOrder (int iReferenceValue)
bool SetBinary (bool bBinary)
bool IsBinary () const
bool DetermineBinaryMode (const unsigned char *pucReferenceValues)
Fileoperator<< (bool bData)
Fileoperator<< (int8_t cData)
Fileoperator<< (uint8_t ucData)
Fileoperator<< (int16_t sData)
Fileoperator<< (uint16_t usData)
Fileoperator<< (int32_t iData)
Fileoperator<< (uint32_t uiData)
Fileoperator<< (float fData)
Fileoperator<< (const char *pszData)
Fileoperator<< (const std::string &rstrData)
Fileoperator<< (const HashString &rstrData)
Fileoperator<< (std::ios_base &(NE_CDECL *pfnManip)(std::ios_base &))
Fileoperator<< (std::basic_ostream< char > &(NE_CDECL *pfnManip)(std::basic_ostream< char > &))
Fileoperator>> (bool &rbData)
Fileoperator>> (int8_t &rcData)
Fileoperator>> (uint8_t &rucData)
Fileoperator>> (int16_t &rsData)
Fileoperator>> (uint16_t &rusData)
Fileoperator>> (int32_t &riData)
Fileoperator>> (uint32_t &ruiData)
Fileoperator>> (float &rfData)
Fileoperator>> (std::string &rstrData)
Fileoperator>> (HashString &rstrData)
Fileoperator>> (std::ios_base &(NE_CDECL *pfnManip)(std::ios_base &))
Fileoperator>> (std::basic_ostream< char > &(NE_CDECL *pfnManip)(std::basic_ostream< char > &))
bool operator! () const

Static Public Member Functions

std::string ExtractBaseFileName (const std::string &rstrPath)
std::string ExtractFileExtension (const std::string &rstrPath)
std::string ExtractFileName (const std::string &rstrPath)
std::string ExtractPathName (const std::string &rstrPath)

Protected Member Functions

virtual void AllocStream (const std::string &rstrFullPath)

Protected Attributes

BufferFileStreamBufm_pkBuffer
std::iostream * m_pkStream
std::ios_base::openmode m_uiOpenMode
bool m_bBinary
Core::BYTEORDER m_eByteOrder
Directorym_pkDirectory


Constructor & Destructor Documentation

BufferFile unsigned char *  pucBuffer = 0,
int  iSize = 0,
const std::string &  rstrPath = "",
const std::string &  rstrFilename = "",
std::ios_base::openmode  uiOpenMode = (std::ios_base::in|std::ios_base::binary),
bool  bOpen = false,
Directory pkDirectory = 0
 

Parameters:
pucBuffer Buffer
iSize Size of buffer
rstrPath Path
rstrFilename Filename
uiOpenMode Open mode
bOpen Open file
pkDirectory Parent directory

virtual ~BufferFile  )  [virtual]
 


Member Function Documentation

virtual void AllocStream const std::string &  rstrFullPath  )  [protected, virtual]
 

Allocate the stream object

Parameters:
rstrFullPath Full path name

Reimplemented from File.

Reimplemented in VirtualFile.

virtual void Close  )  [virtual]
 

Deallocate buffer

Reimplemented from File.

void SetBuffer unsigned char *  pucBuffer,
int  iSize
 

Set buffer to use

Parameters:
pucBuffer Buffer
iSize Size in bytes of buffer

virtual bool Open const std::string &  rstrPath = "",
const std::string &  rstrFilename = "",
std::ios_base::openmode  uiOpenMode = (std::ios_base::openmode) 0
[virtual, inherited]
 

Open file. Close any open handles. If null are passed as args, previously stored names will be used

Parameters:
rstrPath Path
rstrFilename Filename
uiOpenMode Open mode, default is in|binary
Returns:
true if successful, false if error

virtual bool IsValid  )  const [inline, virtual, inherited]
 

Query if file is valid (file exists and is open)

Returns:
true if file is open, false otherwise

void SetByteOrder Core::BYTEORDER  eByteOrder  )  [inline, inherited]
 

Set byte order of file

Parameters:
eByteOrder New byte order

virtual int GetSize  )  [virtual, inherited]
 

Get file size. File does not have to be open. Returns -1 if error (unable to open file)

Returns:
File size

std::streampos Tellg  )  const [inline, inherited]
 

Get current get (read) pointer position

Returns:
Position in stream of get pointer

std::streampos Tellp  )  const [inline, inherited]
 

Get current put (write) pointer position

Returns:
Position in stream of put pointer

virtual File& Read void *  pBuffer,
int  iNumBytes
[virtual, inherited]
 

Read raw data

Parameters:
pBuffer Destination buffer
iNumBytes Number of bytes to read
Returns:
File self-reference

virtual File& Write const void *  pBuffer,
int  iNumBytes
[virtual, inherited]
 

Write raw data

Parameters:
pBuffer Buffer of data to write
iNumBytes Number of bytes to write
Returns:
File self-reference

virtual File& GetLine char *  pcDest,
unsigned int  uiCount,
char  cDelimiter = '\n'
[virtual, inherited]
 

Get up to uiCount characters, discarding delimiter

Parameters:
pcDest Destination buffer, null if input is to be ignored
uiCount Maximum number of characters to extract
cDelimiter Delimiter, default '
'
Returns:
File self-reference

File& Seekg std::streamoff  uiOffset,
std::ios_base::seekdir  uiDirection
[inline, inherited]
 

Reposition the get (read) pointer

Parameters:
uiOffset Offset in bytes
uiDirection Seek direction,
Returns:
File self-reference

File& Seekp std::streamoff  uiOffset,
std::ios_base::seekdir  uiDirection
[inline, inherited]
 

Reposition the put (write) pointer

Parameters:
uiOffset Offset in bytes
uiDirection Seek direction,
Returns:
File self-reference

const std::string& GetPath  )  const [inline, inherited]
 

Returns:
Directory path

const std::string& GetName  )  const [inline, inherited]
 

Returns:
Name of file

Directory* GetDirectory  )  [inline, inherited]
 

Returns:
Ptr to parent directory if any

virtual Core::BYTEORDER GetByteOrder  )  const [inline, virtual, inherited]
 

Returns:
Current file byte order

bool DetermineByteOrder int  iReferenceValue  )  [inherited]
 

Try to determine file byte ordering by reading integer and comparing with reference Integer will be read from file at current position, and compared to reference value. If determination was successful, the file byte ordering will be set. File pointer will be restored to original position in any case.

Parameters:
iReferenceValue Reference integer
Returns:
true if byte order identification was successful, false if not

bool SetBinary bool  bBinary  )  [inherited]
 

Set binary/ascii mode flag

Parameters:
bBinary Set file mode to binary if true, set to ascii if false
Returns:
true if file mode was binary before this call, false if file mode was ascii

bool IsBinary  )  const [inherited]
 

Query if binary/ascii mode

Returns:
true if file mode is binary, false if file mode is ascii

bool DetermineBinaryMode const unsigned char *  pucReferenceValues  )  [inherited]
 

Try to determine file mode by reading four binary values and comparing with reference array. If matching the file mode will be set to binary, if not matching file mode will be set to ascii

Parameters:
pucReferenceValues Pointer to four reference values
Returns:
true if file mode identification was successful, false if not

File& operator<< bool  bData  )  [inherited]
 

Write boolean to file

Parameters:
bData Boolean to write
Returns:
File self-reference

File& operator<< int8_t  cData  )  [inherited]
 

Write char to file

Parameters:
cData Char to write
Returns:
File self-reference

File& operator<< uint8_t  ucData  )  [inherited]
 

Write byte to file

Parameters:
ucData Byte to write
Returns:
File self-reference

File& operator<< int16_t  sData  )  [inherited]
 

Write short to file

Parameters:
sData Short to write
Returns:
File self-reference

File& operator<< uint16_t  usData  )  [inherited]
 

Write unsigned short to file

Parameters:
usData Unsigned short to write
Returns:
File self-reference

File& operator<< int32_t  iData  )  [inherited]
 

Write integer to file

Parameters:
iData Integer to write
Returns:
File self-reference

File& operator<< uint32_t  uiData  )  [inherited]
 

Write unsigned integer to file

Parameters:
uiData Unsigned integer to write
Returns:
File self-reference

File& operator<< float  fData  )  [inherited]
 

Write float to file

Parameters:
fData Float to write
Returns:
File self-reference

File& operator<< const char *  pszData  )  [inherited]
 

Write null-terminated string to file

Parameters:
pszData String to write
Returns:
File self-reference

File& operator<< const std::string &  rstrData  )  [inherited]
 

Write string to file

Parameters:
rstrData String to write
Returns:
File self-reference

File& operator<< const HashString rstrData  )  [inherited]
 

Write string to file

Parameters:
rstrData String to write
Returns:
File self-reference

File& operator<< std::ios_base &  (NE_CDECL *pfnManip)(std::ios_base &)  )  [inline, inherited]
 

Insert stream manipulator

Returns:
File self-reference

File& operator<< std::basic_ostream< char > &  (NE_CDECL *pfnManip)(std::basic_ostream< char > &)  )  [inline, inherited]
 

Insert stream manipulator

Returns:
File self-reference

File& operator>> bool &  rbData  )  [inherited]
 

Read boolean from file

Parameters:
rbData Boolean to read to
Returns:
File self-reference

File& operator>> int8_t &  rcData  )  [inherited]
 

Read char from file

Parameters:
rcData Char to read to
Returns:
File self-reference

File& operator>> uint8_t &  rucData  )  [inherited]
 

Read byte from file

Parameters:
rucData Byte to read to
Returns:
File self-reference

File& operator>> int16_t &  rsData  )  [inherited]
 

Read short from file

Parameters:
rsData Short to read to
Returns:
File self-reference

File& operator>> uint16_t &  rusData  )  [inherited]
 

Read unsigned short from file

Parameters:
rusData Unsigned short to read to
Returns:
File self-reference

File& operator>> int32_t &  riData  )  [inherited]
 

Read integer from file

Parameters:
riData Integer to read to
Returns:
File self-reference

File& operator>> uint32_t &  ruiData  )  [inherited]
 

Read unsigned integer from file

Parameters:
ruiData Unsigned integer to read to
Returns:
File self-reference

File& operator>> float &  rfData  )  [inherited]
 

Read float from file

Parameters:
rfData Float to read to
Returns:
File self-reference

File& operator>> std::string &  rstrData  )  [inherited]
 

Read string from file

Parameters:
rstrData String to read to
Returns:
File self-reference

File& operator>> HashString rstrData  )  [inherited]
 

Read string from file

Parameters:
rstrData Hash string to read to
Returns:
File self-reference

File& operator>> std::ios_base &  (NE_CDECL *pfnManip)(std::ios_base &)  )  [inline, inherited]
 

Insert stream manipulator

Returns:
File self-reference

File& operator>> std::basic_ostream< char > &  (NE_CDECL *pfnManip)(std::basic_ostream< char > &)  )  [inline, inherited]
 

Insert stream manipulator

Returns:
File self-reference

bool operator!  )  const [inline, inherited]
 

Test for valid/invalid state and EOF

Returns:
false if file is valid, true if invalid ro EOF

std::string ExtractBaseFileName const std::string &  rstrPath  )  [static, inherited]
 

Get base file name (no path and no extension) from full path name

Parameters:
rstrPath Full path
Returns:
File base name

std::string ExtractFileExtension const std::string &  rstrPath  )  [static, inherited]
 

Get file extension (no path and no name) from full path name

Parameters:
rstrPath Full path
Returns:
File extension

std::string ExtractFileName const std::string &  rstrPath  )  [static, inherited]
 

Get file name (no path but with extension) from full path name

Parameters:
rstrPath Full path
Returns:
File full name

std::string ExtractPathName const std::string &  rstrPath  )  [static, inherited]
 

Get path name from full path name including file name

Parameters:
rstrPath Full path
Returns:
Path name


Member Data Documentation

BufferFileStreamBuf* m_pkBuffer [protected]
 

Ptr to stream buffer

std::iostream* m_pkStream [protected, inherited]
 

Stream

std::ios_base::openmode m_uiOpenMode [protected, inherited]
 

Open mode

bool m_bBinary [protected, inherited]
 

Binary mode

Core::BYTEORDER m_eByteOrder [protected, inherited]
 

Byte order

Directory* m_pkDirectory [protected, inherited]
 

Directory we are attached to (if any)


The documentation for this class was generated from the following file:
Generated on Wed Jan 21 14:21:11 2004 for NeoEngine by doxygen 1.3.5