2022-04-10 00:17:06 +00:00
|
|
|
#ifndef _CINPUTSTREAM_HPP
|
|
|
|
#define _CINPUTSTREAM_HPP
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
|
|
class CInputStream;
|
|
|
|
template < typename T >
|
|
|
|
struct TType {};
|
|
|
|
template < typename T >
|
2022-07-31 00:38:13 +00:00
|
|
|
inline T cinput_stream_helper(const TType< T >& type, CInputStream& in);
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
class CInputStream {
|
|
|
|
public:
|
2022-08-26 03:46:24 +00:00
|
|
|
CInputStream(s32 len);
|
|
|
|
CInputStream(const void* ptr, s32 len, bool owned);
|
2022-04-10 00:17:06 +00:00
|
|
|
virtual ~CInputStream();
|
2022-07-18 17:53:58 +00:00
|
|
|
virtual u32 Read(void* dest, u32 len) = 0;
|
2022-04-10 00:17:06 +00:00
|
|
|
|
2022-07-15 00:48:18 +00:00
|
|
|
f32 ReadFloat();
|
2022-07-18 17:53:58 +00:00
|
|
|
u64 ReadLongLong();
|
|
|
|
u32 ReadLong();
|
|
|
|
u16 ReadShort();
|
2022-07-15 00:48:18 +00:00
|
|
|
bool ReadBool();
|
2022-07-18 17:53:58 +00:00
|
|
|
u8 ReadChar();
|
|
|
|
u32 ReadBits(u32 len);
|
|
|
|
u32 ReadBytes(void* dest, unsigned long len);
|
2022-07-15 00:48:18 +00:00
|
|
|
void Get(void* dest, unsigned long len);
|
2022-07-18 17:53:58 +00:00
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
template < typename T >
|
2022-07-31 00:38:13 +00:00
|
|
|
inline T Get(const TType<T>& type) {
|
|
|
|
return cinput_stream_helper(type, *this);
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2022-07-15 00:48:18 +00:00
|
|
|
bool GrabAnotherBlock();
|
|
|
|
bool InternalReadNext();
|
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
u32 x4_blockOffset;
|
|
|
|
u32 x8_blockLen;
|
|
|
|
u32 xc_len;
|
|
|
|
u8* x10_ptr;
|
|
|
|
bool x14_owned;
|
|
|
|
u32 x18_readPosition;
|
|
|
|
u32 x1c_bitWord;
|
|
|
|
u32 x20_bitOffset;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2022-07-31 00:38:13 +00:00
|
|
|
inline s32 cinput_stream_helper(const TType< s32 >& type, CInputStream& in) {
|
2022-04-10 00:17:06 +00:00
|
|
|
return in.ReadLong();
|
|
|
|
}
|
|
|
|
template <>
|
2022-07-31 00:38:13 +00:00
|
|
|
inline u32 cinput_stream_helper(const TType< u32 >& type, CInputStream& in) {
|
2022-04-10 00:17:06 +00:00
|
|
|
return in.ReadLong();
|
|
|
|
}
|
2022-07-14 16:24:26 +00:00
|
|
|
template <>
|
2022-09-05 04:00:04 +00:00
|
|
|
inline unsigned int cinput_stream_helper(const TType< unsigned int >& type, CInputStream& in) {
|
2022-07-14 16:24:26 +00:00
|
|
|
return in.ReadLong();
|
|
|
|
}
|
2022-07-31 00:38:13 +00:00
|
|
|
template <>
|
|
|
|
inline float cinput_stream_helper(const TType< float >& type, CInputStream& in) {
|
|
|
|
return in.ReadFloat();
|
|
|
|
}
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
// rstl
|
|
|
|
#include "rstl/pair.hpp"
|
|
|
|
template < typename L, typename R >
|
2022-07-31 00:38:13 +00:00
|
|
|
inline rstl::pair< L, R > cinput_stream_helper(const TType< rstl::pair< L, R > >& type, CInputStream& in) {
|
2022-04-10 00:17:06 +00:00
|
|
|
rstl::pair< L, R > result;
|
2022-07-31 00:38:13 +00:00
|
|
|
result.first = in.Get(TType< L >());
|
|
|
|
result.second = in.Get(TType< R >());
|
2022-04-10 00:17:06 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|