/* * AIM tools * Copyright (C) 2015 lzwdgc * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ #pragma once #include #include #include #include #define READ(b, var) b.read(&var, sizeof(var)) #define READ_NOTHROW(b, var) b.read(&var, sizeof(var), true) #define READ_N(b, var, sz) b.read(&var, sz) #define WRITE(b, var) b.write(&var, sizeof(var)) std::string version(); std::vector readFile(const std::string &fn); void writeFile(const std::string &fn, const std::vector &data); class buffer { public: buffer(); buffer(size_t size); buffer(const std::vector &buf, uint32_t data_offset = 0); buffer(buffer &rhs, uint32_t size); buffer(buffer &rhs, uint32_t size, uint32_t offset); uint32_t read(void *dst, uint32_t size, bool nothrow = false) const; uint32_t write(const void *src, uint32_t size, bool nothrow = false); template uint32_t write(const T &src, bool nothrow = false) { return write(&src, sizeof(src), nothrow); } void skip(int n) const; bool eof() const; bool check(int index) const; void reset() const; uint32_t getIndex() const; uint32_t getSize() const; const std::vector &getBuf() const; private: std::shared_ptr> buf; mutable uint32_t index = 0; mutable uint8_t *ptr = 0; mutable uint32_t data_offset = 0; mutable uint32_t size = 0; };