1 #ifndef ISTREAMREADER_HPP 2 #define ISTREAMREADER_HPP 28 virtual void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current)=0;
59 virtual atUint64
length()
const=0;
67 inline atInt8 readVal(
typename std::enable_if<std::is_same<T, atInt8>::value>::type* = 0)
70 inline atInt8 readValLittle(
typename std::enable_if<std::is_same<T, atInt8>::value>::type* = 0)
73 inline atInt8 readValBig(
typename std::enable_if<std::is_same<T, atInt8>::value>::type* = 0)
82 inline atUint8 readVal(
typename std::enable_if<std::is_same<T, atUint8>::value>::type* = 0)
85 inline atUint8 readValLittle(
typename std::enable_if<std::is_same<T, atUint8>::value>::type* = 0)
88 inline atUint8 readValBig(
typename std::enable_if<std::is_same<T, atUint8>::value>::type* = 0)
97 atInt8* buf =
new atInt8[
length];
99 return std::unique_ptr<atInt8[]>(buf);
108 atUint8* buf =
new atUint8[
length];
110 return std::unique_ptr<atUint8[]>(buf);
138 return m_endian == BigEndian ? utility::BigInt16(val) : utility::LittleInt16(val);
141 inline atInt16 readVal(
typename std::enable_if<std::is_same<T, atInt16>::value>::type* = 0)
153 return utility::LittleInt16(val);
156 inline atInt16 readValLittle(
typename std::enable_if<std::is_same<T, atInt16>::value>::type* = 0)
168 return utility::BigInt16(val);
171 inline atInt16 readValBig(
typename std::enable_if<std::is_same<T, atInt16>::value>::type* = 0)
182 inline atUint16 readVal(
typename std::enable_if<std::is_same<T, atUint16>::value>::type* = 0)
194 return utility::LittleUint16(val);
197 inline atUint16 readValLittle(
typename std::enable_if<std::is_same<T, atUint16>::value>::type* = 0)
209 return utility::BigUint16(val);
212 inline atUint16 readValBig(
typename std::enable_if<std::is_same<T, atUint16>::value>::type* = 0)
224 return m_endian == BigEndian ? utility::BigInt32(val) : utility::LittleInt32(val);
227 inline atInt32 readVal(
typename std::enable_if<std::is_same<T, atInt32>::value>::type* = 0)
239 return utility::LittleInt32(val);
242 inline atInt32 readValLittle(
typename std::enable_if<std::is_same<T, atInt32>::value>::type* = 0)
254 return utility::BigInt32(val);
257 inline atInt32 readValBig(
typename std::enable_if<std::is_same<T, atInt32>::value>::type* = 0)
268 inline atUint32 readVal(
typename std::enable_if<std::is_same<T, atUint32>::value>::type* = 0)
280 return utility::LittleUint32(val);
283 inline atInt32 readValLittle(
typename std::enable_if<std::is_same<T, atUint32>::value>::type* = 0)
295 return utility::BigUint32(val);
298 inline atUint32 readValBig(
typename std::enable_if<std::is_same<T, atUint32>::value>::type* = 0)
310 return m_endian == BigEndian ? utility::BigInt64(val) : utility::LittleInt64(val);
313 inline atInt64 readVal(
typename std::enable_if<std::is_same<T, atInt64>::value>::type* = 0)
325 return utility::LittleInt64(val);
328 inline atInt64 readValLittle(
typename std::enable_if<std::is_same<T, atInt64>::value>::type* = 0)
340 return utility::BigInt64(val);
343 inline atInt64 readValBig(
typename std::enable_if<std::is_same<T, atInt64>::value>::type* = 0)
354 inline atUint64 readVal(
typename std::enable_if<std::is_same<T, atUint64>::value>::type* = 0)
366 return utility::LittleUint64(val);
369 inline atUint64 readValLittle(
typename std::enable_if<std::is_same<T, atUint64>::value>::type* = 0)
381 return utility::BigUint64(val);
384 inline atUint64 readValBig(
typename std::enable_if<std::is_same<T, atUint64>::value>::type* = 0)
396 return m_endian == BigEndian ? utility::BigFloat(val) : utility::LittleFloat(val);
399 inline float readVal(
typename std::enable_if<std::is_same<T, float>::value>::type* = 0)
411 return utility::LittleFloat(val);
414 inline float readValLittle(
typename std::enable_if<std::is_same<T, float>::value>::type* = 0)
426 return utility::BigFloat(val);
429 inline float readValBig(
typename std::enable_if<std::is_same<T, float>::value>::type* = 0)
441 return m_endian == BigEndian ? utility::BigDouble(val) : utility::LittleDouble(val);
444 inline double readVal(
typename std::enable_if<std::is_same<T, double>::value>::type* = 0)
456 return utility::LittleDouble(val);
459 inline double readValLittle(
typename std::enable_if<std::is_same<T, double>::value>::type* = 0)
471 return utility::BigDouble(val);
474 inline double readValBig(
typename std::enable_if<std::is_same<T, double>::value>::type* = 0)
488 inline bool readVal(
typename std::enable_if<std::is_same<T, bool>::value>::type* = 0)
491 inline bool readValLittle(
typename std::enable_if<std::is_same<T, bool>::value>::type* = 0)
494 inline bool readValBig(
typename std::enable_if<std::is_same<T, bool>::value>::type* = 0)
506 if (m_endian == BigEndian)
508 utility::BigFloat(val.vec[0]);
509 utility::BigFloat(val.vec[1]);
513 utility::LittleFloat(val.vec[0]);
514 utility::LittleFloat(val.vec[1]);
519 inline atVec2f readVal(
typename std::enable_if<std::is_same<T, atVec2f>::value>::type* = 0)
531 utility::LittleFloat(val.vec[0]);
532 utility::LittleFloat(val.vec[1]);
536 inline atVec2f readValLittle(
typename std::enable_if<std::is_same<T, atVec2f>::value>::type* = 0)
548 utility::BigFloat(val.vec[0]);
549 utility::BigFloat(val.vec[1]);
553 inline atVec2f readValBig(
typename std::enable_if<std::is_same<T, atVec2f>::value>::type* = 0)
565 if (m_endian == BigEndian)
567 utility::BigFloat(val.vec[0]);
568 utility::BigFloat(val.vec[1]);
569 utility::BigFloat(val.vec[2]);
573 utility::LittleFloat(val.vec[0]);
574 utility::LittleFloat(val.vec[1]);
575 utility::LittleFloat(val.vec[2]);
580 inline atVec3f readVal(
typename std::enable_if<std::is_same<T, atVec3f>::value>::type* = 0)
592 utility::LittleFloat(val.vec[0]);
593 utility::LittleFloat(val.vec[1]);
594 utility::LittleFloat(val.vec[2]);
598 inline atVec3f readValLittle(
typename std::enable_if<std::is_same<T, atVec3f>::value>::type* = 0)
610 utility::BigFloat(val.vec[0]);
611 utility::BigFloat(val.vec[1]);
612 utility::BigFloat(val.vec[2]);
616 inline atVec3f readValBig(
typename std::enable_if<std::is_same<T, atVec3f>::value>::type* = 0)
628 if (m_endian == BigEndian)
630 utility::BigFloat(val.vec[0]);
631 utility::BigFloat(val.vec[1]);
632 utility::BigFloat(val.vec[2]);
633 utility::BigFloat(val.vec[3]);
637 utility::LittleFloat(val.vec[0]);
638 utility::LittleFloat(val.vec[1]);
639 utility::LittleFloat(val.vec[2]);
640 utility::LittleFloat(val.vec[3]);
645 inline atVec4f readVal(
typename std::enable_if<std::is_same<T, atVec4f>::value>::type* = 0)
657 utility::LittleFloat(val.vec[0]);
658 utility::LittleFloat(val.vec[1]);
659 utility::LittleFloat(val.vec[2]);
660 utility::LittleFloat(val.vec[3]);
664 inline atVec4f readValLittle(
typename std::enable_if<std::is_same<T, atVec4f>::value>::type* = 0)
676 utility::BigFloat(val.vec[0]);
677 utility::BigFloat(val.vec[1]);
678 utility::BigFloat(val.vec[2]);
679 utility::BigFloat(val.vec[3]);
683 inline atVec4f readValBig(
typename std::enable_if<std::is_same<T, atVec4f>::value>::type* = 0)
695 if (m_endian == BigEndian)
697 utility::BigDouble(val.vec[0]);
698 utility::BigDouble(val.vec[1]);
702 utility::LittleDouble(val.vec[0]);
703 utility::LittleDouble(val.vec[1]);
708 inline atVec2d readVal(
typename std::enable_if<std::is_same<T, atVec2d>::value>::type* = 0)
720 utility::LittleDouble(val.vec[0]);
721 utility::LittleDouble(val.vec[1]);
725 inline atVec2d readValLittle(
typename std::enable_if<std::is_same<T, atVec2d>::value>::type* = 0)
737 utility::BigDouble(val.vec[0]);
738 utility::BigDouble(val.vec[1]);
742 inline atVec2d readValBig(
typename std::enable_if<std::is_same<T, atVec2d>::value>::type* = 0)
754 if (m_endian == BigEndian)
756 utility::BigDouble(val.vec[0]);
757 utility::BigDouble(val.vec[1]);
758 utility::BigDouble(val.vec[2]);
762 utility::LittleDouble(val.vec[0]);
763 utility::LittleDouble(val.vec[1]);
764 utility::LittleDouble(val.vec[2]);
769 inline atVec3d readVal(
typename std::enable_if<std::is_same<T, atVec3d>::value>::type* = 0)
781 utility::LittleDouble(val.vec[0]);
782 utility::LittleDouble(val.vec[1]);
783 utility::LittleDouble(val.vec[2]);
787 inline atVec3d readValLittle(
typename std::enable_if<std::is_same<T, atVec3d>::value>::type* = 0)
799 utility::BigDouble(val.vec[0]);
800 utility::BigDouble(val.vec[1]);
801 utility::BigDouble(val.vec[2]);
805 inline atVec3d readValBig(
typename std::enable_if<std::is_same<T, atVec3d>::value>::type* = 0)
817 if (m_endian == BigEndian)
819 utility::BigDouble(val.vec[0]);
820 utility::BigDouble(val.vec[1]);
821 utility::BigDouble(val.vec[2]);
822 utility::BigDouble(val.vec[3]);
826 utility::LittleDouble(val.vec[0]);
827 utility::LittleDouble(val.vec[1]);
828 utility::LittleDouble(val.vec[2]);
829 utility::LittleDouble(val.vec[3]);
834 inline atVec4d readVal(
typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0)
846 utility::LittleDouble(val.vec[0]);
847 utility::LittleDouble(val.vec[1]);
848 utility::LittleDouble(val.vec[2]);
849 utility::LittleDouble(val.vec[3]);
853 inline atVec4d readValLittle(
typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0)
865 utility::BigDouble(val.vec[0]);
866 utility::BigDouble(val.vec[1]);
867 utility::BigDouble(val.vec[2]);
868 utility::BigDouble(val.vec[3]);
872 inline atVec4d readValBig(
typename std::enable_if<std::is_same<T, atVec4d>::value>::type* = 0)
884 return std::string();
892 if (fixedLen >= 0 && i >= fixedLen - 1)
898 utf8proc_uint8_t mb[4];
899 utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(chr), mb);
902 atWarning(
"invalid UTF-8 character while encoding");
906 retval.append(reinterpret_cast<char*>(mb), c);
910 if (fixedLen >= 0 && i < fixedLen)
925 return std::string();
933 if (fixedLen >= 0 && i >= fixedLen - 1)
939 utf8proc_uint8_t mb[4];
940 utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(chr), mb);
943 atWarning(
"invalid UTF-8 character while encoding");
947 retval.append(reinterpret_cast<char*>(mb), c);
951 if (fixedLen >= 0 && i < fixedLen)
966 return std::string();
974 if (fixedLen >= 0 && i >= fixedLen - 1)
980 utf8proc_uint8_t mb[4];
981 utf8proc_ssize_t c = utf8proc_encode_char(utf8proc_int32_t(chr), mb);
984 atWarning(
"invalid UTF-8 character while encoding");
988 retval.append(reinterpret_cast<char*>(mb), c);
992 if (fixedLen >= 0 && i < fixedLen)
1006 return std::string();
1011 for (i = 1 ; chr != 0 ; ++i)
1015 if (fixedLen >= 0 && i >= fixedLen)
1021 if (fixedLen >= 0 && i < fixedLen)
1027 inline std::string readVal(
typename std::enable_if<std::is_same<T, std::string>::value>::type* = 0)
1038 return std::wstring();
1044 for (i = 1 ; chr != 0 ; ++i)
1048 if (fixedLen >= 0 && i >= fixedLen)
1054 if (fixedLen >= 0 && i < fixedLen)
1060 inline std::wstring readVal(
typename std::enable_if<std::is_same<T, std::wstring>::value>::type* = 0)
1072 return std::wstring();
1078 for (i = 1 ; chr != 0 ; ++i)
1082 if (fixedLen >= 0 && i >= fixedLen)
1088 if (fixedLen >= 0 && i < fixedLen)
1094 inline std::wstring readValLittle(
typename std::enable_if<std::is_same<T, std::wstring>::value>::type* = 0)
1106 return std::wstring();
1111 for (i = 1 ; chr != 0 ; ++i)
1115 if (fixedLen >= 0 && i >= fixedLen)
1121 if (fixedLen >= 0 && i < fixedLen)
1127 inline std::wstring readValBig(
typename std::enable_if<std::is_same<T, std::wstring>::value>::type* = 0)
1139 typename std::enable_if<std::is_arithmetic<T>::value ||
1140 std::is_same<T, atVec2f>::value ||
1141 std::is_same<T, atVec3f>::value ||
1142 std::is_same<T, atVec4f>::value>::type* = 0)
1145 vector.reserve(count);
1146 for (
size_t i=0 ; i<count ; ++i)
1147 vector.push_back(readVal<T>());
1159 typename std::enable_if<std::is_arithmetic<T>::value ||
1160 std::is_same<T, atVec2f>::value ||
1161 std::is_same<T, atVec3f>::value ||
1162 std::is_same<T, atVec4f>::value>::type* = 0)
1165 vector.reserve(count);
1166 for (
size_t i=0 ; i<count ; ++i)
1167 vector.push_back(readValLittle<T>());
1179 typename std::enable_if<std::is_arithmetic<T>::value ||
1180 std::is_same<T, atVec2f>::value ||
1181 std::is_same<T, atVec3f>::value ||
1182 std::is_same<T, atVec4f>::value>::type* = 0)
1185 vector.reserve(count);
1186 for (
size_t i=0 ; i<count ; ++i)
1187 vector.push_back(readValBig<T>());
1197 typename std::enable_if<!std::is_arithmetic<T>::value &&
1198 !std::is_same<T, atVec2f>::value &&
1199 !std::is_same<T, atVec3f>::value &&
1200 !std::is_same<T, atVec4f>::value>::type* = 0)
1203 vector.reserve(count);
1204 for (
size_t i=0 ; i<count ; ++i)
1206 vector.emplace_back();
1207 vector.back().read(*
this);
1222 vector.reserve(count);
1223 for (
size_t i=0 ; i<count ; ++i)
1225 vector.emplace_back();
1226 readf(*
this, vector.back());
1230 template <
typename T>
1233 rhs = lhs.readVal<T>();
1238 #endif // ISTREAMREADER atUint8 readUByte()
Reads a byte at the current position and advances the current position.
void seekAlign32()
Sets the buffers position relative to the next 32-byte aligned position.
atInt32 readInt32()
Reads a Int32 and swaps to endianness specified by setEndian depending on platform and advances the c...
atInt8 readByte()
Reads a byte at the current position and advances the current position.
std::unique_ptr< atInt8[]> readBytes(atUint64 length)
Reads a byte at the current position and advances the current position.
std::string readWStringAsString(atInt32 fixedLen=-1)
Reads a wide-char string (using endianness from setEndian), converts to UTF8 and advances the positio...
std::wstring readWString(atInt32 fixedLen=-1)
Reads a wstring and advances the position in the file.
atVec3f readVec3fBig()
Reads an atVec3f (12 bytes), swaps against big endianness depending on platform and advances the curr...
double readDoubleBig()
Reads a double and swaps against big endianness depending on platform and advances the current positi...
atUint32 readUint32Little()
Reads a Uint32 and swaps against little endianness depending on platform and advances the current pos...
atVec2d readVec2d()
Reads an atVec2d (16 bytes), swaps to endianness specified by setEndian depending on platform and adv...
atVec4f readVec4fLittle()
Reads an atVec4f (16 bytes), swaps against little endianness depending on platform and advances the c...
void enumerate(std::vector< T > &vector, size_t count, std::function< void(IStreamReader &, T &)> readf)
Performs lambda-assisted std::vector enumeration reads using type T.
atInt32 readInt32Big()
Reads a Int32 and swaps against big endianness depending on platform and advances the current positio...
atInt64 readInt64Little()
Reads a Int64 and swaps against little endianness depending on platform and advances the current posi...
atVec3f readVec3f()
Reads an atVec3f (12 bytes), swaps to endianness specified by setEndian depending on platform and adv...
The IStreamReader class defines a basic API for reading from streams, Implementors are provided with ...
atVec4d readVec4dBig()
Reads an atVec4d (32 bytes), swaps against big endianness depending on platform and advances the curr...
std::wstring readWStringLittle(atInt32 fixedLen=-1)
Reads a wstring assuming little-endian characters and advances the position in the file...
float readFloatBig()
Reads a float and swaps against big endianness depending on platform and advances the current positio...
atVec3d readVec3dBig()
Reads an atVec3d (24 bytes), swaps against big endianness depending on platform and advances the curr...
atVec2d readVec2dBig()
Reads an atVec2d (16 bytes), swaps against big endianness depending on platform and advances the curr...
atVec2f readVec2fLittle()
Reads an atVec2f (8 bytes), swaps against little endianness depending on platform and advances the cu...
float readFloat()
Reads a float and swaps to endianness specified by setEndian depending on platform and advances the c...
std::string readWStringAsStringBig(atInt32 fixedLen=-1)
Reads a wide-char string (against big-endian), converts to UTF8 and advances the position in the file...
atUint16 readUint16Big()
Reads a Uint16 and swaps against big endianness depending on platform and advances the current positi...
atInt16 readInt16Little()
Reads a Int16 and swaps against little endianness depending on platform and advances the current posi...
atUint64 readUint64()
Reads a Uint64 and swaps to endianness specified by setEndian depending on platform and advances the ...
atInt64 readInt64()
Reads a Int64 and swaps to endianness specified by setEndian depending on platform and advances the c...
std::string readString(atInt32 fixedLen=-1)
Reads a string and advances the position in the file.
std::wstring readWStringBig(atInt32 fixedLen=-1)
Reads a wstring assuming big-endian characters and advances the position in the file.
atInt16 readInt16()
Reads a Int16 and swaps to endianness specified by setEndian depending on platform and advances the c...
virtual atUint64 position() const =0
Returns the current position in the stream.
atVec4d readVec4d()
Reads an atVec4d (32 bytes), swaps to endianness specified by setEndian depending on platform and adv...
atUint16 readUint16Little()
Reads a Uint16 and swaps against little endianness depending on platform and advances the current pos...
atVec3d readVec3dLittle()
Reads an atVec3d (24 bytes), swaps against little endianness depending on platform and advances the c...
virtual void seek(atInt64 pos, SeekOrigin origin=SeekOrigin::Current)=0
Sets the buffers position relative to the specified position. It seeks relative to the current posit...
atVec4f readVec4f()
Reads an atVec4f (16 bytes), swaps to endianness specified by setEndian depending on platform and adv...
atUint32 readUint32Big()
Reads a Uint32 and swaps against big endianness depending on platform and advances the current positi...
atVec4d readVec4dLittle()
Reads an atVec4d (32 bytes), swaps against little endianness depending on platform and advances the c...
std::unique_ptr< atUint8[]> readUBytes(atUint64 length)
Reads a byte at the current position and advances the current position.
void enumerateBig(std::vector< T > &vector, size_t count, typename std::enable_if< std::is_arithmetic< T >::value||std::is_same< T, atVec2f >::value||std::is_same< T, atVec3f >::value||std::is_same< T, atVec4f >::value >::type *=0)
Performs automatic std::vector enumeration reads using numeric type T.
atVec3f readVec3fLittle()
Reads an atVec3f (12 bytes), swaps against little endianness depending on platform and advances the c...
atUint64 readUint64Big()
Reads a Uint64 and swaps against big endianness depending on platform and advances the current positi...
void seekAlign64()
Sets the buffer's position relative to the next 64-byte aligned position.
atVec3d readVec3d()
Reads an atVec3d (24 bytes), swaps to endianness specified by setEndian depending on platform and adv...
bool readBool()
Reads a bool and advances the current position.
atUint64 readUint64Little()
Reads a Uint64 and swaps against little endianness depending on platform and advances the current pos...
atUint64 readBytesToBuf(void *buf, atUint64 len)
Attempts to read a fixed length of data into a pre-allocated buffer.
atInt32 readInt32Little()
Reads a Int32 and swaps against little endianness depending on platform and advances the current posi...
void enumerateLittle(std::vector< T > &vector, size_t count, typename std::enable_if< std::is_arithmetic< T >::value||std::is_same< T, atVec2f >::value||std::is_same< T, atVec3f >::value||std::is_same< T, atVec4f >::value >::type *=0)
Performs automatic std::vector enumeration reads using numeric type T.
std::string readWStringAsStringLittle(atInt32 fixedLen=-1)
Reads a wide-char string (against little-endian), converts to UTF8 and advances the position in the f...
atInt16 readInt16Big()
Reads a Int16 and swaps against big endianness depending on platform and advances the current positio...
virtual atUint64 length() const =0
Returns the length of the file.
atUint32 readUint32()
Reads a Uint32 and swaps to endianness specified by setEndian depending on platform and advances the ...
atVec2f readVec2fBig()
Reads an atVec2f (8 bytes), swaps against big endianness depending on platform and advances the curre...
void enumerate(std::vector< T > &vector, size_t count, typename std::enable_if< std::is_arithmetic< T >::value||std::is_same< T, atVec2f >::value||std::is_same< T, atVec3f >::value||std::is_same< T, atVec4f >::value >::type *=0)
Performs automatic std::vector enumeration reads using numeric type T.
bool atEnd() const
Returns whether or not the stream is at the end.
void enumerate(std::vector< T > &vector, size_t count, typename std::enable_if<!std::is_arithmetic< T >::value &&!std::is_same< T, atVec2f >::value &&!std::is_same< T, atVec3f >::value &&!std::is_same< T, atVec4f >::value >::type *=0)
Performs automatic std::vector enumeration reads using non-numeric type T.
atVec4f readVec4fBig()
Reads an atVec4f (16 bytes), swaps against big endianness depending on platform and advances the curr...
atVec2d readVec2dLittle()
Reads an atVec2d (16 bytes), swaps against little endianness depending on platform and advances the c...
atInt64 readInt64Big()
Reads a Int64 and swaps against big endianness depending on platform and advances the current positio...
float readFloatLittle()
Reads a float and swaps against little endianness depending on platform and advances the current posi...
double readDouble()
Reads a double and swaps to endianness specified by setEndian depending on platform and advances the ...
atUint16 readUint16()
Reads a Uint16 and swaps to endianness specified by setEndian depending on platform and advances the ...
void seekAlign16()
Sets the buffer's position relative to the next 16-byte aligned position.
virtual atUint64 readUBytesToBuf(void *buf, atUint64 len)=0
Attempts to read a fixed length of data into a pre-allocated buffer, this function is client defined ...
atVec2f readVec2f()
Reads an atVec2f (8 bytes), swaps to endianness specified by setEndian depending on platform and adva...
double readDoubleLittle()
Reads a double and swaps against little endianness depending on platform and advances the current pos...