46 #ifndef AI_STREAMREADER_H_INCLUDED
47 #define AI_STREAMREADER_H_INCLUDED
50 #pragma GCC system_header
53 #include <assimp/ByteSwapper.h>
54 #include <assimp/Defines.h>
55 #include <assimp/Exceptional.h>
72 template <
bool SwapEndianess = false,
bool RuntimeSwitch = false>
103 mStream(std::shared_ptr<
IOStream>(stream)),
109 ai_assert(
nullptr != stream);
129 return Get<double>();
135 return Get<int16_t>();
141 return Get<int8_t>();
147 return Get<int32_t>();
153 return Get<int64_t>();
159 return Get<uint16_t>();
165 return Get<uint8_t>();
171 return Get<uint32_t>();
177 return Get<uint64_t>();
183 return (
unsigned int)(mEnd - mCurrent);
191 return (
unsigned int)(mLimit - mCurrent);
198 if (mCurrent > mLimit) {
217 if (mCurrent > mLimit || mCurrent < mBuffer) {
230 ::memcpy(out, ur, bytes);
235 return (
unsigned int)(mCurrent - mBuffer);
238 void SetCurrentPos(
size_t pos) {
251 if (UINT_MAX == _limit) {
256 mLimit = mBuffer + _limit;
267 return (
unsigned int)(mLimit - mBuffer);
279 template <
typename T>
287 template <
typename T>
289 if (mCurrent +
sizeof(T) > mLimit) {
294 ::memcpy(&f, mCurrent,
sizeof(T));
296 mCurrent +=
sizeof(T);
304 if (
nullptr == mStream) {
308 const size_t filesize = mStream->FileSize() - mStream->Tell();
310 throw DeadlyImportError(
"StreamReader: File is empty or EOF is already reached");
313 mCurrent = mBuffer =
new int8_t[filesize];
314 const size_t read = mStream->Read(mCurrent, 1, filesize);
316 ai_assert(read <= filesize);
317 mEnd = mLimit = &mBuffer[read - 1] + 1;
321 std::shared_ptr<IOStream> mStream;
331 #ifdef AI_BUILD_BIG_ENDIAN
332 typedef StreamReader<true> StreamReaderLE;
333 typedef StreamReader<false> StreamReaderBE;
335 typedef StreamReader<true> StreamReaderBE;
336 typedef StreamReader<false> StreamReaderLE;
341 typedef StreamReader<true, true> StreamReaderAny;
345 #endif // !! AI_STREAMREADER_H_INCLUDED
int8_t GetI1()
Definition: StreamReader.h:140
void CopyAndAdvance(void *out, size_t bytes)
Definition: StreamReader.h:226
int8_t * GetPtr() const
Definition: StreamReader.h:205
size_t GetRemainingSize() const
Get the remaining stream size (to the end of the stream)
Definition: StreamReader.h:182
float GetF4()
Read a float from the stream.
Definition: StreamReader.h:122
void IncPtr(intptr_t plus)
Definition: StreamReader.h:196
uint8_t GetU1()
Read a unsigned 8 bit integer from the stream.
Definition: StreamReader.h:164
uint64_t GetU8()
Read a unsigned 64 bit integer from the stream.
Definition: StreamReader.h:176
void SetPtr(int8_t *p)
Definition: StreamReader.h:215
Definition: StreamReader.h:73
int GetCurrentPos() const
Get the current offset from the beginning of the file.
Definition: StreamReader.h:234
uint16_t GetU2()
Definition: StreamReader.h:158
Definition: ByteSwapper.h:267
T Get()
Definition: StreamReader.h:288
double GetF8()
Read a double from the stream.
Definition: StreamReader.h:128
int64_t GetI8()
Definition: StreamReader.h:152
uint32_t GetU4()
Read an unsigned 32 bit integer from the stream.
Definition: StreamReader.h:170
Definition: Exceptional.h:72
StreamReader & operator>>(T &f)
Definition: StreamReader.h:280
int32_t GetI4()
Definition: StreamReader.h:146
unsigned int GetReadLimit() const
Definition: StreamReader.h:266
int16_t GetI2()
Definition: StreamReader.h:134
size_t GetRemainingSizeToLimit() const
Definition: StreamReader.h:190
File I/O wrappers for C++.
void SkipToReadLimit()
Definition: StreamReader.h:273
Definition: ai_assert.h:50
unsigned int SetReadLimit(unsigned int _limit)
Definition: StreamReader.h:249
CPP-API: Class to handle file I/O for C++.
Definition: IOStream.hpp:75
StreamReader(std::shared_ptr< IOStream > stream, bool le=false)
Definition: StreamReader.h:90