QGearsSerializer.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <OgreAxisAlignedBox.h>
  17. #include <OgreColourValue.h>
  18. #include <OgreDataStream.h>
  19. #include <OgreSerializer.h>
  20. #include <Ogre.h>
  21. #include "common/TypeDefine.h"
  22. namespace QGears{
  23. /**
  24. * Handles file serialization.
  25. */
  26. class Serializer : public Ogre::Serializer{
  27. public:
  28. /**
  29. * Constructor.
  30. *
  31. * Determines the endian mode of the file.
  32. */
  33. Serializer();
  34. /**
  35. * Destructor
  36. */
  37. virtual ~Serializer();
  38. // TODO implement some more serialization!?
  39. // ISerializeable readObject(serializer)
  40. // virtual void readObject(ISerializable o) { o.readObject(this); }
  41. // template<T> readObject(T)
  42. protected:
  43. /**
  44. * Reads an object as a 2 dimensional vector.
  45. *
  46. * @param stream[in] Input data.
  47. * @param dest[out] The formed vector data.
  48. */
  49. void readObject(Ogre::DataStreamPtr &stream, Ogre::Vector2 &dest);
  50. /**
  51. * Reads an object as a 3 dimensional vector.
  52. *
  53. * @param stream[in] Input data.
  54. * @param dest[out] The formed vector data.
  55. */
  56. void readObject(Ogre::DataStreamPtr &stream, Ogre::Vector3 &dest);
  57. /**
  58. * Reads an object as an axis aligned box.
  59. *
  60. * Can be used for bounding boxes.
  61. *
  62. * @param stream[in] Input data.
  63. * @param dest[out] The formed box data.
  64. */
  65. void readObject(
  66. Ogre::DataStreamPtr &stream, Ogre::AxisAlignedBox &dest
  67. );
  68. /**
  69. * Reads an object as a pixel.
  70. *
  71. * @param stream[in] Input data.
  72. * @param dest[out] The formed pixel data.
  73. */
  74. void readObject(Ogre::DataStreamPtr &stream, Pixel &dest);
  75. /**
  76. * Reads a stream as text.
  77. *
  78. * @param stream[in] Input data.
  79. * @param dest[out] The read characters will be stored here.
  80. * @param count[in] Read this many characters.
  81. */
  82. void ReadChars(
  83. Ogre::DataStreamPtr& stream, char* dest, size_t count
  84. );
  85. /**
  86. * Reads one byte from a stream and evaluates it as a boolean.
  87. *
  88. * @param stream[in] Input data.
  89. * @param dest[out] The evaluated boolean.
  90. * @todo 1 is true?
  91. */
  92. void Read1ByteBool(Ogre::DataStreamPtr &stream, bool &dest);
  93. /**
  94. * Reads two bytes from a stream and evaluates them as a boolean.
  95. *
  96. * @param stream[in] Input data.
  97. * @param dest[out] The evaluated boolean.
  98. * @todo 1 is true?
  99. */
  100. void Read2ByteBool(Ogre::DataStreamPtr &stream, bool &dest);
  101. /**
  102. * Reads 16 bytes from a stream and evaluates as an unsigned short.
  103. *
  104. * @param stream[in] Input data.
  105. * @param dest[out] The evaluated number.
  106. */
  107. void ReadShort(Ogre::DataStreamPtr &stream, uint16 &dest);
  108. /**
  109. * Reads 16 bytes from a stream and evaluates as a signed integer.
  110. *
  111. * @param stream[in] Input data.
  112. * @param dest[out] The evaluated number.
  113. */
  114. void ReadInt16(Ogre::DataStream &stream, sint16 &dest);
  115. /**
  116. * Reads 16 bytes from a stream and evaluates as an unsigned int.
  117. *
  118. * @param stream[in] Input data.
  119. * @param dest[out] The evaluated number.
  120. */
  121. void ReadUInt16(Ogre::DataStream &stream, uint16 &dest);
  122. /**
  123. * Reads 16 bytes from a stream and evaluates as a signed integer.
  124. *
  125. * @param stream[in] Input data.
  126. * @param dest[out] The evaluated number.
  127. */
  128. void ReadInt16(Ogre::DataStreamPtr &stream, sint16 &dest);
  129. /**
  130. * Reads 16 bytes from a stream and evaluates as an unsigned int.
  131. *
  132. * @param stream[in] Input data.
  133. * @param dest[out] The evaluated number.
  134. */
  135. void ReadUInt16(Ogre::DataStreamPtr &stream, uint16 &dest);
  136. /**
  137. * Reads 32 bytes from a stream and evaluates as an unsigned int.
  138. *
  139. * @param stream[in] Input data.
  140. * @param dest[out] The evaluated number.
  141. */
  142. void ReadUInt32(Ogre::DataStreamPtr &stream, uint32 &dest);
  143. /**
  144. * Reads 32 bytes from a stream and evaluates as a signed int.
  145. *
  146. * @param stream[in] Input data.
  147. * @param dest[out] The evaluated number.
  148. */
  149. void ReadSInt32(Ogre::DataStreamPtr &stream, sint32 &dest);
  150. /**
  151. * Reads 32 bytes from a stream and evaluates as an unsigned int.
  152. *
  153. * @param stream[in] Input data.
  154. * @param dest[out] The evaluated number.
  155. */
  156. void ReadUInt32(Ogre::DataStream &stream, uint32 &dest);
  157. /**
  158. * Reads 8 bytes from a stream and evaluates as an unsigned int.
  159. *
  160. * @param stream[in] Input data.
  161. * @param dest[out] The evaluated number.
  162. */
  163. void ReadUInt8(Ogre::DataStream& stream, uint8 &dest);
  164. /**
  165. * Reads 8 bytes from a stream and evaluates as an unsigned int.
  166. *
  167. * @param stream[in] Input data.
  168. * @param dest[out] The evaluated number.
  169. */
  170. void ReadUInt8(Ogre::DataStreamPtr &stream, uint8 &dest);
  171. /**
  172. * Reads bytes from a stream and evaluates them as a float.
  173. *
  174. * @param stream[in] Input data.
  175. * @param dest[out] The evaluated number.
  176. */
  177. void ReadFloat(Ogre::DataStreamPtr &stream, float &dest);
  178. /**
  179. * @todo Understand and document.
  180. */
  181. void ReadEndString(
  182. Ogre::DataStreamPtr &stream, const String &end_text
  183. );
  184. /**
  185. * @todo Understand and document.
  186. */
  187. String GetLine(Ogre::DataStreamPtr &stream) const;
  188. /**
  189. * A comment tag.
  190. */
  191. static const String TAG_COMMENT;
  192. };
  193. }