Serializer.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. //
  2. // Urho3D Engine
  3. // Copyright (c) 2008-2011 Lasse Öörni
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include "Map.h"
  25. #include "StringHash.h"
  26. class Color;
  27. class IntRect;
  28. class IntVector2;
  29. class Quaternion;
  30. class Rect;
  31. class Variant;
  32. class Vector2;
  33. class Vector3;
  34. class Vector4;
  35. struct ResourceRef;
  36. struct ResourceRefList;
  37. typedef Vector<Variant> VariantVector;
  38. typedef Map<ShortStringHash, Variant> VariantMap;
  39. /// Abstract stream for writing.
  40. class Serializer
  41. {
  42. public:
  43. /// Destruct.
  44. virtual ~Serializer();
  45. /// Write bytes to the stream. Return number of bytes actually written.
  46. virtual unsigned Write(const void* data, unsigned size) = 0;
  47. /// Write a 32-bit integer.
  48. bool WriteInt(int value);
  49. /// Write a 16-bit integer.
  50. bool WriteShort(short value);
  51. /// Write an 8-bit integer.
  52. bool WriteByte(signed char value);
  53. /// Write a 32-bit unsigned integer.
  54. bool WriteUInt(unsigned value);
  55. /// Write a 16-bit unsigned integer.
  56. bool WriteUShort(unsigned short value);
  57. /// Write an 8-bit unsigned integer.
  58. bool WriteUByte(unsigned char value);
  59. /// Write a bool.
  60. bool WriteBool(bool value);
  61. /// Write a float.
  62. bool WriteFloat(float 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 color.
  82. bool WriteColor(const Color& value);
  83. /// Write a bounding box.
  84. bool WriteBoundingBox(const BoundingBox& value);
  85. /// Write a null-terminated string.
  86. bool WriteString(const String& value);
  87. /// Write a four-letter file ID. If the string is not long enough, spaces will be appended.
  88. bool WriteFileID(const String& value);
  89. /// Write a 32-bit StringHash.
  90. bool WriteStringHash(const StringHash& value);
  91. /// Write a 16-bit ShortStringHash.
  92. bool WriteShortStringHash(const ShortStringHash& value);
  93. /// Write a buffer, with size encoded as VLE.
  94. bool WriteBuffer(const PODVector<unsigned char>& buffer);
  95. /// Write a resource reference.
  96. bool WriteResourceRef(const ResourceRef& value);
  97. /// Write a resource reference list.
  98. bool WriteResourceRefList(const ResourceRefList& value);
  99. /// Write a variant.
  100. bool WriteVariant(const Variant& value);
  101. /// Write a variant without the type information.
  102. bool WriteVariantData(const Variant& value);
  103. /// Write a variant vector.
  104. bool WriteVariantVector(const VariantVector& value);
  105. /// Write a variant map.
  106. bool WriteVariantMap(const VariantMap& value);
  107. /// Write a variable-length encoded unsigned integer, which can use 29 bits maximum.
  108. bool WriteVLE(unsigned value);
  109. /// Write a 24-bit network object ID.
  110. bool WriteNetID(unsigned value);
  111. /// Write a text line. Char codes 13 & 10 will be automatically appended.
  112. bool WriteLine(const String& value);
  113. };