Split.hpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. ///
  2. /// \file Archive/Split.hpp
  3. ///
  4. /// Serialization dispatch macros for separate save/load.
  5. ///
  6. /// \copyright
  7. /// Copyright (c) 2016-2017 Josh Blum
  8. /// SPDX-License-Identifier: BSL-1.0
  9. ///
  10. #pragma once
  11. #include <Pothos/Config.hpp>
  12. #include <Pothos/Archive/Invoke.hpp>
  13. #include <type_traits>
  14. /*!
  15. * Declare a serialize() function that can dispatch to
  16. * an individually declared save and load function.
  17. * Call in the outside scope, no namespaces or functions.
  18. */
  19. #define POTHOS_SERIALIZATION_SPLIT_FREE(T) \
  20. namespace Pothos { namespace serialization { \
  21. template <typename Archive> \
  22. void serialize(Archive &ar, T &t, const unsigned int ver) { \
  23. Pothos::serialization::invokeSplit(ar, t, ver); \
  24. } \
  25. }}
  26. /*!
  27. * Declare a serialize() function that can dispatch to
  28. * individually declared save and load member functions.
  29. * Call in the public part of a struct or class declaration.
  30. */
  31. #define POTHOS_SERIALIZATION_SPLIT_MEMBER() \
  32. template <typename Archive> \
  33. typename std::enable_if<Archive::isSave::value>::type \
  34. serialize(Archive &ar, const unsigned int ver) { \
  35. this->save(ar, ver); \
  36. } \
  37. template <typename Archive> \
  38. typename std::enable_if<!Archive::isSave::value>::type \
  39. serialize(Archive &ar, const unsigned int ver) { \
  40. this->load(ar, ver); \
  41. }