ObjectStream.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-FileCopyrightText: 2021 Jorrit Rouwe
  2. // SPDX-License-Identifier: MIT
  3. #pragma once
  4. #include <Jolt/Core/StaticArray.h>
  5. #include <Jolt/Core/Reference.h>
  6. #include <Jolt/ObjectStream/SerializableAttribute.h>
  7. JPH_NAMESPACE_BEGIN
  8. /// Base class for object stream input and output streams.
  9. class ObjectStream
  10. {
  11. public:
  12. /// Stream type
  13. enum class EStreamType
  14. {
  15. Text,
  16. Binary,
  17. };
  18. protected:
  19. /// Constructor
  20. virtual ~ObjectStream() = default;
  21. /// Identifier for objects
  22. using Identifier = uint32;
  23. static constexpr int sVersion = 1;
  24. static constexpr int sRevision = 0;
  25. static constexpr Identifier sNullIdentifier = 0;
  26. };
  27. // Define macro to declare functions for a specific primitive type
  28. #define JPH_DECLARE_PRIMITIVE(name) \
  29. bool OSIsType(name *, int inArrayDepth, EOSDataType inDataType, const char *inClassName);
  30. // This file uses the JPH_DECLARE_PRIMITIVE macro to define all types
  31. #include <Jolt/ObjectStream/ObjectStreamTypes.h>
  32. // Define serialization templates
  33. template <class T>
  34. bool OSIsType(vector<T> *, int inArrayDepth, EOSDataType inDataType, const char *inClassName)
  35. {
  36. return (inArrayDepth > 0 && OSIsType((T *)nullptr, inArrayDepth - 1, inDataType, inClassName));
  37. }
  38. template <class T, uint N>
  39. bool OSIsType(StaticArray<T, N> *, int inArrayDepth, EOSDataType inDataType, const char *inClassName)
  40. {
  41. return (inArrayDepth > 0 && OSIsType((T *)nullptr, inArrayDepth - 1, inDataType, inClassName));
  42. }
  43. template <class T, uint N>
  44. bool OSIsType(T (*)[N], int inArrayDepth, EOSDataType inDataType, const char *inClassName)
  45. {
  46. return (inArrayDepth > 0 && OSIsType((T *)nullptr, inArrayDepth - 1, inDataType, inClassName));
  47. }
  48. template <class T>
  49. bool OSIsType(Ref<T> *, int inArrayDepth, EOSDataType inDataType, const char *inClassName)
  50. {
  51. return OSIsType((T *)nullptr, inArrayDepth, inDataType, inClassName);
  52. }
  53. template <class T>
  54. bool OSIsType(RefConst<T> *, int inArrayDepth, EOSDataType inDataType, const char *inClassName)
  55. {
  56. return OSIsType((T *)nullptr, inArrayDepth, inDataType, inClassName);
  57. }
  58. JPH_NAMESPACE_END