6 #include "VectorMath.h"
18 namespace BinaryParsing
23 membuf(
char* p,
size_t n) {
27 char* getCurrent()
const
33 virtual pos_type seekoff( off_type off, std::ios_base::seekdir dir,
34 std::ios_base::openmode which = std::ios_base::in | std::ios_base::out )
38 if (dir == std::ios::cur)
40 setg(eback(), gptr() + off, egptr());
42 else if (dir == std::ios::beg)
44 setg(eback(), eback() + off, egptr());
46 else if (dir == std::ios::end)
48 setg(eback(), egptr() - off, egptr());
55 return gptr() - eback();
58 virtual pos_type seekpos( pos_type off,
59 std::ios_base::openmode which = std::ios_base::in | std::ios_base::out )
61 return seekoff(off, std::ios::beg, which);
66 bool StreamIsAligned(std::istream& stream,
int alignment,
bool alignedReads);
68 void AlignStream(std::istream& reader,
int alignment,
bool alignedReads);
73 T ParseT(std::istream& reader,
bool alignedReads)
75 AlignStream(reader,
sizeof(T), alignedReads);
77 reader.read((
char*)&result,
sizeof(T));
82 inline Eegeo::v2 ParseT<Eegeo::v2>(std::istream& reader,
bool alignedReads)
84 AlignStream(reader,
sizeof(
float), alignedReads);
86 reader.read((
char*)&result,
sizeof(
Eegeo::v2));
91 inline Eegeo::v3 ParseT<Eegeo::v3>(std::istream& reader,
bool alignedReads)
93 AlignStream(reader,
sizeof(
float), alignedReads);
95 reader.read((
char*)&result,
sizeof(
Eegeo::v3));
100 inline Eegeo::v4 ParseT<Eegeo::v4>(std::istream& reader,
bool alignedReads)
102 AlignStream(reader,
sizeof(
float), alignedReads);
104 reader.read((
char*)&result,
sizeof(
Eegeo::v4));
109 inline Eegeo::m44 ParseT<Eegeo::m44>(std::istream& reader,
bool alignedReads)
111 AlignStream(reader,
sizeof(
float), alignedReads);
113 reader.read((
char*)&result,
sizeof(
Eegeo::m44));
120 AlignStream(reader,
sizeof(
double), alignedReads);
133 T Parse(std::istream& reader,
size_t *parseSize)
const
135 AlignStream(reader,
sizeof(T));
137 reader.read((
char*)&result,
sizeof(T));
139 *parseSize +=
sizeof(T);
145 T Parse(std::istream& reader)
const
147 return ParseT<T>(reader, m_alignedReads);
150 template <
class T,
size_t N>
151 void Parse(std::istream& reader, T (&result)[N])
const
153 AlignStream(reader,
sizeof(T));
154 reader.read((
char*)&result,
sizeof(T) * N);
158 void ParseShortString(std::istream& reader, std::string& outputString)
const
160 size_t length = Parse<T>(reader);
162 AlignStream(reader,
sizeof(
char));
163 outputString.resize(length);
164 reader.read((
char*)&outputString[0], length *
sizeof(
char));
167 std::string ParseFourCC(std::istream& reader)
const;
169 u32 Read7BitEncodedInt(std::istream& reader)
const;
170 std::string ParseString(std::istream& reader)
const;
171 std::vector<std::string> ParseStringArray(std::istream& reader)
const;
173 bool StreamIsAligned(std::istream& stream,
int alignment)
const
175 return BinaryParsing::StreamIsAligned(stream, alignment, m_alignedReads);
178 void AlignStream(std::istream& stream,
int alignment)
const
180 BinaryParsing::AlignStream(stream, alignment, m_alignedReads);