/////////////////////////////////////////////////////////////////////////////// // // Name: FilePacker.h // Author: Rich Cross // Contact: rich@wildfiregames.com // /////////////////////////////////////////////////////////////////////////////// #ifndef _FILEPACKER_H #define _FILEPACKER_H #include #include "lib/types.h" // u32 #include "CStr.h" //////////////////////////////////////////////////////////////////////////////////////// // 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: // CFilePacker exceptions class CError { }; class CFileOpenError : public CError { }; class CFileWriteError : public CError { }; 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 m_Data; }; #endif