prime/include/Kyoto/Streams/CInputStream.hpp

76 lines
1.8 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(int len);
CInputStream(const void* ptr, int len, bool owned);
virtual ~CInputStream();
virtual uint Read(void* dest, uint len) = 0;
2022-07-15 00:48:18 +00:00
f32 ReadFloat();
2022-07-18 17:53:58 +00:00
u64 ReadLongLong();
uint ReadLong();
2022-07-18 17:53:58 +00:00
u16 ReadShort();
2022-07-15 00:48:18 +00:00
bool ReadBool();
2022-07-18 17:53:58 +00:00
u8 ReadChar();
uint ReadBits(uint len);
uint 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();
uint x4_blockOffset;
uint x8_blockLen;
uint xc_len;
u8* x10_ptr;
bool x14_owned;
uint x18_readPosition;
uint x1c_bitWord;
uint x20_bitOffset;
};
template <>
inline int cinput_stream_helper(const TType< int >& type, CInputStream& in) {
return in.ReadLong();
}
template <>
inline uint cinput_stream_helper(const TType< uint >& type, CInputStream& in) {
return in.ReadLong();
}
template <>
inline unsigned long cinput_stream_helper(const TType< unsigned long >& 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