Deserializer.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  1. //
  2. // Copyright (c) 2008-2017 the Urho3D project.
  3. //
  4. // Permission is hereby granted, free of charge, to any person obtaining a copy
  5. // of this software and associated documentation files (the "Software"), to deal
  6. // in the Software without restriction, including without limitation the rights
  7. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. // copies of the Software, and to permit persons to whom the Software is
  9. // furnished to do so, subject to the following conditions:
  10. //
  11. // The above copyright notice and this permission notice shall be included in
  12. // all copies or substantial portions of the Software.
  13. //
  14. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  20. // THE SOFTWARE.
  21. //
  22. #pragma once
  23. #include "../Core/Variant.h"
  24. #include "../Math/BoundingBox.h"
  25. #include "../Math/Rect.h"
  26. namespace Atomic
  27. {
  28. /// Abstract stream for reading.
  29. class ATOMIC_API Deserializer
  30. {
  31. public:
  32. /// Construct with zero size.
  33. Deserializer();
  34. /// Construct with defined size.
  35. Deserializer(unsigned size);
  36. /// Destruct.
  37. virtual ~Deserializer();
  38. /// Read bytes from the stream. Return number of bytes actually read.
  39. virtual unsigned Read(void* dest, unsigned size) = 0;
  40. /// Set position from the beginning of the stream.
  41. virtual unsigned Seek(unsigned position) = 0;
  42. /// Return name of the stream.
  43. virtual const String& GetName() const;
  44. /// Return a checksum if applicable.
  45. virtual unsigned GetChecksum();
  46. /// Return whether the end of stream has been reached.
  47. virtual bool IsEof() const { return position_ >= size_; }
  48. /// Return current position.
  49. unsigned GetPosition() const { return position_; }
  50. /// Return size.
  51. unsigned GetSize() const { return size_; }
  52. /// Read a 64-bit integer.
  53. long long ReadInt64();
  54. /// Read a 32-bit integer.
  55. int ReadInt();
  56. /// Read a 16-bit integer.
  57. short ReadShort();
  58. /// Read an 8-bit integer.
  59. signed char ReadByte();
  60. /// Read a 64-bit unsigned integer.
  61. unsigned long long ReadUInt64();
  62. /// Read a 32-bit unsigned integer.
  63. unsigned ReadUInt();
  64. /// Read a 16-bit unsigned integer.
  65. unsigned short ReadUShort();
  66. /// Read an 8-bit unsigned integer.
  67. unsigned char ReadUByte();
  68. /// Read a bool.
  69. bool ReadBool();
  70. /// Read a float.
  71. float ReadFloat();
  72. /// Read a double.
  73. double ReadDouble();
  74. /// Read an IntRect.
  75. IntRect ReadIntRect();
  76. /// Read an IntVector2.
  77. IntVector2 ReadIntVector2();
  78. /// Read an IntVector3.
  79. IntVector3 ReadIntVector3();
  80. /// Read a Rect.
  81. Rect ReadRect();
  82. /// Read a Vector2.
  83. Vector2 ReadVector2();
  84. /// Read a Vector3.
  85. Vector3 ReadVector3();
  86. /// Read a Vector3 packed into 3 x 16 bits with the specified maximum absolute range.
  87. Vector3 ReadPackedVector3(float maxAbsCoord);
  88. /// Read a Vector4.
  89. Vector4 ReadVector4();
  90. /// Read a quaternion.
  91. Quaternion ReadQuaternion();
  92. /// Read a quaternion with each component packed in 16 bits.
  93. Quaternion ReadPackedQuaternion();
  94. /// Read a Matrix3.
  95. Matrix3 ReadMatrix3();
  96. /// Read a Matrix3x4.
  97. Matrix3x4 ReadMatrix3x4();
  98. /// Read a Matrix4.
  99. Matrix4 ReadMatrix4();
  100. /// Read a color.
  101. Color ReadColor();
  102. /// Read a bounding box.
  103. BoundingBox ReadBoundingBox();
  104. /// Read a null-terminated string.
  105. String ReadString();
  106. /// Read a four-letter file ID.
  107. String ReadFileID();
  108. /// Read a 32-bit StringHash.
  109. StringHash ReadStringHash();
  110. /// Read a buffer with size encoded as VLE.
  111. PODVector<unsigned char> ReadBuffer();
  112. /// Read a resource reference.
  113. ResourceRef ReadResourceRef();
  114. /// Read a resource reference list.
  115. ResourceRefList ReadResourceRefList();
  116. /// Read a variant.
  117. Variant ReadVariant();
  118. /// Read a variant whose type is already known.
  119. Variant ReadVariant(VariantType type);
  120. /// Read a variant vector.
  121. VariantVector ReadVariantVector();
  122. /// Read a string vector.
  123. StringVector ReadStringVector();
  124. /// Read a variant map.
  125. VariantMap ReadVariantMap();
  126. /// Read a variable-length encoded unsigned integer, which can use 29 bits maximum.
  127. unsigned ReadVLE();
  128. /// Read a 24-bit network object ID.
  129. unsigned ReadNetID();
  130. /// Read a text line.
  131. String ReadLine();
  132. protected:
  133. /// Stream position.
  134. unsigned position_;
  135. /// Stream size.
  136. unsigned size_;
  137. };
  138. }