Files
0ad/source/ps/FileUnpacker.h
T
janwas e2eb5b2610 part4: adapt codebase to changes in lib/
mostly straightforward except for CVSFile / Filesystem. moved the former
into the newly created latter component. removed VFSUtil entirely (that
functionality is available from lib/file/file_system_util.h)

Xeromyces.cpp: simplify buffer handling since smart pointers are now in
play. also use WriteBuffer instead of membuffer.

This was SVN commit r5519.
2007-12-20 20:21:45 +00:00

63 lines
1.8 KiB
C++

/**
* =========================================================================
* File : FileUnpacker.h
* Project : 0 A.D.
* Description : Buffer and 'stream' for reading binary files
* =========================================================================
*/
#ifndef INCLUDED_FILEUNPACKER
#define INCLUDED_FILEUNPACKER
#include <vector>
class CStr8;
#include "ps/Errors.h"
#ifndef ERROR_GROUP_FILE_DEFINED
#define ERROR_GROUP_FILE_DEFINED
// FilePacker.h defines these too
ERROR_GROUP(File);
ERROR_TYPE(File, OpenFailed);
#endif
ERROR_TYPE(File, InvalidType);
ERROR_TYPE(File, InvalidVersion);
ERROR_TYPE(File, ReadFailed);
ERROR_TYPE(File, UnexpectedEOF);
////////////////////////////////////////////////////////////////////////////////
// CFileUnpacker: class to assist in reading of binary files
class CFileUnpacker
{
public:
// constructor
CFileUnpacker();
~CFileUnpacker();
// Read: open and read in given file, check magic bits against those given; throw
// variety of exceptions for missing files etc
void Read(const char* filename, const char magicstr[4]);
// GetVersion: return stored file version
u32 GetVersion() const { return m_Version; }
// UnpackRaw: unpack given number of bytes from the input stream into the given array
// - throws PSERROR_File_UnexpectedEOF if the end of the data stream is reached before
// the given number of bytes have been read
void UnpackRaw(void* rawdata, size_t rawdatalen);
// UnpackString: unpack a string from the raw data stream
void UnpackString(CStr8& result);
private:
// the data read from file and used during unpack operations
shared_ptr<u8> m_Buf;
size_t m_Size;
// current unpack position in stream
size_t m_UnpackPos;
// version of the file currently being read
u32 m_Version;
};
#endif