Merge pull request #6460 from lioncash/datareader

DataReader: Minor API changes
This commit is contained in:
Léo Lam 2018-03-19 15:02:50 +01:00 committed by GitHub
commit f335790623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 11 additions and 10 deletions

View File

@ -13,18 +13,19 @@
class DataReader class DataReader
{ {
public: public:
__forceinline DataReader() : buffer(nullptr), end(nullptr) {} DataReader() = default;
__forceinline DataReader(u8* src, u8* _end) : buffer(src), end(_end) {} DataReader(u8* src, u8* end_) : buffer(src), end(end_) {}
__forceinline u8* GetPointer() { return buffer; } u8* GetPointer() { return buffer; }
__forceinline u8* operator=(u8* src) const u8* GetPointer() const { return buffer; }
DataReader& operator=(u8* src)
{ {
buffer = src; buffer = src;
return src; return *this;
} }
__forceinline size_t size() { return end - buffer; } size_t size() const { return end - buffer; }
template <typename T, bool swapped = true> template <typename T, bool swapped = true>
__forceinline T Peek(int offset = 0) __forceinline T Peek(int offset = 0) const
{ {
T data; T data;
std::memcpy(&data, &buffer[offset], sizeof(T)); std::memcpy(&data, &buffer[offset], sizeof(T));
@ -54,12 +55,12 @@ public:
} }
template <typename T = u8> template <typename T = u8>
__forceinline void Skip(size_t data = 1) void Skip(size_t data = 1)
{ {
buffer += sizeof(T) * data; buffer += sizeof(T) * data;
} }
private: private:
u8* __restrict buffer; u8* __restrict buffer = nullptr;
u8* end; u8* end = nullptr;
}; };