2022-10-09 05:13:17 +00:00
|
|
|
#ifndef _CINPUTSTREAM
|
|
|
|
#define _CINPUTSTREAM
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
#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-09-05 04:01:13 +00:00
|
|
|
CInputStream(int len);
|
|
|
|
CInputStream(const void* ptr, int len, bool owned);
|
2022-04-10 00:17:06 +00:00
|
|
|
virtual ~CInputStream();
|
2022-09-05 04:01:13 +00:00
|
|
|
virtual uint Read(void* dest, uint len) = 0;
|
2022-04-10 00:17:06 +00:00
|
|
|
|
2022-10-09 05:37:23 +00:00
|
|
|
float ReadFloat();
|
2022-07-18 17:53:58 +00:00
|
|
|
u64 ReadLongLong();
|
2022-09-05 04:01:13 +00:00
|
|
|
uint ReadLong();
|
2022-10-09 05:37:23 +00:00
|
|
|
ushort ReadShort();
|
2022-07-15 00:48:18 +00:00
|
|
|
bool ReadBool();
|
2022-10-09 05:37:23 +00:00
|
|
|
uchar ReadChar();
|
2022-09-05 04:01:13 +00:00
|
|
|
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
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
template < typename T >
|
2022-09-18 06:05:46 +00:00
|
|
|
inline T Get(const TType< T >& type) {
|
2022-07-31 00:38:13 +00:00
|
|
|
return cinput_stream_helper(type, *this);
|
2022-04-10 00:17:06 +00:00
|
|
|
}
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
bool ReadPackedBool() { return ReadBits(1) != 0; }
|
2022-10-05 16:28:37 +00:00
|
|
|
|
2022-10-09 16:34:58 +00:00
|
|
|
// TODO: this cast to uint fixes regalloc in
|
|
|
|
// CIEKeyframeEmitter / rstl::vector(CInputStream&)
|
|
|
|
// why?
|
|
|
|
int ReadInt32() { return static_cast< uint >(Get(TType< int >())); }
|
|
|
|
|
2022-04-10 00:17:06 +00:00
|
|
|
private:
|
2022-07-15 00:48:18 +00:00
|
|
|
bool GrabAnotherBlock();
|
|
|
|
bool InternalReadNext();
|
|
|
|
|
2022-09-05 04:01:13 +00:00
|
|
|
uint x4_blockOffset;
|
|
|
|
uint x8_blockLen;
|
|
|
|
uint xc_len;
|
2022-10-09 05:37:23 +00:00
|
|
|
uchar* x10_ptr;
|
2022-04-10 00:17:06 +00:00
|
|
|
bool x14_owned;
|
2022-09-05 04:01:13 +00:00
|
|
|
uint x18_readPosition;
|
|
|
|
uint x1c_bitWord;
|
|
|
|
uint x20_bitOffset;
|
2022-04-10 00:17:06 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
template <>
|
2022-09-05 04:01:13 +00:00
|
|
|
inline int cinput_stream_helper(const TType< int >& type, CInputStream& in) {
|
2022-04-10 00:17:06 +00:00
|
|
|
return in.ReadLong();
|
|
|
|
}
|
|
|
|
template <>
|
2022-09-05 04:01:13 +00:00
|
|
|
inline uint cinput_stream_helper(const TType< uint >& 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:01:13 +00:00
|
|
|
inline unsigned long cinput_stream_helper(const TType< unsigned long >& 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-10-09 16:34:58 +00:00
|
|
|
template <>
|
|
|
|
inline short cinput_stream_helper(const TType< short >& type, CInputStream& in) {
|
|
|
|
return in.ReadShort();
|
|
|
|
}
|
|
|
|
template <>
|
|
|
|
inline ushort cinput_stream_helper(const TType< ushort >& type, CInputStream& in) {
|
|
|
|
return in.ReadShort();
|
|
|
|
}
|
2022-04-10 00:17:06 +00:00
|
|
|
|
|
|
|
// rstl
|
|
|
|
#include "rstl/pair.hpp"
|
|
|
|
template < typename L, typename R >
|
2022-09-18 06:05:46 +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;
|
|
|
|
}
|
|
|
|
|
2022-10-09 16:34:58 +00:00
|
|
|
#include "rstl/vector.hpp"
|
|
|
|
template < typename T, typename A >
|
|
|
|
inline rstl::vector< T, A >::vector(CInputStream& in)
|
|
|
|
: x4_count(0), x8_capacity(0), xc_items(nullptr) {
|
|
|
|
int count = in.ReadInt32();
|
|
|
|
reserve(count);
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
push_back(in.Get(TType< T >()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-09 05:13:17 +00:00
|
|
|
#endif // _CINPUTSTREAM
|