Athena IO Library
IStreamWriter.hpp
1 #ifndef ISTREAMWRITER_HPP
2 #define ISTREAMWRITER_HPP
3 
4 #include "utf8proc.h"
5 #include "IStream.hpp"
6 #include <memory>
7 
8 namespace athena
9 {
10 namespace io
11 {
12 class IStreamWriter : public IStream
13 {
14 public:
15  virtual ~IStreamWriter() {}
21  virtual void seek(atInt64 pos, SeekOrigin origin = SeekOrigin::Current)=0;
22 
25  inline void seekAlign32() {seek(ROUND_UP_32(position()), SeekOrigin::Begin);}
26 
31  inline bool atEnd() const {return position() >= length();}
32 
37  virtual atUint64 position() const=0;
38 
43  virtual atUint64 length() const=0;
44 
48  inline void writeUByte(atUint8 val) {writeUBytes(&val, 1);}
49  inline void writeVal(atUint8 val) {writeUByte(val);}
50  inline void writeValLittle(atUint8 val) {writeUByte(val);}
51  inline void writeValBig(atUint8 val) {writeUByte(val);}
52 
56  inline void writeByte(atInt8 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);}
60 
67  virtual void writeUBytes(const atUint8* data, atUint64 len)=0;
68 
75  inline void writeBytes(const void* data, atUint64 len) {writeUBytes((atUint8*)data, len);}
76 
82  inline void writeInt16(atInt16 val)
83  {
84  if (m_endian == BigEndian)
85  utility::BigInt16(val);
86  else
87  utility::LittleInt16(val);
88  writeUBytes((atUint8*)&val, 2);
89  }
90  inline void writeVal(atInt16 val) {writeInt16(val);}
91 
97  inline void writeInt16Little(atInt16 val)
98  {
99  utility::LittleInt16(val);
100  writeUBytes((atUint8*)&val, 2);
101  }
102  inline void writeValLittle(atInt16 val) {writeInt16Little(val);}
103 
109  inline void writeInt16Big(atInt16 val)
110  {
111  utility::BigInt16(val);
112  writeUBytes((atUint8*)&val, 2);
113  }
114  inline void writeValBig(atInt16 val) {writeInt16Big(val);}
115 
121  inline void writeUint16(atUint16 val) {writeInt16(val);}
122  inline void writeVal(atUint16 val) {writeUint16(val);}
123 
129  inline void writeUint16Little(atUint16 val) {writeInt16Little(val);}
130  inline void writeValLittle(atUint16 val) {writeUint16Little(val);}
131 
137  inline void writeUint16Big(atUint16 val) {writeInt16Big(val);}
138  inline void writeValBig(atUint16 val) {writeUint16Big(val);}
139 
145  inline void writeInt32(atInt32 val)
146  {
147  if (m_endian == BigEndian)
148  utility::BigInt32(val);
149  else
150  utility::LittleInt32(val);
151  writeUBytes((atUint8*)&val, 4);
152  }
153  inline void writeVal(atInt32 val) {writeInt32(val);}
154 
160  inline void writeInt32Little(atInt32 val)
161  {
162  utility::LittleInt32(val);
163  writeUBytes((atUint8*)&val, 4);
164  }
165  inline void writeValLittle(atInt32 val) {writeInt32Little(val);}
166 
172  inline void writeInt32Big(atInt32 val)
173  {
174  utility::BigInt32(val);
175  writeUBytes((atUint8*)&val, 4);
176  }
177  inline void writeValBig(atInt32 val) {writeInt32Big(val);}
178 
184  inline void writeUint32(atUint32 val) {writeInt32(val);}
185  inline void writeVal(atUint32 val) {writeUint32(val);}
186 
192  inline void writeUint32Little(atUint32 val) {writeInt32Little(val);}
193  inline void writeValLittle(atUint32 val) {writeUint32Little(val);}
194 
200  inline void writeUint32Big(atUint32 val) {writeInt32Big(val);}
201  inline void writeValBig(atUint32 val) {writeUint32Big(val);}
202 
208  inline void writeInt64(atInt64 val)
209  {
210  if (m_endian == BigEndian)
211  utility::BigInt64(val);
212  else
213  utility::LittleInt64(val);
214  writeUBytes((atUint8*)&val, 8);
215  }
216  inline void writeVal(atInt64 val) {writeInt64(val);}
217 
223  inline void writeInt64Little(atInt64 val)
224  {
225  utility::LittleInt64(val);
226  writeUBytes((atUint8*)&val, 8);
227  }
228  inline void writeValLittle(atInt64 val) {writeInt64Little(val);}
229 
235  inline void writeInt64Big(atInt64 val)
236  {
237  utility::BigInt64(val);
238  writeUBytes((atUint8*)&val, 8);
239  }
240  inline void writeValBig(atInt64 val) {writeInt64Big(val);}
241 
247  inline void writeUint64(atUint64 val) {writeInt64(val);}
248  inline void writeVal(atUint64 val) {writeUint64(val);}
249 
255  inline void writeUint64Little(atUint64 val) {writeInt64Little(val);}
256  inline void writeValLittle(atUint64 val) {writeUint64Little(val);}
257 
263  inline void writeUint64Big(atUint64 val) {writeInt64Big(val);}
264  inline void writeValBig(atUint64 val) {writeUint64Big(val);}
265 
271  inline void writeFloat(float val)
272  {
273  if (m_endian == BigEndian)
274  utility::BigFloat(val);
275  else
276  utility::LittleFloat(val);
277  writeUBytes((atUint8*)&val, 4);
278  }
279  inline void writeVal(float val) {writeFloat(val);}
280 
286  inline void writeFloatLittle(float val)
287  {
288  utility::LittleFloat(val);
289  writeUBytes((atUint8*)&val, 4);
290  }
291  inline void writeValLittle(float val) {writeFloatLittle(val);}
292 
298  inline void writeFloatBig(float val)
299  {
300  utility::BigFloat(val);
301  writeUBytes((atUint8*)&val, 4);
302  }
303  inline void writeValBig(float val) {writeFloatBig(val);}
304 
310  inline void writeDouble(double val)
311  {
312  if (m_endian == BigEndian)
313  utility::BigDouble(val);
314  else
315  utility::LittleDouble(val);
316  writeUBytes((atUint8*)&val, 8);
317  }
318  inline void writeVal(double val) {writeDouble(val);}
319 
325  inline void writeDoubleLittle(double val)
326  {
327  utility::LittleDouble(val);
328  writeUBytes((atUint8*)&val, 8);
329  }
330  inline void writeValLittle(double val) {writeDoubleLittle(val);}
331 
337  inline void writeDoubleBig(double val)
338  {
339  utility::BigDouble(val);
340  writeUBytes((atUint8*)&val, 8);
341  }
342  inline void writeValBig(double val) {writeDoubleBig(val);}
343 
349  inline void writeBool(bool val) {writeUBytes((atUint8*)&val, 1);}
350  inline void writeVal(bool val) {writeBool(val);}
351  inline void writeValLittle(bool val) {writeBool(val);}
352  inline void writeValBig(bool val) {writeBool(val);}
353 
359  inline void writeVec2f(const atVec2f& vec)
360  {
361  atVec2f tmp = vec;
362  if (m_endian == BigEndian)
363  {
364  utility::BigFloat(tmp.vec[0]);
365  utility::BigFloat(tmp.vec[1]);
366  }
367  else
368  {
369  utility::LittleFloat(tmp.vec[0]);
370  utility::LittleFloat(tmp.vec[1]);
371  }
372  writeUBytes((atUint8*)&tmp, 8);
373  }
374  inline void writeVal(const atVec2f& val) {writeVec2f(val);}
375 
381  inline void writeVec2fLittle(const atVec2f& vec)
382  {
383  atVec2f tmp = vec;
384  utility::LittleFloat(tmp.vec[0]);
385  utility::LittleFloat(tmp.vec[1]);
386  writeUBytes((atUint8*)&tmp, 8);
387  }
388  inline void writeValLittle(const atVec2f& val) {writeVec2fLittle(val);}
389 
395  inline void writeVec2fBig(const atVec2f& vec)
396  {
397  atVec2f tmp = vec;
398  utility::BigFloat(tmp.vec[0]);
399  utility::BigFloat(tmp.vec[1]);
400  writeUBytes((atUint8*)&tmp, 8);
401  }
402  inline void writeValBig(const atVec2f& val) {writeVec2fBig(val);}
403 
409  inline void writeVec3f(const atVec3f& vec)
410  {
411  atVec3f tmp = vec;
412  if (m_endian == BigEndian)
413  {
414  utility::BigFloat(tmp.vec[0]);
415  utility::BigFloat(tmp.vec[1]);
416  utility::BigFloat(tmp.vec[2]);
417  }
418  else
419  {
420  utility::LittleFloat(tmp.vec[0]);
421  utility::LittleFloat(tmp.vec[1]);
422  utility::LittleFloat(tmp.vec[2]);
423  }
424  writeUBytes((atUint8*)&tmp, 12);
425  }
426  inline void writeVal(const atVec3f& val) {writeVec3f(val);}
427 
433  inline void writeVec3fLittle(const atVec3f& vec)
434  {
435  atVec3f tmp = vec;
436  utility::LittleFloat(tmp.vec[0]);
437  utility::LittleFloat(tmp.vec[1]);
438  utility::LittleFloat(tmp.vec[2]);
439  writeUBytes((atUint8*)&tmp, 12);
440  }
441  inline void writeValLittle(const atVec3f& val) {writeVec3fLittle(val);}
442 
448  inline void writeVec3fBig(const atVec3f& vec)
449  {
450  atVec3f tmp = vec;
451  utility::BigFloat(tmp.vec[0]);
452  utility::BigFloat(tmp.vec[1]);
453  utility::BigFloat(tmp.vec[2]);
454  writeUBytes((atUint8*)&tmp, 12);
455  }
456  inline void writeValBig(const atVec3f& val) {writeVec3fBig(val);}
457 
463  inline void writeVec4f(const atVec4f& vec)
464  {
465  atVec4f tmp = vec;
466  if (m_endian == BigEndian)
467  {
468  utility::BigFloat(tmp.vec[0]);
469  utility::BigFloat(tmp.vec[1]);
470  utility::BigFloat(tmp.vec[2]);
471  utility::BigFloat(tmp.vec[3]);
472  }
473  else
474  {
475  utility::LittleFloat(tmp.vec[0]);
476  utility::LittleFloat(tmp.vec[1]);
477  utility::LittleFloat(tmp.vec[2]);
478  utility::LittleFloat(tmp.vec[3]);
479  }
480  writeUBytes((atUint8*)&tmp, 16);
481  }
482  inline void writeVal(const atVec4f& val) {writeVec4f(val);}
483 
489  inline void writeVec4fLittle(const atVec4f& vec)
490  {
491  atVec4f tmp = vec;
492  utility::LittleFloat(tmp.vec[0]);
493  utility::LittleFloat(tmp.vec[1]);
494  utility::LittleFloat(tmp.vec[2]);
495  utility::LittleFloat(tmp.vec[3]);
496  writeUBytes((atUint8*)&tmp, 16);
497  }
498  inline void writeValLittle(const atVec4f& val) {writeVec4fLittle(val);}
499 
505  inline void writeVec4fBig(const atVec4f& vec)
506  {
507  atVec4f tmp = vec;
508  utility::BigFloat(tmp.vec[0]);
509  utility::BigFloat(tmp.vec[1]);
510  utility::BigFloat(tmp.vec[2]);
511  utility::BigFloat(tmp.vec[3]);
512  writeUBytes((atUint8*)&tmp, 16);
513  }
514  inline void writeValBig(const atVec4f& val) {writeVec4fBig(val);}
515 
521  inline void writeVec2d(const atVec2d& vec)
522  {
523  atVec2d tmp = vec;
524  if (m_endian == BigEndian)
525  {
526  utility::BigDouble(tmp.vec[0]);
527  utility::BigDouble(tmp.vec[1]);
528  }
529  else
530  {
531  utility::LittleDouble(tmp.vec[0]);
532  utility::LittleDouble(tmp.vec[1]);
533  }
534  writeUBytes((atUint8*)&tmp, 16);
535  }
536  inline void writeVal(const atVec2d& val) {writeVec2d(val);}
537 
543  inline void writeVec2dLittle(const atVec2d& vec)
544  {
545  atVec2d tmp = vec;
546  utility::LittleDouble(tmp.vec[0]);
547  utility::LittleDouble(tmp.vec[1]);
548  writeUBytes((atUint8*)&tmp, 16);
549  }
550  inline void writeValLittle(const atVec2d& val) {writeVec2dLittle(val);}
551 
557  inline void writeVec2dBig(const atVec2d& vec)
558  {
559  atVec2d tmp = vec;
560  utility::BigDouble(tmp.vec[0]);
561  utility::BigDouble(tmp.vec[1]);
562  writeUBytes((atUint8*)&tmp, 16);
563  }
564  inline void writeValBig(const atVec2d& val) {writeVec2dBig(val);}
565 
571  inline void writeVec3d(const atVec3d& vec)
572  {
573  atVec3d tmp = vec;
574  if (m_endian == BigEndian)
575  {
576  utility::BigDouble(tmp.vec[0]);
577  utility::BigDouble(tmp.vec[1]);
578  utility::BigDouble(tmp.vec[2]);
579  }
580  else
581  {
582  utility::LittleDouble(tmp.vec[0]);
583  utility::LittleDouble(tmp.vec[1]);
584  utility::LittleDouble(tmp.vec[2]);
585  }
586  writeUBytes((atUint8*)&tmp, 24);
587  }
588  inline void writeVal(const atVec3d& val) {writeVec3d(val);}
589 
595  inline void writeVec3dLittle(const atVec3d& vec)
596  {
597  atVec3d tmp = vec;
598  utility::LittleDouble(tmp.vec[0]);
599  utility::LittleDouble(tmp.vec[1]);
600  utility::LittleDouble(tmp.vec[2]);
601  writeUBytes((atUint8*)&tmp, 24);
602  }
603  inline void writeValLittle(const atVec3d& val) {writeVec3dLittle(val);}
604 
610  inline void writeVec3dBig(const atVec3d& vec)
611  {
612  atVec3d tmp = vec;
613  utility::BigDouble(tmp.vec[0]);
614  utility::BigDouble(tmp.vec[1]);
615  utility::BigDouble(tmp.vec[2]);
616  writeUBytes((atUint8*)&tmp, 24);
617  }
618  inline void writeValBig(const atVec3d& val) {writeVec3dBig(val);}
619 
625  inline void writeVec4d(const atVec4d& vec)
626  {
627  atVec4d tmp = vec;
628  if (m_endian == BigEndian)
629  {
630  utility::BigDouble(tmp.vec[0]);
631  utility::BigDouble(tmp.vec[1]);
632  utility::BigDouble(tmp.vec[2]);
633  utility::BigDouble(tmp.vec[3]);
634  }
635  else
636  {
637  utility::LittleDouble(tmp.vec[0]);
638  utility::LittleDouble(tmp.vec[1]);
639  utility::LittleDouble(tmp.vec[2]);
640  utility::LittleDouble(tmp.vec[3]);
641  }
642  writeUBytes((atUint8*)&tmp, 32);
643  }
644  inline void writeVal(const atVec4d& val) {writeVec4d(val);}
645 
651  inline void writeVec4dLittle(const atVec4d& vec)
652  {
653  atVec4d tmp = vec;
654  utility::LittleDouble(tmp.vec[0]);
655  utility::LittleDouble(tmp.vec[1]);
656  utility::LittleDouble(tmp.vec[2]);
657  utility::LittleDouble(tmp.vec[3]);
658  writeUBytes((atUint8*)&tmp, 32);
659  }
660  inline void writeValLittle(const atVec4d& val) {writeVec4dLittle(val);}
661 
667  inline void writeVec4dBig(const atVec4d& vec)
668  {
669  atVec4d tmp = vec;
670  utility::BigDouble(tmp.vec[0]);
671  utility::BigDouble(tmp.vec[1]);
672  utility::BigDouble(tmp.vec[2]);
673  utility::BigDouble(tmp.vec[3]);
674  writeUBytes((atUint8*)&tmp, 32);
675  }
676  inline void writeValBig(const atVec4d& val) {writeVec4dBig(val);}
677 
686  inline void writeStringAsWString(const std::string& str, atInt32 fixedLen = -1)
687  {
688  if (fixedLen == 0)
689  return;
690  std::string tmpStr = "\xEF\xBB\xBF" + str;
691  const utf8proc_uint8_t* buf = reinterpret_cast<const utf8proc_uint8_t*>(tmpStr.c_str());
692  if (fixedLen < 0)
693  {
694  while (*buf)
695  {
696  utf8proc_int32_t wc;
697  utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
698  if (len < 0)
699  {
700  atWarning("invalid UTF-8 character while decoding");
701  return;
702  }
703  buf += len;
704  if (wc != 0xFEFF)
705  writeUint16(atUint16(wc));
706  }
707  writeUint16(0);
708  }
709  else
710  {
711  for (atInt32 i=0 ; i<fixedLen ; ++i)
712  {
713  utf8proc_int32_t wc = 0;
714  if (*buf)
715  {
716  utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
717  if (len < 0)
718  {
719  atWarning("invalid UTF-8 character while decoding");
720  return;
721  }
722  buf += len;
723  }
724 
725  if (wc == 0xFEFF)
726  {
727  --i;
728  continue;
729  }
730 
731  writeUint16(atUint16(wc));
732  }
733  }
734  }
735 
744  inline void writeStringAsWStringLittle(const std::string& str, atInt32 fixedLen = -1)
745  {
746  if (fixedLen == 0)
747  return;
748  std::string tmpStr = "\xEF\xBB\xBF" + str;
749  const utf8proc_uint8_t* buf = reinterpret_cast<const utf8proc_uint8_t*>(tmpStr.c_str());
750  if (fixedLen < 0)
751  {
752  while (*buf)
753  {
754  utf8proc_int32_t wc;
755  utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
756  if (len < 0)
757  {
758  atWarning("invalid UTF-8 character while decoding");
759  return;
760  }
761  buf += len;
762  if (wc != 0xFEFF)
763  writeUint16Little(atUint16(wc));
764  }
766  }
767  else
768  {
769  for (atInt32 i=0 ; i<fixedLen ; ++i)
770  {
771  utf8proc_int32_t wc = 0;
772  if (*buf)
773  {
774  utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
775  if (len < 0)
776  {
777  atWarning("invalid UTF-8 character while decoding");
778  return;
779  }
780  buf += len;
781  }
782 
783  if (wc == 0xFEFF)
784  {
785  --i;
786  continue;
787  }
788 
789  writeUint16Little(atUint16(wc));
790  }
791  }
792  }
793 
802  inline void writeStringAsWStringBig(const std::string& str, atInt32 fixedLen = -1)
803  {
804  if (fixedLen == 0)
805  return;
806 
807  std::string tmpStr = "\xEF\xBB\xBF" + str;
808  const utf8proc_uint8_t* buf = reinterpret_cast<const utf8proc_uint8_t*>(tmpStr.c_str());
809  if (fixedLen < 0)
810  {
811  while (*buf)
812  {
813  utf8proc_int32_t wc;
814  utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
815  if (len < 0)
816  {
817  atWarning("invalid UTF-8 character while decoding");
818  return;
819  }
820  buf += len;
821  if (wc != 0xFEFF)
822  writeUint16Big(atUint16(wc));
823  }
824  writeUint16Big(0);
825  }
826  else
827  {
828  for (atInt32 i=0 ; i<fixedLen ; ++i)
829  {
830  utf8proc_int32_t wc = 0;
831  if (*buf)
832  {
833  utf8proc_ssize_t len = utf8proc_iterate(buf, -1, &wc);
834  if (len < 0)
835  {
836  atWarning("invalid UTF-8 character while decoding");
837  return;
838  }
839  buf += len;
840  }
841 
842  if (wc == 0xFEFF)
843  {
844  --i;
845  continue;
846  }
847 
848  writeUint16Big(atUint16(wc));
849  }
850  }
851  }
852 
858  inline void writeString(const std::string& str, atInt32 fixedLen = -1)
859  {
860  if (fixedLen == 0)
861  return;
862 
863  if (fixedLen < 0)
864  {
865  for (atUint8 c : str)
866  {
867  writeUByte(c);
868 
869  if (c == '\0')
870  break;
871  }
872  writeUByte(0);
873  }
874  else
875  {
876  auto it = str.begin();
877  for (atInt32 i=0 ; i<fixedLen ; ++i)
878  {
879  atUint8 chr;
880  if (it == str.end())
881  chr = 0;
882  else
883  chr = *it++;
884  writeUByte(chr);
885  }
886  }
887  }
888  inline void writeVal(const std::string& val) {writeString(val);}
889 
897  inline void writeWString(const std::wstring& str, atInt32 fixedLen = -1)
898  {
899  if (fixedLen == 0)
900  return;
901 
902  if (fixedLen < 0)
903  {
904  for (atUint16 c : str)
905  {
906  writeUint16(c);
907 
908  if (c == L'\0')
909  break;
910  }
911  writeUint16(0);
912  }
913  else
914  {
915  auto it = str.begin();
916  for (atInt32 i=0 ; i<fixedLen ; ++i)
917  {
918  atUint16 chr;
919  if (it == str.end())
920  chr = 0;
921  else
922  chr = *it++;
923  writeUint16(chr);
924  }
925  }
926  }
927  inline void writeVal(const std::wstring& val) {writeWString(val);}
928 
936  inline void writeWStringLittle(const std::wstring& str, atInt32 fixedLen = -1)
937  {
938  if (fixedLen == 0)
939  return;
940 
941  if (fixedLen < 0)
942  {
943  for (atUint16 c : str)
944  {
946 
947  if (c == L'\0')
948  break;
949  }
951  }
952  else
953  {
954  auto it = str.begin();
955  for (atInt32 i=0 ; i<fixedLen ; ++i)
956  {
957  atUint16 chr;
958  if (it == str.end())
959  chr = 0;
960  else
961  chr = *it++;
962  writeUint16Little(chr);
963  }
964  }
965  }
966  inline void writeValLittle(const std::wstring& val) {writeWStringLittle(val);}
967 
975  inline void writeWStringBig(const std::wstring& str, atInt32 fixedLen = -1)
976  {
977  if (fixedLen == 0)
978  return;
979 
980  if (fixedLen < 0)
981  {
982  for (atUint16 c : str)
983  {
984  writeUint16Big(c);
985 
986  if (c == L'\0')
987  break;
988  }
989  writeUint16Big(0);
990  }
991  else
992  {
993  auto it = str.begin();
994  for (atInt32 i=0 ; i<fixedLen ; ++i)
995  {
996  atUint16 chr;
997  if (it == str.end())
998  chr = 0;
999  else
1000  chr = *it++;
1001  writeUint16Big(chr);
1002  }
1003  }
1004  }
1005  inline void writeValBig(const std::wstring& val) {writeWStringBig(val);}
1006 
1007  inline void fill(atUint8 val, atUint64 length)
1008  {
1009  if (length == 0)
1010  return;
1011 
1012  std::unique_ptr<atUint8[]> tmp(new atUint8[length]);
1013  memset(tmp.get(), val, length);
1014  writeUBytes(tmp.get(), length);
1015  }
1016 
1017  inline void fill(atInt8 val, atUint64 length)
1018  {fill((atUint8)val, length);}
1019 
1025  template <class T>
1026  void enumerate(const std::vector<T>& vector,
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)
1031  {
1032  for (const T& item : vector)
1033  writeVal(item);
1034  }
1035 
1041  template <class T>
1042  void enumerateLittle(const std::vector<T>& 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)
1047  {
1048  for (const T& item : vector)
1049  writeValLittle(item);
1050  }
1051 
1057  template <class T>
1058  void enumerateBig(const std::vector<T>& vector,
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)
1063  {
1064  for (const T& item : vector)
1065  writeValBig(item);
1066  }
1067 
1071  template <class T>
1072  void enumerate(const std::vector<T>& 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)
1077  {
1078  for (const T& item : vector)
1079  item.write(*this);
1080  }
1081 };
1082 
1083 template <typename T>
1084 IStreamWriter& operator<<(IStreamWriter& lhs, const T& rhs)
1085 {
1086  lhs.writeVal(rhs);
1087  return lhs;
1088 }
1089 }
1090 }
1091 #endif // STREAMWRITER_HPP
1092 
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&#39;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&#39;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...