Serializer.h 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. //
  2. // Copyright (c) 2008-2015 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 "../Container/HashMap.h"
  24. #include "../Core/Variant.h"
  25. #include "../Math/BoundingBox.h"
  26. #include "../Math/StringHash.h"
  27. namespace Atomic
  28. {
  29. class Color;
  30. class IntRect;
  31. class IntVector2;
  32. class Quaternion;
  33. class Rect;
  34. class Vector2;
  35. class Vector3;
  36. class Vector4;
  37. /// Abstract stream for writing.
  38. class ATOMIC_API Serializer
  39. {
  40. public:
  41. /// Destruct.
  42. virtual ~Serializer();
  43. /// Write bytes to the stream. Return number of bytes actually written.
  44. virtual unsigned Write(const void* data, unsigned size) = 0;
  45. /// Write a 32-bit integer.
  46. bool WriteInt(int value);
  47. /// Write a 16-bit integer.
  48. bool WriteShort(short value);
  49. /// Write an 8-bit integer.
  50. bool WriteByte(signed char value);
  51. /// Write a 32-bit unsigned integer.
  52. bool WriteUInt(unsigned value);
  53. /// Write a 16-bit unsigned integer.
  54. bool WriteUShort(unsigned short value);
  55. /// Write an 8-bit unsigned integer.
  56. bool WriteUByte(unsigned char value);
  57. /// Write a bool.
  58. bool WriteBool(bool value);
  59. /// Write a float.
  60. bool WriteFloat(float value);
  61. /// Write a double.
  62. bool WriteDouble(double value);
  63. /// Write an IntRect.
  64. bool WriteIntRect(const IntRect& value);
  65. /// Write an IntVector2.
  66. bool WriteIntVector2(const IntVector2& value);
  67. /// Write a Rect.
  68. bool WriteRect(const Rect& value);
  69. /// Write a Vector2.
  70. bool WriteVector2(const Vector2& value);
  71. /// Write a Vector3.
  72. bool WriteVector3(const Vector3& value);
  73. /// Write a Vector3 packed into 3 x 16 bits with the specified maximum absolute range.
  74. bool WritePackedVector3(const Vector3& value, float maxAbsCoord);
  75. /// Write a Vector4.
  76. bool WriteVector4(const Vector4& value);
  77. /// Write a quaternion.
  78. bool WriteQuaternion(const Quaternion& value);
  79. /// Write a quaternion with each component packed in 16 bits.
  80. bool WritePackedQuaternion(const Quaternion& value);
  81. /// Write a Matrix3.
  82. bool WriteMatrix3(const Matrix3& value);
  83. /// Write a Matrix3x4.
  84. bool WriteMatrix3x4(const Matrix3x4& value);
  85. /// Write a Matrix4.
  86. bool WriteMatrix4(const Matrix4& value);
  87. /// Write a color.
  88. bool WriteColor(const Color& value);
  89. /// Write a bounding box.
  90. bool WriteBoundingBox(const BoundingBox& value);
  91. /// Write a null-terminated string.
  92. bool WriteString(const String& value);
  93. /// Write a four-letter file ID. If the string is not long enough, spaces will be appended.
  94. bool WriteFileID(const String& value);
  95. /// Write a 32-bit StringHash.
  96. bool WriteStringHash(const StringHash& value);
  97. /// Write a buffer, with size encoded as VLE.
  98. bool WriteBuffer(const PODVector<unsigned char>& buffer);
  99. /// Write a resource reference.
  100. bool WriteResourceRef(const ResourceRef& value);
  101. /// Write a resource reference list.
  102. bool WriteResourceRefList(const ResourceRefList& value);
  103. /// Write a variant.
  104. bool WriteVariant(const Variant& value);
  105. /// Write a variant without the type information.
  106. bool WriteVariantData(const Variant& value);
  107. /// Write a variant vector.
  108. bool WriteVariantVector(const VariantVector& value);
  109. /// Write a variant vector.
  110. bool WriteStringVector(const StringVector& value);
  111. /// Write a variant map.
  112. bool WriteVariantMap(const VariantMap& value);
  113. /// Write a variable-length encoded unsigned integer, which can use 29 bits maximum.
  114. bool WriteVLE(unsigned value);
  115. /// Write a 24-bit network object ID.
  116. bool WriteNetID(unsigned value);
  117. /// Write a text line. Char codes 13 & 10 will be automatically appended.
  118. bool WriteLine(const String& value);
  119. };
  120. }