Pothos  0.5.0-ga4964040
The Pothos dataflow programming software suite
Invoke.hpp
Go to the documentation of this file.
1 
12 #pragma once
13 #include <Pothos/Config.hpp>
14 #include <type_traits>
15 #include <utility> //std::declval
16 
17 namespace Pothos {
18 namespace serialization {
19 
25  {
26  public:
27  VersionType(const unsigned int ver):
28  ver(ver)
29  {
30  return;
31  }
32 
33  operator const unsigned int &(void) const
34  {
35  return ver;
36  }
37 
38  operator unsigned int &(void)
39  {
40  return ver;
41  }
42 
43  private:
44  unsigned int ver;
45  };
46 
51  template <typename T, typename Archive>
52  struct hasSerialize
53  {
54  template <typename U>
55  static auto test(U* p) -> decltype(p->serialize(std::declval<Archive&>(), std::declval<const unsigned int>()));
56 
57  template <typename U>
58  static auto test(...) -> std::false_type;
59 
60  using type = typename std::is_same<decltype(test<T>(nullptr)), void>::type;
61  static const auto value = type::value;
62  };
63 
67  template <typename Archive, typename T>
68  typename std::enable_if<std::is_same<typename Archive::isSave, std::true_type>::value>::type
69  invokeSplit(Archive &ar, T &value, const unsigned int ver)
70  {
71  const VersionType vt(ver);
72  save(ar, value, vt);
73  }
74 
78  template <typename Archive, typename T>
79  typename std::enable_if<std::is_same<typename Archive::isSave, std::false_type>::value>::type
80  invokeSplit(Archive &ar, T &value, const unsigned int ver)
81  {
82  const VersionType vt(ver);
83  load(ar, value, vt);
84  }
85 
89  template <typename Archive, typename T>
90  typename std::enable_if<!hasSerialize<T, Archive>::value>::type
91  invokeSerialize(Archive &ar, T &value, const unsigned int ver)
92  {
93  const VersionType vt(ver);
94  serialize(ar, value, vt);
95  }
96 
100  template <typename Archive, typename T>
101  typename std::enable_if<hasSerialize<T, Archive>::value>::type
102  invokeSerialize(Archive &ar, T &value, const unsigned int ver)
103  {
104  value.serialize(ar, ver);
105  }
106 
107 } //namespace serialization
108 } //namespace Pothos
typename std::is_same< decltype(test< T >(nullptr)), void >::type type
Definition: Invoke.hpp:60
VersionType(const unsigned int ver)
Definition: Invoke.hpp:27
Definition: ArchiveEntry.hpp:20
std::enable_if<!hasSerialize< T, Archive >::value >::type invokeSerialize(Archive &ar, T &value, const unsigned int ver)
Definition: Invoke.hpp:91
void save(Archive &ar, const std::complex< T > &t, const unsigned int)
Definition: Complex.hpp:20
void serialize(Archive &ar, std::complex< T > &t, const unsigned int ver)
Definition: Complex.hpp:37
Definition: Invoke.hpp:52
Definition: Invoke.hpp:24
std::enable_if< std::is_same< typename Archive::isSave, std::true_type >::value >::type invokeSplit(Archive &ar, T &value, const unsigned int ver)
Definition: Invoke.hpp:69
void load(Archive &ar, std::complex< T > &t, const unsigned int)
Definition: Complex.hpp:27