2013-04-17 21:09:55 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
|
|
|
// Licensed under GPLv2
|
|
|
|
// Refer to the license.txt file included.
|
2011-01-10 06:14:56 -07:00
|
|
|
|
2014-02-10 11:54:46 -07:00
|
|
|
#pragma once
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-10-21 00:01:38 -06:00
|
|
|
#include "Common/Common.h"
|
2008-12-07 21:46:09 -07:00
|
|
|
|
2014-11-24 14:22:42 -07:00
|
|
|
class DataReader
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
__forceinline DataReader()
|
|
|
|
: buffer(nullptr), end(nullptr) {}
|
|
|
|
|
|
|
|
__forceinline DataReader(u8* src, u8* _end)
|
|
|
|
: buffer(src), end(_end) {}
|
|
|
|
|
2015-01-06 09:49:27 -07:00
|
|
|
__forceinline u8* GetPointer()
|
2014-11-24 14:22:42 -07:00
|
|
|
{
|
2015-01-06 09:49:27 -07:00
|
|
|
return buffer;
|
2014-11-24 14:22:42 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline u8* operator=(u8* src)
|
|
|
|
{
|
|
|
|
buffer = src;
|
|
|
|
return src;
|
|
|
|
}
|
|
|
|
|
|
|
|
__forceinline size_t size()
|
|
|
|
{
|
|
|
|
return end - buffer;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, bool swapped = true> __forceinline T Peek(int offset = 0)
|
|
|
|
{
|
|
|
|
T data = *(T*)(buffer + offset);
|
|
|
|
if (swapped)
|
|
|
|
data = Common::FromBigEndian(data);
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, bool swapped = true> __forceinline T Read()
|
|
|
|
{
|
|
|
|
const T result = Peek<T, swapped>();
|
|
|
|
buffer += sizeof(T);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T, bool swapped = false> __forceinline void Write(T data)
|
|
|
|
{
|
|
|
|
if (swapped)
|
|
|
|
data = Common::FromBigEndian(data);
|
|
|
|
*(T*)(buffer) = data;
|
|
|
|
buffer += sizeof(T);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T = u8> __forceinline void Skip(size_t data = 1)
|
|
|
|
{
|
|
|
|
buffer += sizeof(T) * data;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
u8* __restrict buffer;
|
|
|
|
u8* end;
|
|
|
|
};
|