HALDLS
traits.h
Go to the documentation of this file.
1 #pragma once
2 #include "fisch/vx/traits.h"
3 #include "fisch/vx/word_access_type.h"
4 #include "haldls/vx/genpybind.h"
5 #include "hate/type_list.h"
6 #include "hate/visibility.h"
7 #include <type_traits>
8 #include <boost/utility/enable_if.hpp>
9 #include <boost/variant.hpp>
10 
12 
16 class GENPYBIND(visible) DifferentialWriteTrait
17 {};
18 
22 enum class GENPYBIND(visible) Backend
23 {
24 #define PLAYBACK_CONTAINER(Name, Type) Name,
25 #define LAST_PLAYBACK_CONTAINER(Name, Type) Name
26 #include "fisch/vx/container.def"
27 };
28 
29 typedef hate::type_list<
30 #define PLAYBACK_CONTAINER(Name, Type) fisch::vx::word_access_type::Name,
31 #define LAST_PLAYBACK_CONTAINER(Name, Type) fisch::vx::word_access_type::Name
32 #include "fisch/vx/container.def"
33  >
35 
36 namespace detail {
37 
38 template <typename BackendContainer>
40 {
41  constexpr static Backend backend = static_cast<Backend>(
42  hate::index_type_list_by_type<BackendContainer, BackendContainerList>::value);
43 };
44 
45 template <Backend B>
47 {
48  typedef
49  typename hate::index_type_list_by_integer<static_cast<size_t>(B), BackendContainerList>::
51 };
52 
53 template <typename T, size_t N>
54 constexpr bool is_in_array(std::array<T, N> const& arr, T const& test)
55 {
56  for (auto a : arr) {
57  if (a == test) {
58  return true;
59  }
60  }
61  return false;
62 }
63 
72 template <
73  typename ContainerT,
74  typename DefaultBackendContainer,
75  typename... AdditionalBackendContainer>
77 {
78  typedef hate::type_list<DefaultBackendContainer, AdditionalBackendContainer...> container_list;
79  typedef DefaultBackendContainer default_container;
80 
81  constexpr static Backend default_backend =
83 
84  constexpr static std::array<Backend, sizeof...(AdditionalBackendContainer) + 1> valid_backends{
87 
88  template <typename TL>
90 
91  template <typename... Ts>
92  struct generate_lookup_table<hate::type_list<Ts...>>
93  {
94  typedef std::array<Backend, sizeof...(Ts)> table_type;
95 
96  template <size_t I, size_t... Is>
97  constexpr static table_type gen(table_type table, std::index_sequence<I, Is...>)
98  {
99  if constexpr (hate::is_in_type_list<
100  typename hate::index_type_list_by_integer<
101  I, BackendContainerList>::type,
102  container_list>::value) {
103  table[I] = static_cast<Backend>(
104  hate::index_type_list_by_type<
105  typename hate::index_type_list_by_integer<I, BackendContainerList>::type,
106  container_list>::value);
107  } else {
108  table[I] = static_cast<Backend>(0);
109  }
110  if constexpr (sizeof...(Is) != 0) {
111  return gen(table, std::index_sequence<Is...>());
112  } else {
113  return table;
114  }
115  }
116 
117  constexpr static auto backend_index_lookup_table =
118  gen(table_type(), std::make_index_sequence<sizeof...(Ts)>());
119  };
120 
121  constexpr static auto backend_index_lookup_table =
123 
124  constexpr static bool valid(Backend backend) { return is_in_array(valid_backends, backend); }
125 };
126 
127 template <typename ContainerT>
128 struct BackendContainerTrait : public BackendContainerBase<ContainerT, ContainerT>
129 {};
130 
131 } // namespace detail
132 
133 
134 template <typename T, typename = void>
135 struct HasLocalData : public std::false_type
136 {};
137 
138 template <typename T>
139 struct HasLocalData<T, typename boost::enable_if_has_type<typename T::has_local_data>::type>
140  : public T::has_local_data
141 {};
142 
143 template <typename T>
144 struct HasLocalData<T, typename boost::enable_if_has_type<typename T::is_leaf_node>::type>
145  : public T::is_leaf_node
146 {};
147 
148 } // namespace haldls::vx
Trait signalling derived-from container type support differential write operation.
Definition: traits.h:17
#define GENPYBIND_TAG_HALDLS_VX
Definition: genpybind.h:4
constexpr bool is_in_array(std::array< T, N > const &arr, T const &test)
Definition: traits.h:54
Backend
Possible backends to target with PlaybackProgramBuilder::read/write.
Definition: traits.h:23
hate::type_list<#define PLAYBACK_CONTAINER(Name, Type) #define LAST_PLAYBACK_CONTAINER(Name, Type) > BackendContainerList
Definition: traits.h:34
constexpr static table_type gen(table_type table, std::index_sequence< I, Is... >)
Definition: traits.h:97
Backend container trait base.
Definition: traits.h:77
hate::type_list< DefaultBackendContainer, AdditionalBackendContainer... > container_list
Definition: traits.h:78
DefaultBackendContainer default_container
Definition: traits.h:79
constexpr static bool valid(Backend backend)
Definition: traits.h:124
hate::index_type_list_by_integer< static_cast< size_t >B), BackendContainerList >::type container_type
Definition: traits.h:50