prime/include/Kyoto/Streams/CInputStream.hpp

76 lines
1.7 KiB
C++
Raw Normal View History

#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);
class CInputStream {
public:
CInputStream(s32 len);
CInputStream(const void* ptr, s32 len, bool owned);
virtual ~CInputStream();
2022-07-18 17:53:58 +00:00
virtual u32 Read(void* dest, u32 len) = 0;
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
template < typename T >
2022-07-31 00:38:13 +00:00
inline T Get(const TType<T>& type) {
return cinput_stream_helper(type, *this);
}
private:
2022-07-15 00:48:18 +00:00
bool GrabAnotherBlock();
bool InternalReadNext();
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) {
return in.ReadLong();
}
template <>
2022-07-31 00:38:13 +00:00
inline u32 cinput_stream_helper(const TType< u32 >& type, CInputStream& in) {
return in.ReadLong();
}
template <>
2022-09-05 04:00:04 +00:00
inline unsigned int cinput_stream_helper(const TType< unsigned int >& type, CInputStream& in) {
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();
}
// 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) {
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 >());
return result;
}
#endif