Deserializer.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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. Return actual new position.
  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. /// Set position relative to current position. Return actual new position.
  49. unsigned SeekRelative(int delta);
  50. /// Return current position.
  51. unsigned GetPosition() const { return position_; }
  52. /// Return current position.
  53. unsigned Tell() const { return position_; }
  54. /// Return size.
  55. unsigned GetSize() const { return size_; }
  56. /// Read a 64-bit integer.
  57. long long ReadInt64();
  58. /// Read a 32-bit integer.
  59. int ReadInt();
  60. /// Read a 16-bit integer.
  61. short ReadShort();
  62. /// Read an 8-bit integer.
  63. signed char ReadByte();
  64. /// Read a 64-bit unsigned integer.
  65. unsigned long long ReadUInt64();
  66. /// Read a 32-bit unsigned integer.
  67. unsigned ReadUInt();
  68. /// Read a 16-bit unsigned integer.
  69. unsigned short ReadUShort();
  70. /// Read an 8-bit unsigned integer.
  71. unsigned char ReadUByte();
  72. /// Read a bool.
  73. bool ReadBool();
  74. /// Read a float.
  75. float ReadFloat();
  76. /// Read a double.
  77. double ReadDouble();
  78. /// Read an IntRect.
  79. IntRect ReadIntRect();
  80. /// Read an IntVector2.
  81. IntVector2 ReadIntVector2();
  82. /// Read an IntVector3.
  83. IntVector3 ReadIntVector3();
  84. /// Read a Rect.
  85. Rect ReadRect();
  86. /// Read a Vector2.
  87. Vector2 ReadVector2();
  88. /// Read a Vector3.
  89. Vector3 ReadVector3();
  90. /// Read a Vector3 packed into 3 x 16 bits with the specified maximum absolute range.
  91. Vector3 ReadPackedVector3(float maxAbsCoord);
  92. /// Read a Vector4.
  93. Vector4 ReadVector4();
  94. /// Read a quaternion.
  95. Quaternion ReadQuaternion();
  96. /// Read a quaternion with each component packed in 16 bits.
  97. Quaternion ReadPackedQuaternion();
  98. /// Read a Matrix3.
  99. Matrix3 ReadMatrix3();
  100. /// Read a Matrix3x4.
  101. Matrix3x4 ReadMatrix3x4();
  102. /// Read a Matrix4.
  103. Matrix4 ReadMatrix4();
  104. /// Read a color.
  105. Color ReadColor();
  106. /// Read a bounding box.
  107. BoundingBox ReadBoundingBox();
  108. /// Read a null-terminated string.
  109. String ReadString();
  110. /// Read a four-letter file ID.
  111. String ReadFileID();
  112. /// Read a 32-bit StringHash.
  113. StringHash ReadStringHash();
  114. /// Read a buffer with size encoded as VLE.
  115. PODVector<unsigned char> ReadBuffer();
  116. /// Read a resource reference.
  117. ResourceRef ReadResourceRef();
  118. /// Read a resource reference list.
  119. ResourceRefList ReadResourceRefList();
  120. /// Read a variant.
  121. Variant ReadVariant();
  122. /// Read a variant whose type is already known.
  123. Variant ReadVariant(VariantType type);
  124. /// Read a variant vector.
  125. VariantVector ReadVariantVector();
  126. /// Read a string vector.
  127. StringVector ReadStringVector();
  128. /// Read a variant map.
  129. VariantMap ReadVariantMap();
  130. /// Read a variable-length encoded unsigned integer, which can use 29 bits maximum.
  131. unsigned ReadVLE();
  132. /// Read a 24-bit network object ID.
  133. unsigned ReadNetID();
  134. /// Read a text line.
  135. String ReadLine();
  136. protected:
  137. /// Stream position.
  138. unsigned position_;
  139. /// Stream size.
  140. unsigned size_;
  141. };
  142. }