0ad/source/ps/FilePacker.h
janwas b755ddefda remove all author/modified by tags.
make include guards consistent.

This was SVN commit r5040.
2007-05-07 16:33:24 +00:00

53 lines
1.6 KiB
C++

/**
* =========================================================================
* File : FilePacker.h
* Project : 0 A.D.
* Description : Resizable buffer, for writing binary files
* =========================================================================
*/
#ifndef INCLUDED_FILEPACKER
#define INCLUDED_FILEPACKER
#include <vector>
#include "CStr.h"
#include "ps/Errors.h"
#ifndef ERROR_GROUP_FILE_DEFINED
#define ERROR_GROUP_FILE_DEFINED
// FileUnpacker.h defines these too
ERROR_GROUP(File);
ERROR_TYPE(File, OpenFailed);
#endif
ERROR_TYPE(File, WriteFailed);
////////////////////////////////////////////////////////////////////////////////////////
// CFilePacker: class to assist in writing of binary files.
// basically a resizeable buffer that allows adding raw data and strings;
// upon calling Write(), everything is written out to disk.
class CFilePacker
{
public:
// constructor
// adds version and signature (i.e. the header) to the buffer.
// this means Write() can write the entire buffer to file in one go,
// which is simpler and more efficient than writing in pieces.
CFilePacker(u32 version, const char magicstr[4]);
// Write: write out to file all packed data added so far
void Write(const char* filename);
// PackRaw: pack given number of bytes onto the end of the data stream
void PackRaw(const void* rawdata, u32 rawdatalen);
// PackString: pack a string onto the end of the data stream
void PackString(const CStr& str);
private:
// the output data stream built during pack operations.
// contains the header, so we can write this out in one go.
std::vector<u8> m_Data;
};
#endif