madness.h
Go to the documentation of this file.
1 //
2 // Created by Eduard Valeyev on 5/3/21.
3 //
4 
5 #ifndef TTG_SERIALIZATION_MADNESS_H
6 #define TTG_SERIALIZATION_MADNESS_H
7 
8 #include <type_traits>
9 
10 #ifdef TTG_SERIALIZATION_SUPPORTS_MADNESS
11 #include <madness/world/archive.h>
12 #include <madness/world/buffer_archive.h>
13 #include <madness/world/type_traits.h>
14 #endif
15 
17 
18 namespace ttg::detail {
19 
20  /*----- if_madness_{input,output,}_archive_v -----*/
21 
22 #ifdef TTG_SERIALIZATION_SUPPORTS_MADNESS
23  template <typename T>
24  inline constexpr bool is_madness_archive_v = madness::is_archive_v<T>;
25  template <typename T>
26  inline constexpr bool is_madness_input_archive_v = madness::is_input_archive_v<T>;
27 
28  template <typename T>
29  inline constexpr bool is_madness_output_archive_v = madness::is_output_archive_v<T>;
30 
31  /*----- is_archive_v for madness archives -----*/
32  template <typename T>
33  inline constexpr bool is_archive_v<T, std::enable_if_t<is_madness_archive_v<T>>> = true;
34  template <typename T>
35  inline constexpr bool is_input_archive_v<T, std::enable_if_t<is_madness_input_archive_v<T>>> = true;
36  template <typename T>
37  inline constexpr bool is_output_archive_v<T, std::enable_if_t<is_madness_output_archive_v<T>>> = true;
38 
39 #else // TTG_SERIALIZATION_SUPPORTS_MADNESS
40  template <typename T>
41  inline constexpr bool is_madness_archive_v = false;
42  template <typename T>
43  inline constexpr bool is_madness_input_archive_v = false;
44  template <typename T>
45  inline constexpr bool is_madness_output_archive_v = false;
46 #endif // TTG_SERIALIZATION_SUPPORTS_MADNESS
47 
48  /*----- is_madness_{input,output}_serializable_v -----*/
49 
50  template <typename Archive, typename T, class = void>
51  struct is_madness_output_serializable : std::false_type {};
52 
53 #ifdef TTG_SERIALIZATION_SUPPORTS_MADNESS
54  template <typename Archive, typename T>
56  Archive, T, std::enable_if_t<madness::is_output_archive_v<Archive> && madness::is_serializable_v<Archive, T>>>
57  : std::true_type {};
58 #endif // TTG_SERIALIZATION_SUPPORTS_MADNESS
59 
60  template <typename Archive, typename T>
61  inline static constexpr bool is_madness_output_serializable_v = is_madness_output_serializable<Archive, T>::value;
62 
63  template <typename Archive, typename T, class = void>
64  struct is_madness_input_serializable : std::false_type {};
65 
66 #ifdef TTG_SERIALIZATION_SUPPORTS_MADNESS
67  template <typename Archive, typename T>
69  Archive, T, std::enable_if_t<madness::is_input_archive_v<Archive> && madness::is_serializable_v<Archive, T>>>
70  : std::true_type {};
71 #endif // TTG_SERIALIZATION_SUPPORTS_MADNESS
72 
73  template <typename Archive, typename T>
74  inline static constexpr bool is_madness_input_serializable_v = is_madness_input_serializable<Archive, T>::value;
75 
76  template <typename Archive, typename T>
77  inline static constexpr bool is_madness_serializable_v =
78  is_madness_input_serializable_v<Archive, T> || is_madness_output_serializable_v<Archive, T>;
79 
80  template <typename T, class = void>
81  struct is_madness_buffer_serializable : std::false_type {};
82 
83 #ifdef TTG_SERIALIZATION_SUPPORTS_MADNESS
84  template <typename T>
86  T, std::enable_if_t<is_madness_input_serializable_v<madness::archive::BufferInputArchive, T> &&
87  is_madness_output_serializable_v<madness::archive::BufferOutputArchive, T>>>
88  : std::true_type {};
89 #endif
90 
92  template <typename T>
94 
95  template <typename T, class = void>
96  struct is_madness_user_buffer_serializable : std::false_type {};
97 
98 #ifdef TTG_SERIALIZATION_SUPPORTS_MADNESS
99  template <typename T>
101  T, std::enable_if_t<madness::is_user_serializable_v<madness::archive::BufferInputArchive, T> &&
102  madness::is_user_serializable_v<madness::archive::BufferOutputArchive, T>>> : std::true_type {
103  };
104 #endif
105 
107  template <typename T>
109 
110 } // namespace ttg::detail
111 
112 #endif // TTG_SERIALIZATION_MADNESS_H
constexpr bool is_madness_output_archive_v
Definition: madness.h:45
constexpr bool is_madness_archive_v
Definition: madness.h:41
constexpr bool is_madness_input_archive_v
Definition: madness.h:43
constexpr bool is_madness_user_buffer_serializable_v
evaluates to true if can serialize T to/from buffer using user-provided MADNESS serialization
Definition: madness.h:108
constexpr bool is_madness_buffer_serializable_v
evaluates to true if can serialize T to/from buffer using MADNESS serialization
Definition: madness.h:93