Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*!
  2. * \file include/utils/binary.h
  3. * \brief Binary file reading utilities
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _UTILS_BINARY_H_
  8. #define _UTILS_BINARY_H_
  9. #include <fstream>
  10. #include <string>
  11. class BinaryReader {
  12. public:
  13. virtual ~BinaryReader();
  14. virtual long long tell() = 0;
  15. virtual void seek(long long pos = 0) = 0;
  16. virtual bool eof() = 0;
  17. virtual int8_t read8();
  18. virtual uint8_t readU8();
  19. virtual int16_t read16();
  20. virtual uint16_t readU16();
  21. virtual int32_t read32();
  22. virtual uint32_t readU32();
  23. virtual int64_t read64();
  24. virtual uint64_t readU64();
  25. virtual float readFloat();
  26. private:
  27. virtual void read(char* d, int c) = 0;
  28. };
  29. class BinaryFile : public BinaryReader {
  30. public:
  31. explicit BinaryFile(std::string f = "");
  32. virtual ~BinaryFile();
  33. int open(std::string f = "");
  34. virtual long long tell();
  35. virtual void seek(long long pos = 0);
  36. virtual bool eof();
  37. private:
  38. virtual void read(char* d, int c);
  39. std::ifstream file;
  40. };
  41. class BinaryMemory : public BinaryReader {
  42. public:
  43. BinaryMemory(const char* d = nullptr, long long max = -1);
  44. virtual ~BinaryMemory();
  45. int open(const char* d = nullptr, long long max = -1);
  46. virtual long long tell();
  47. virtual void seek(long long pos = 0);
  48. virtual bool eof();
  49. private:
  50. virtual void read(char* d, int c);
  51. const char* data;
  52. long long offset;
  53. long long max;
  54. };
  55. #endif