Serializer.h 4.6 KB

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