BWAPI
trunk/bwapi/Replay_Tool/FileReader.h
Go to the documentation of this file.
00001 #pragma once
00002 #include <windows.h>
00003 #include <string>
00004 
00005 class FileReader
00006 {
00007 public:
00008   FileReader();
00009   FileReader(const void *pData, DWORD dwDataSize);
00010   ~FileReader();
00011   bool Open(const char *pszFilename);
00012   bool Error(const char *pszText = NULL);
00013   void Free();
00014   bool Eof();
00015   template <class _T>
00016   _T Read()
00017   {
00018     _T rval;
00019     if ( dwOffset + sizeof(_T) <= dwFileSize )
00020     {
00021       rval = *(_T*)&this->pMem[dwOffset];
00022       dwOffset += sizeof(_T);
00023     }
00024     else
00025     {
00026       memset(&rval, 0, sizeof(_T));
00027       this->eof = true;
00028     }
00029     return rval;
00030   }
00031   void Read(void *pBuffer, DWORD dwSize);
00032   int         Read7BitEncodedInt();
00033   std::string ReadString();
00034   std::string ReadCString(const char *deliminators = NULL);
00035   DWORD       GetSize();
00036   //FileReader  Decompress(DWORD dwCompressedSize, DWORD dwDecompressedSize);  // Requires XNA header
00037 private:
00038   HANDLE  hFile;
00039   BYTE    *pMem;
00040   DWORD   dwFileSize;
00041   DWORD   dwOffset;
00042   bool    eof;
00043 };
00044 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines