SimpleSerialize.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include "TimeValue.h"
  10. #include <ISerialize.h> // <> required for Interfuscator
  11. template<bool READING, ESerializationTarget TARGET>
  12. class CSimpleSerializeImpl
  13. {
  14. public:
  15. CSimpleSerializeImpl()
  16. : m_failed(false)
  17. {
  18. }
  19. ILINE bool IsReading() const
  20. {
  21. return READING;
  22. }
  23. ILINE void BeginGroup(const char* szName)
  24. {
  25. }
  26. ILINE void EndGroup()
  27. {
  28. }
  29. ILINE bool Ok() const
  30. {
  31. return !m_failed;
  32. }
  33. protected:
  34. ILINE void Failed()
  35. {
  36. m_failed = true;
  37. }
  38. private:
  39. bool m_failed;
  40. };
  41. template<class Impl>
  42. class CSimpleSerialize : public ISerialize
  43. {
  44. public:
  45. ILINE CSimpleSerialize(Impl& impl)
  46. : m_impl(impl)
  47. {
  48. }
  49. void BeginGroup(const char* szName) override
  50. {
  51. m_impl.BeginGroup(szName);
  52. }
  53. bool BeginOptionalGroup(const char* szName, bool condition) override
  54. {
  55. return m_impl.BeginOptionalGroup(szName, condition);
  56. }
  57. void EndGroup() override
  58. {
  59. m_impl.EndGroup();
  60. }
  61. bool IsReading() const override
  62. {
  63. return m_impl.IsReading();
  64. }
  65. void WriteStringValue(const char* name, SSerializeString& value) override
  66. {
  67. m_impl.Value(name, value);
  68. }
  69. void ReadStringValue(const char* name, SSerializeString& curValue) override
  70. {
  71. m_impl.Value(name, curValue);
  72. }
  73. #define SERIALIZATION_TYPE(T) \
  74. void Value(const char* name, T& x) override \
  75. { \
  76. m_impl.Value(name, x); \
  77. }
  78. #include "SerializationTypes.h"
  79. #undef SERIALIZATION_TYPE
  80. Impl* GetInnerImpl()
  81. {
  82. return &m_impl;
  83. }
  84. protected:
  85. Impl& m_impl;
  86. };
  87. //////////////////////////////////////////////////////////////////////////
  88. // Support serialization with default values,
  89. // Require Implementation serialization stub to have Value() method returning boolean.
  90. //////////////////////////////////////////////////////////////////////////
  91. template<class Impl>
  92. using CSimpleSerializeWithDefaults = CSimpleSerialize<Impl>;