Deserializer.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // Copyright (c) 2008-2020 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 Urho3D
  27. {
  28. /// Abstract stream for reading.
  29. /// @fakeref
  30. class URHO3D_API Deserializer
  31. {
  32. public:
  33. /// Construct with zero size.
  34. Deserializer();
  35. /// Construct with defined size.
  36. explicit Deserializer(unsigned size);
  37. /// Destruct.
  38. virtual ~Deserializer();
  39. /// Read bytes from the stream. Return number of bytes actually read.
  40. virtual unsigned Read(void* dest, unsigned size) = 0;
  41. /// Set position from the beginning of the stream. Return actual new position.
  42. virtual unsigned Seek(unsigned position) = 0;
  43. /// Return name of the stream.
  44. /// @property
  45. virtual const String& GetName() const;
  46. /// Return a checksum if applicable.
  47. /// @property
  48. virtual unsigned GetChecksum();
  49. /// Return whether the end of stream has been reached.
  50. /// @property
  51. virtual bool IsEof() const { return position_ >= size_; }
  52. /// Set position relative to current position. Return actual new position.
  53. unsigned SeekRelative(int delta);
  54. /// Return current position.
  55. /// @property
  56. unsigned GetPosition() const { return position_; }
  57. /// Return current position.
  58. unsigned Tell() const { return position_; }
  59. /// Return size.
  60. /// @property
  61. unsigned GetSize() const { return size_; }
  62. /// Read a 64-bit integer.
  63. long long ReadInt64();
  64. /// Read a 32-bit integer.
  65. int ReadInt();
  66. /// Read a 16-bit integer.
  67. short ReadShort();
  68. /// Read an 8-bit integer.
  69. signed char ReadByte();
  70. /// Read a 64-bit unsigned integer.
  71. unsigned long long ReadUInt64();
  72. /// Read a 32-bit unsigned integer.
  73. unsigned ReadUInt();
  74. /// Read a 16-bit unsigned integer.
  75. unsigned short ReadUShort();
  76. /// Read an 8-bit unsigned integer.
  77. unsigned char ReadUByte();
  78. /// Read a bool.
  79. bool ReadBool();
  80. /// Read a float.
  81. float ReadFloat();
  82. /// Read a double.
  83. double ReadDouble();
  84. /// Read an IntRect.
  85. IntRect ReadIntRect();
  86. /// Read an IntVector2.
  87. IntVector2 ReadIntVector2();
  88. /// Read an IntVector3.
  89. IntVector3 ReadIntVector3();
  90. /// Read a Rect.
  91. Rect ReadRect();
  92. /// Read a Vector2.
  93. Vector2 ReadVector2();
  94. /// Read a Vector3.
  95. Vector3 ReadVector3();
  96. /// Read a Vector3 packed into 3 x 16 bits with the specified maximum absolute range.
  97. Vector3 ReadPackedVector3(float maxAbsCoord);
  98. /// Read a Vector4.
  99. Vector4 ReadVector4();
  100. /// Read a quaternion.
  101. Quaternion ReadQuaternion();
  102. /// Read a quaternion with each component packed in 16 bits.
  103. Quaternion ReadPackedQuaternion();
  104. /// Read a Matrix3.
  105. Matrix3 ReadMatrix3();
  106. /// Read a Matrix3x4.
  107. Matrix3x4 ReadMatrix3x4();
  108. /// Read a Matrix4.
  109. Matrix4 ReadMatrix4();
  110. /// Read a color.
  111. Color ReadColor();
  112. /// Read a bounding box.
  113. BoundingBox ReadBoundingBox();
  114. /// Read a null-terminated string.
  115. String ReadString();
  116. /// Read a four-letter file ID.
  117. String ReadFileID();
  118. /// Read a 32-bit StringHash.
  119. StringHash ReadStringHash();
  120. /// Read a buffer with size encoded as VLE.
  121. PODVector<unsigned char> ReadBuffer();
  122. /// Read a resource reference.
  123. ResourceRef ReadResourceRef();
  124. /// Read a resource reference list.
  125. ResourceRefList ReadResourceRefList();
  126. /// Read a variant.
  127. Variant ReadVariant();
  128. /// Read a variant whose type is already known.
  129. Variant ReadVariant(VariantType type);
  130. /// Read a variant vector.
  131. VariantVector ReadVariantVector();
  132. /// Read a string vector.
  133. StringVector ReadStringVector();
  134. /// Read a variant map.
  135. VariantMap ReadVariantMap();
  136. /// Read a variable-length encoded unsigned integer, which can use 29 bits maximum.
  137. unsigned ReadVLE();
  138. /// Read a 24-bit network object ID.
  139. unsigned ReadNetID();
  140. /// Read a text line.
  141. String ReadLine();
  142. protected:
  143. /// Stream position.
  144. unsigned position_;
  145. /// Stream size.
  146. unsigned size_;
  147. };
  148. }