2022-02-18 07:37:54 +00:00
|
|
|
#pragma once
|
|
|
|
#include "Runtime/GCNTypes.hpp"
|
|
|
|
|
|
|
|
#include <array>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
namespace metaforce {
|
|
|
|
class COutputStream {
|
2022-02-22 05:53:57 +00:00
|
|
|
template <typename T>
|
|
|
|
friend void coutput_stream_helper(const T& t, COutputStream& out);
|
2022-02-18 07:37:54 +00:00
|
|
|
u32 x4_position = 0;
|
|
|
|
u32 x8_bufLen = 0;
|
|
|
|
u8* xc_ptr = nullptr;
|
|
|
|
u32 x10_numWrites = 0;
|
|
|
|
u32 x14_shiftRegister = 0;
|
|
|
|
u32 x18_shiftRegisterOffset = 32;
|
|
|
|
u8 x1c_scratch[96]{};
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void DoFlush();
|
|
|
|
void DoPut(const u8* ptr, u32 len);
|
2022-03-22 08:37:10 +00:00
|
|
|
virtual void Write(const u8* ptr, u32 len) = 0;
|
2022-02-18 07:37:54 +00:00
|
|
|
public:
|
2022-03-22 08:37:10 +00:00
|
|
|
COutputStream(s32 unk);
|
2022-02-18 07:37:54 +00:00
|
|
|
virtual ~COutputStream();
|
|
|
|
|
|
|
|
void WriteBits(u32 val, u32 bitCount);
|
|
|
|
void WriteChar(u8 c);
|
|
|
|
void WriteShort(u16 s);
|
|
|
|
void WriteLong(u32 l);
|
|
|
|
void WriteLongLong(u64 ll);
|
|
|
|
void WriteFloat(float f);
|
|
|
|
void WriteDouble(double d);
|
|
|
|
|
|
|
|
void WriteInt8(s8 c) { Put(c); }
|
|
|
|
void WriteUint8(u8 c) { Put(c); }
|
|
|
|
void WriteInt16(s16 s) { Put(s); }
|
|
|
|
void WriteUint16(u16 s) { Put(s); }
|
|
|
|
void WriteInt32(s32 l) { Put(l); }
|
|
|
|
void WriteUint32(u32 l) { Put(l); }
|
|
|
|
void WriteInt64(u64 ll) { Put(ll); }
|
|
|
|
void WriteUint64(u64 ll) { Put(ll); }
|
|
|
|
void WriteReal32(float f) { Put(f); }
|
|
|
|
void WriteReal64(double d) { Put(d); }
|
|
|
|
|
|
|
|
void FlushShiftRegister();
|
|
|
|
void Flush();
|
|
|
|
void Put(const u8* ptr, u32 len);
|
|
|
|
template <typename T>
|
|
|
|
void Put(const T& t) {
|
|
|
|
coutput_stream_helper(t, *this);
|
|
|
|
}
|
|
|
|
|
|
|
|
static u32 GetBitCount(u32 val);
|
|
|
|
};
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
void coutput_stream_helper(const T& t, COutputStream& out) {
|
|
|
|
t.PutTo(out);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const bool& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const char& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const s8& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const u8& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const s16& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const u16& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const s32& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const u32& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const s64& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const u64& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const float& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const double& t, COutputStream& out);
|
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const std::string& t, COutputStream& out);
|
2022-02-28 03:33:48 +00:00
|
|
|
template <>
|
|
|
|
void coutput_stream_helper(const std::string_view& t, COutputStream& out);
|
2022-02-22 05:53:57 +00:00
|
|
|
} // namespace metaforce
|