QGearsLGPArchiveSerializer.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 "QGearsSerializer.h"
  17. #include "QGearsLGPArchive.h"
  18. namespace QGears{
  19. /**
  20. * Manages LGP archives serialization.
  21. */
  22. class LGPArchiveSerializer : public Serializer{
  23. public:
  24. /**
  25. * Constructor.
  26. */
  27. LGPArchiveSerializer();
  28. /**
  29. * Destructor.
  30. */
  31. virtual ~LGPArchiveSerializer();
  32. /**
  33. * Imports an A file.
  34. *
  35. * @param stream[in] The contents of the archive.
  36. * @param dest[out] The formed LGP archive file.
  37. */
  38. virtual void ImportLGPArchive(
  39. Ogre::DataStreamPtr &stream, LGPArchive* dest
  40. );
  41. enum {
  42. /**
  43. * Magic MIME string length.
  44. */
  45. MAGIC_STRING_LENGTH = 10,
  46. /**
  47. * Max file name length.
  48. */
  49. FILE_NAME_LENGTH = 20
  50. };
  51. typedef LGPArchive::FileEntry FileEntry;
  52. typedef LGPArchive::FileList FileList;
  53. protected:
  54. /**
  55. * Reads an archive header and sets the instance data.
  56. *
  57. * @param stream[in] The contents of the LGP archive.
  58. */
  59. virtual void ReadFileHeader(Ogre::DataStreamPtr &stream);
  60. /**
  61. * Reads an object as a LGP archive.
  62. *
  63. * @param stream[in] Input data.
  64. * @param file_entry[out] The formed LGP archive.
  65. */
  66. virtual void readObject(
  67. Ogre::DataStreamPtr &stream, FileEntry& file_entry
  68. );
  69. template<typename ValueType> void ReadVector(
  70. Ogre::DataStreamPtr &stream, std::vector<ValueType> &dest,
  71. size_t count
  72. ){
  73. dest.clear();
  74. dest.reserve( count );
  75. for (size_t i(count); i --;){
  76. ValueType in_tmp;
  77. readObject(stream, in_tmp);
  78. dest.push_back(in_tmp);
  79. }
  80. }
  81. };
  82. }