2022-10-09 01:13:17 -04:00
|
|
|
#ifndef _CINPUTSTREAM
|
|
|
|
|
#define _CINPUTSTREAM
|
2022-04-09 20:17:06 -04:00
|
|
|
|
|
|
|
|
#include "types.h"
|
|
|
|
|
|
2022-10-20 21:32:04 -04:00
|
|
|
#include "stddef.h"
|
|
|
|
|
|
2022-04-09 20:17:06 -04:00
|
|
|
class CInputStream;
|
|
|
|
|
template < typename T >
|
|
|
|
|
struct TType {};
|
|
|
|
|
template < typename T >
|
2022-10-14 22:22:32 -07:00
|
|
|
T cinput_stream_helper(const TType< T >& type, CInputStream& in);
|
2022-04-09 20:17:06 -04:00
|
|
|
|
2023-01-07 18:11:54 -08:00
|
|
|
template < typename T >
|
2025-05-23 03:05:25 -07:00
|
|
|
inline TType< T > TGetType(const T&) {
|
2023-01-07 18:11:54 -08:00
|
|
|
return TType< T >();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-09 20:17:06 -04:00
|
|
|
class CInputStream {
|
|
|
|
|
public:
|
2022-09-05 00:01:13 -04:00
|
|
|
CInputStream(int len);
|
|
|
|
|
CInputStream(const void* ptr, int len, bool owned);
|
2022-04-09 20:17:06 -04:00
|
|
|
virtual ~CInputStream();
|
2022-10-12 23:09:15 -07:00
|
|
|
virtual size_t Read(void* dest, size_t len) = 0;
|
2022-04-09 20:17:06 -04:00
|
|
|
|
2022-10-09 01:37:23 -04:00
|
|
|
float ReadFloat();
|
2022-07-18 13:53:58 -04:00
|
|
|
u64 ReadLongLong();
|
2022-09-05 00:01:13 -04:00
|
|
|
uint ReadLong();
|
2022-10-09 01:37:23 -04:00
|
|
|
ushort ReadShort();
|
2022-07-14 20:48:18 -04:00
|
|
|
bool ReadBool();
|
2026-01-07 11:01:50 -08:00
|
|
|
char ReadChar();
|
2022-09-05 00:01:13 -04:00
|
|
|
uint ReadBits(uint len);
|
2022-10-12 23:09:15 -07:00
|
|
|
size_t ReadBytes(void* dest, size_t len);
|
2022-07-14 20:48:18 -04:00
|
|
|
void Get(void* dest, unsigned long len);
|
2022-07-18 13:53:58 -04:00
|
|
|
|
2022-04-09 20:17:06 -04:00
|
|
|
template < typename T >
|
2026-01-20 13:41:07 -08:00
|
|
|
T Get(const TType< T >& type = TType< T >()) {
|
2025-05-23 03:05:25 -07:00
|
|
|
return cinput_stream_helper(TType< T >(), *this);
|
2022-04-09 20:17:06 -04:00
|
|
|
}
|
|
|
|
|
|
2022-10-09 01:13:17 -04:00
|
|
|
bool ReadPackedBool() { return ReadBits(1) != 0; }
|
2022-10-05 09:28:37 -07:00
|
|
|
|
2023-10-17 17:36:08 -04:00
|
|
|
int ReadInt32() { return Get< int >(); }
|
|
|
|
|
ushort ReadUint16() { return Get< ushort >(); }
|
|
|
|
|
short ReadInt16() { return Get< short >(); }
|
2022-10-09 12:34:58 -04:00
|
|
|
|
2022-10-22 20:02:37 -07:00
|
|
|
uint GetBlockOffset() const { return x4_blockOffset; }
|
2023-10-19 21:15:38 -07:00
|
|
|
const uint GetReadPosition() const { return x18_readPosition; }
|
2022-10-22 20:02:37 -07:00
|
|
|
|
2022-04-09 20:17:06 -04:00
|
|
|
private:
|
2022-07-14 20:48:18 -04:00
|
|
|
bool GrabAnotherBlock();
|
|
|
|
|
bool InternalReadNext();
|
|
|
|
|
|
2022-09-05 00:01:13 -04:00
|
|
|
uint x4_blockOffset;
|
|
|
|
|
uint x8_blockLen;
|
|
|
|
|
uint xc_len;
|
2022-10-09 01:37:23 -04:00
|
|
|
uchar* x10_ptr;
|
2022-04-09 20:17:06 -04:00
|
|
|
bool x14_owned;
|
2022-09-05 00:01:13 -04:00
|
|
|
uint x18_readPosition;
|
|
|
|
|
uint x1c_bitWord;
|
|
|
|
|
uint x20_bitOffset;
|
2022-04-09 20:17:06 -04:00
|
|
|
};
|
|
|
|
|
|
2023-01-07 18:11:54 -08:00
|
|
|
template < typename T >
|
|
|
|
|
inline T cinput_stream_helper(const TType< T >& type, CInputStream& in) {
|
2022-10-14 22:22:32 -07:00
|
|
|
return T(in);
|
|
|
|
|
}
|
2022-10-15 19:09:59 +03:00
|
|
|
template <>
|
|
|
|
|
inline bool cinput_stream_helper(const TType< bool >& type, CInputStream& in) {
|
|
|
|
|
return in.ReadBool();
|
|
|
|
|
}
|
2022-10-22 21:49:41 -07:00
|
|
|
template <>
|
|
|
|
|
inline char cinput_stream_helper(const TType< char >& type, CInputStream& in) {
|
|
|
|
|
return in.ReadChar();
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-23 17:15:06 -07:00
|
|
|
template <>
|
|
|
|
|
inline unsigned char cinput_stream_helper(const TType< unsigned char >& type, CInputStream& in) {
|
|
|
|
|
return in.ReadChar();
|
|
|
|
|
}
|
|
|
|
|
|
2022-04-09 20:17:06 -04:00
|
|
|
template <>
|
2022-09-05 00:01:13 -04:00
|
|
|
inline int cinput_stream_helper(const TType< int >& type, CInputStream& in) {
|
2022-04-09 20:17:06 -04:00
|
|
|
return in.ReadLong();
|
|
|
|
|
}
|
|
|
|
|
template <>
|
2022-09-05 00:01:13 -04:00
|
|
|
inline uint cinput_stream_helper(const TType< uint >& type, CInputStream& in) {
|
2022-04-09 20:17:06 -04:00
|
|
|
return in.ReadLong();
|
|
|
|
|
}
|
2022-07-14 12:24:26 -04:00
|
|
|
template <>
|
2022-09-05 00:01:13 -04:00
|
|
|
inline unsigned long cinput_stream_helper(const TType< unsigned long >& type, CInputStream& in) {
|
2022-07-14 12:24:26 -04:00
|
|
|
return in.ReadLong();
|
|
|
|
|
}
|
2022-07-30 17:38:13 -07:00
|
|
|
template <>
|
|
|
|
|
inline float cinput_stream_helper(const TType< float >& type, CInputStream& in) {
|
|
|
|
|
return in.ReadFloat();
|
|
|
|
|
}
|
2022-10-09 12:34:58 -04: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-09 20:17:06 -04:00
|
|
|
|
|
|
|
|
// rstl
|
|
|
|
|
#include "rstl/pair.hpp"
|
|
|
|
|
template < typename L, typename R >
|
2026-01-30 10:02:47 -08:00
|
|
|
inline rstl::pair< L, R >::pair(CInputStream& in)
|
|
|
|
|
: first(in.Get< L >()), second(in.Get< R >()) {}
|
2022-04-09 20:17:06 -04:00
|
|
|
|
2022-10-09 12:34:58 -04:00
|
|
|
#include "rstl/vector.hpp"
|
2022-10-14 22:22:32 -07:00
|
|
|
template < typename T, typename Alloc >
|
|
|
|
|
inline rstl::vector< T, Alloc >::vector(CInputStream& in, const Alloc& allocator)
|
2022-10-09 12:34:58 -04:00
|
|
|
: x4_count(0), x8_capacity(0), xc_items(nullptr) {
|
2025-05-23 03:05:25 -07:00
|
|
|
int count = in.Get(TGetType(0));
|
2022-10-09 12:34:58 -04:00
|
|
|
reserve(count);
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
2026-01-30 10:02:47 -08:00
|
|
|
push_back(in.Get< T >());
|
2022-10-09 12:34:58 -04:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-20 15:45:54 +03:00
|
|
|
#include "rstl/reserved_vector.hpp"
|
|
|
|
|
template < typename T, int N >
|
2023-01-07 18:11:54 -08:00
|
|
|
inline rstl::reserved_vector< T, N >::reserved_vector(CInputStream& in) : x0_count(in.ReadInt32()) {
|
2022-10-20 15:45:54 +03:00
|
|
|
for (int i = 0; i < x0_count; i++) {
|
|
|
|
|
construct(&data()[i], in.Get(TType< T >()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-09 01:13:17 -04:00
|
|
|
#endif // _CINPUTSTREAM
|