1 #ifndef ISTREAMWRITER_HPP 2 #define ISTREAMWRITER_HPP 21 virtual void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current)=0;
43 virtual atUint64
length()
const=0;
49 inline void writeVal(atUint8 val) {
writeUByte(val);}
50 inline void writeValLittle(atUint8 val) {
writeUByte(val);}
51 inline void writeValBig(atUint8 val) {
writeUByte(val);}
57 inline void writeVal(atInt8 val) {
writeByte(val);}
58 inline void writeValLittle(atInt8 val) {
writeByte(val);}
59 inline void writeValBig(atInt8 val) {
writeByte(val);}
67 virtual void writeUBytes(
const atUint8* data, atUint64 len)=0;
84 if (m_endian == BigEndian)
85 utility::BigInt16(val);
87 utility::LittleInt16(val);
90 inline void writeVal(atInt16 val) {
writeInt16(val);}
99 utility::LittleInt16(val);
111 utility::BigInt16(val);
122 inline void writeVal(atUint16 val) {
writeUint16(val);}
147 if (m_endian == BigEndian)
148 utility::BigInt32(val);
150 utility::LittleInt32(val);
153 inline void writeVal(atInt32 val) {
writeInt32(val);}
162 utility::LittleInt32(val);
174 utility::BigInt32(val);
185 inline void writeVal(atUint32 val) {
writeUint32(val);}
210 if (m_endian == BigEndian)
211 utility::BigInt64(val);
213 utility::LittleInt64(val);
216 inline void writeVal(atInt64 val) {
writeInt64(val);}
225 utility::LittleInt64(val);
237 utility::BigInt64(val);
248 inline void writeVal(atUint64 val) {
writeUint64(val);}
273 if (m_endian == BigEndian)
274 utility::BigFloat(val);
276 utility::LittleFloat(val);
279 inline void writeVal(
float val) {
writeFloat(val);}
288 utility::LittleFloat(val);
300 utility::BigFloat(val);
312 if (m_endian == BigEndian)
313 utility::BigDouble(val);
315 utility::LittleDouble(val);
318 inline void writeVal(
double val) {
writeDouble(val);}
327 utility::LittleDouble(val);
339 utility::BigDouble(val);
350 inline void writeVal(
bool val) {
writeBool(val);}
351 inline void writeValLittle(
bool val) {
writeBool(val);}
352 inline void writeValBig(
bool val) {
writeBool(val);}
362 if (m_endian == BigEndian)
364 utility::BigFloat(tmp.vec[0]);
365 utility::BigFloat(tmp.vec[1]);
369 utility::LittleFloat(tmp.vec[0]);
370 utility::LittleFloat(tmp.vec[1]);
384 utility::LittleFloat(tmp.vec[0]);
385 utility::LittleFloat(tmp.vec[1]);
398 utility::BigFloat(tmp.vec[0]);
399 utility::BigFloat(tmp.vec[1]);
412 if (m_endian == BigEndian)
414 utility::BigFloat(tmp.vec[0]);
415 utility::BigFloat(tmp.vec[1]);
416 utility::BigFloat(tmp.vec[2]);
420 utility::LittleFloat(tmp.vec[0]);
421 utility::LittleFloat(tmp.vec[1]);
422 utility::LittleFloat(tmp.vec[2]);
436 utility::LittleFloat(tmp.vec[0]);
437 utility::LittleFloat(tmp.vec[1]);
438 utility::LittleFloat(tmp.vec[2]);
451 utility::BigFloat(tmp.vec[0]);
452 utility::BigFloat(tmp.vec[1]);
453 utility::BigFloat(tmp.vec[2]);
466 if (m_endian == BigEndian)
468 utility::BigFloat(tmp.vec[0]);
469 utility::BigFloat(tmp.vec[1]);
470 utility::BigFloat(tmp.vec[2]);
471 utility::BigFloat(tmp.vec[3]);
475 utility::LittleFloat(tmp.vec[0]);
476 utility::LittleFloat(tmp.vec[1]);
477 utility::LittleFloat(tmp.vec[2]);
478 utility::LittleFloat(tmp.vec[3]);
492 utility::LittleFloat(tmp.vec[0]);
493 utility::LittleFloat(tmp.vec[1]);
494 utility::LittleFloat(tmp.vec[2]);
495 utility::LittleFloat(tmp.vec[3]);
508 utility::BigFloat(tmp.vec[0]);
509 utility::BigFloat(tmp.vec[1]);
510 utility::BigFloat(tmp.vec[2]);
511 utility::BigFloat(tmp.vec[3]);
524 if (m_endian == BigEndian)
526 utility::BigDouble(tmp.vec[0]);
527 utility::BigDouble(tmp.vec[1]);
531 utility::LittleDouble(tmp.vec[0]);
532 utility::LittleDouble(tmp.vec[1]);
546 utility::LittleDouble(tmp.vec[0]);
547 utility::LittleDouble(tmp.vec[1]);
560 utility::BigDouble(tmp.vec[0]);
561 utility::BigDouble(tmp.vec[1]);
574 if (m_endian == BigEndian)
576 utility::BigDouble(tmp.vec[0]);
577 utility::BigDouble(tmp.vec[1]);
578 utility::BigDouble(tmp.vec[2]);
582 utility::LittleDouble(tmp.vec[0]);
583 utility::LittleDouble(tmp.vec[1]);
584 utility::LittleDouble(tmp.vec[2]);
598 utility::LittleDouble(tmp.vec[0]);
599 utility::LittleDouble(tmp.vec[1]);
600 utility::LittleDouble(tmp.vec[2]);
613 utility::BigDouble(tmp.vec[0]);
614 utility::BigDouble(tmp.vec[1]);
615 utility::BigDouble(tmp.vec[2]);
628 if (m_endian == BigEndian)
630 utility::BigDouble(tmp.vec[0]);
631 utility::BigDouble(tmp.vec[1]);
632 utility::BigDouble(tmp.vec[2]);
633 utility::BigDouble(tmp.vec[3]);
637 utility::LittleDouble(tmp.vec[0]);
638 utility::LittleDouble(tmp.vec[1]);
639 utility::LittleDouble(tmp.vec[2]);
640 utility::LittleDouble(tmp.vec[3]);
654 utility::LittleDouble(tmp.vec[0]);
655 utility::LittleDouble(tmp.vec[1]);
656 utility::LittleDouble(tmp.vec[2]);
657 utility::LittleDouble(tmp.vec[3]);
670 utility::BigDouble(tmp.vec[0]);
671 utility::BigDouble(tmp.vec[1]);
672 utility::BigDouble(tmp.vec[2]);
673 utility::BigDouble(tmp.vec[3]);
690 std::string tmpStr =
"\xEF\xBB\xBF" + str;
691 const utf8proc_uint8_t* buf =
reinterpret_cast<const utf8proc_uint8_t*
>(tmpStr.c_str());
697 utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
700 atWarning(
"invalid UTF-8 character while decoding");
711 for (atInt32 i=0 ; i<fixedLen ; ++i)
713 utf8proc_int32_t wc = 0;
716 utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
719 atWarning(
"invalid UTF-8 character while decoding");
748 std::string tmpStr =
"\xEF\xBB\xBF" + str;
749 const utf8proc_uint8_t* buf =
reinterpret_cast<const utf8proc_uint8_t*
>(tmpStr.c_str());
755 utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
758 atWarning(
"invalid UTF-8 character while decoding");
769 for (atInt32 i=0 ; i<fixedLen ; ++i)
771 utf8proc_int32_t wc = 0;
774 utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
777 atWarning(
"invalid UTF-8 character while decoding");
807 std::string tmpStr =
"\xEF\xBB\xBF" + str;
808 const utf8proc_uint8_t* buf =
reinterpret_cast<const utf8proc_uint8_t*
>(tmpStr.c_str());
814 utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
817 atWarning(
"invalid UTF-8 character while decoding");
828 for (atInt32 i=0 ; i<fixedLen ; ++i)
830 utf8proc_int32_t wc = 0;
833 utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
836 atWarning(
"invalid UTF-8 character while decoding");
858 inline void writeString(
const std::string& str, atInt32 fixedLen = -1)
865 for (atUint8 c : str)
876 auto it = str.begin();
877 for (atInt32 i=0 ; i<fixedLen ; ++i)
888 inline void writeVal(
const std::string& val) {
writeString(val);}
897 inline void writeWString(
const std::wstring& str, atInt32 fixedLen = -1)
904 for (atUint16 c : str)
915 auto it = str.begin();
916 for (atInt32 i=0 ; i<fixedLen ; ++i)
927 inline void writeVal(
const std::wstring& val) {
writeWString(val);}
943 for (atUint16 c : str)
954 auto it = str.begin();
955 for (atInt32 i=0 ; i<fixedLen ; ++i)
982 for (atUint16 c : str)
993 auto it = str.begin();
994 for (atInt32 i=0 ; i<fixedLen ; ++i)
1005 inline void writeValBig(
const std::wstring& val) {
writeWStringBig(val);}
1007 inline void fill(atUint8 val, atUint64
length)
1012 std::unique_ptr<atUint8[]> tmp(
new atUint8[length]);
1013 memset(tmp.get(), val,
length);
1017 inline void fill(atInt8 val, atUint64 length)
1018 {fill((atUint8)val, length);}
1027 typename std::enable_if<std::is_arithmetic<T>::value ||
1028 std::is_same<T, atVec2f>::value ||
1029 std::is_same<T, atVec3f>::value ||
1030 std::is_same<T, atVec4f>::value>::type* = 0)
1032 for (
const T& item : vector)
1043 typename std::enable_if<std::is_arithmetic<T>::value ||
1044 std::is_same<T, atVec2f>::value ||
1045 std::is_same<T, atVec3f>::value ||
1046 std::is_same<T, atVec4f>::value>::type* = 0)
1048 for (
const T& item : vector)
1049 writeValLittle(item);
1059 typename std::enable_if<std::is_arithmetic<T>::value ||
1060 std::is_same<T, atVec2f>::value ||
1061 std::is_same<T, atVec3f>::value ||
1062 std::is_same<T, atVec4f>::value>::type* = 0)
1064 for (
const T& item : vector)
1073 typename std::enable_if<!std::is_arithmetic<T>::value &&
1074 !std::is_same<T, atVec2f>::value &&
1075 !std::is_same<T, atVec3f>::value &&
1076 !std::is_same<T, atVec4f>::value>::type* = 0)
1078 for (
const T& item : vector)
1083 template <
typename T>
1091 #endif // STREAMWRITER_HPP void writeVec4fLittle(const atVec4f &vec)
Writes an atVec4f (16 bytes) to the buffer and advances the buffer. It also swaps the bytes against l...
void writeFloatLittle(float val)
Writes an float to the buffer and advances the buffer. It also swaps the bytes against little dependi...
void writeUint32(atUint32 val)
Writes an Uint32 to the buffer and advances the buffer. It also swaps the bytes depending on the plat...
void writeVec2f(const atVec2f &vec)
Writes an atVec2f (8 bytes) to the buffer and advances the buffer. It also swaps the bytes depending ...
void writeFloat(float val)
Writes an float to the buffer and advances the buffer. It also swaps the bytes depending on the platf...
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...
void writeInt64Big(atInt64 val)
Writes an Int64 to the buffer and advances the buffer. It also swaps the bytes against big depending ...
virtual atUint64 position() const =0
Returns the current position in the stream.
void enumerateBig(const std::vector< T > &vector, 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 writes using numeric type T.
void enumerateLittle(const std::vector< T > &vector, 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 writes using numeric type T.
bool atEnd() const
Returns whether or not the stream is at the end.
void writeInt32Big(atInt32 val)
Writes an Int32 to the buffer and advances the buffer. It also swaps the bytes against big depending ...
void writeVec3fBig(const atVec3f &vec)
Writes an atVec3f (12 bytes) to the buffer and advances the buffer. It also swaps the bytes against b...
virtual atUint64 length() const =0
Returns whether or not the stream is at the end.
void writeUint16Little(atUint16 val)
Writes an Uint16 to the buffer and advances the buffer. It also swaps the bytes against little depend...
void writeWStringBig(const std::wstring &str, atInt32 fixedLen=-1)
Writes an wstring to the buffer and advances the buffer.
void writeByte(atInt8 val)
Writes a byte at the current position and advances the position by one byte.
void enumerate(const std::vector< T > &vector, 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 writes using numeric type T.
void writeWStringLittle(const std::wstring &str, atInt32 fixedLen=-1)
Writes an wstring to the buffer and advances the buffer.
void writeUint64Big(atUint64 val)
Writes an Uint64 to the buffer and advances the buffer. It also swaps the bytes against big depending...
void writeWString(const std::wstring &str, atInt32 fixedLen=-1)
Writes an wstring to the buffer and advances the buffer.
void writeUint32Big(atUint32 val)
Writes an Uint32 to the buffer and advances the buffer. It also swaps the bytes against big depending...
virtual void writeUBytes(const atUint8 *data, atUint64 len)=0
Writes the given buffer with the specified length, buffers can be bigger than the length however it's...
void writeBytes(const void *data, atUint64 len)
Writes the given buffer with the specified length, buffers can be bigger than the length however it's...
void writeStringAsWStringBig(const std::string &str, atInt32 fixedLen=-1)
Converts a UTF8 string to a wide-char string in the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings.
void writeInt16(atInt16 val)
Writes an Int16 to the buffer and advances the buffer. It also swaps the bytes depending on the platf...
void enumerate(const std::vector< T > &vector, 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 writes using non-numeric type T.
void writeVec2fBig(const atVec2f &vec)
Writes an atVec2f (8 bytes) to the buffer and advances the buffer. It also swaps the bytes against bi...
void writeVec4dBig(const atVec4d &vec)
Writes an atVec4d (32 bytes) to the buffer and advances the buffer. It also swaps the bytes against b...
void writeDouble(double val)
Writes an double to the buffer and advances the buffer. It also swaps the bytes depending on the plat...
void writeBool(bool val)
Writes an bool to the buffer and advances the buffer. It also swaps the bytes depending on the platfo...
void writeVec4fBig(const atVec4f &vec)
Writes an atVec4f (16 bytes) to the buffer and advances the buffer. It also swaps the bytes against b...
void writeStringAsWString(const std::string &str, atInt32 fixedLen=-1)
Converts a UTF8 string to a wide-char string in the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings.
void writeVec4f(const atVec4f &vec)
Writes an atVec4f (16 bytes) to the buffer and advances the buffer. It also swaps the bytes depending...
void writeUint64(atUint64 val)
Writes an Uint64 to the buffer and advances the buffer. It also swaps the bytes depending on the plat...
void writeUint16(atUint16 val)
Writes an Uint16 to the buffer and advances the buffer. It also swaps the bytes depending on the plat...
void writeUint32Little(atUint32 val)
Writes an Uint32 to the buffer and advances the buffer. It also swaps the bytes against little depend...
void writeInt16Big(atInt16 val)
Writes an Int16 to the buffer and advances the buffer. It also swaps the bytes against big depending ...
void writeVec2fLittle(const atVec2f &vec)
Writes an atVec2f (8 bytes) to the buffer and advances the buffer. It also swaps the bytes against li...
void writeStringAsWStringLittle(const std::string &str, atInt32 fixedLen=-1)
Converts a UTF8 string to a wide-char string in the buffer and advances the buffer. It also swaps the bytes depending on the platform and Stream settings.
void writeInt16Little(atInt16 val)
Writes an Int16 to the buffer and advances the buffer. It also swaps the bytes against little dependi...
void writeVec4dLittle(const atVec4d &vec)
Writes an atVec4d (32 bytes) to the buffer and advances the buffer. It also swaps the bytes against l...
void writeVec2dLittle(const atVec2d &vec)
Writes an atVec2d (16 bytes) to the buffer and advances the buffer. It also swaps the bytes against l...
void writeInt32(atInt32 val)
Writes an Int32 to the buffer and advances the buffer. It also swaps the bytes depending on the platf...
void writeDoubleBig(double val)
Writes an double to the buffer and advances the buffer. It also swaps the bytes against big depending...
void writeVec2dBig(const atVec2d &vec)
Writes an atVec2d (16 bytes) to the buffer and advances the buffer. It also swaps the bytes against b...
void writeInt64(atInt64 val)
Writes an Int64 to the buffer and advances the buffer. It also swaps the bytes depending on the platf...
void writeVec3d(const atVec3d &vec)
Writes an atVec3d (24 bytes) to the buffer and advances the buffer. It also swaps the bytes depending...
void writeVec3dLittle(const atVec3d &vec)
Writes an atVec3d (24 bytes) to the buffer and advances the buffer. It also swaps the bytes against l...
void writeVec3dBig(const atVec3d &vec)
Writes an atVec3d (24 bytes) to the buffer and advances the buffer. It also swaps the bytes against b...
void writeVec3f(const atVec3f &vec)
Writes an atVec3f (12 bytes) to the buffer and advances the buffer. It also swaps the bytes depending...
void writeUint16Big(atUint16 val)
Writes an Uint16 to the buffer and advances the buffer. It also swaps the bytes against big depending...
void writeUByte(atUint8 val)
Writes a byte at the current position and advances the position by one byte.
void writeFloatBig(float val)
Writes an float to the buffer and advances the buffer. It also swaps the bytes against big depending ...
void writeUint64Little(atUint64 val)
Writes an Uint64 to the buffer and advances the buffer. It also swaps the bytes against little depend...
void writeVec4d(const atVec4d &vec)
Writes an atVec4d (32 bytes) to the buffer and advances the buffer. It also swaps the bytes depending...
void writeDoubleLittle(double val)
Writes an double to the buffer and advances the buffer. It also swaps the bytes against little depend...
void writeString(const std::string &str, atInt32 fixedLen=-1)
Writes an string to the buffer and advances the buffer.
void seekAlign32()
Sets the buffers position relative to the next 32-byte aligned position.
void writeInt32Little(atInt32 val)
Writes an Int32 to the buffer and advances the buffer. It also swaps the bytes against little dependi...
void writeVec2d(const atVec2d &vec)
Writes an atVec2d (16 bytes) to the buffer and advances the buffer. It also swaps the bytes depending...
void writeInt64Little(atInt64 val)
Writes an Int64 to the buffer and advances the buffer. It also swaps the bytes against little dependi...
void writeVec3fLittle(const atVec3f &vec)
Writes an atVec3f (12 bytes) to the buffer and advances the buffer. It also swaps the bytes against l...