4 #ifndef MEASUREMENTCONTAINERWITHDIMENSION_H
5 #define MEASUREMENTCONTAINERWITHDIMENSION_H
9 template <
typename container_t, std::
size_t DIM>
26 #ifdef ENABLE_DEBUG_TRACE
27 #define DEBUG_TRACE(a) do { a; } while (0)
29 #define DEBUG_TRACE(a) do { } while (0)
37 template <
typename derived_t,
typename ...T_Container>
44 const derived_t &
derived()
const {
return *
static_cast<const derived_t *
>(
this); }
49 template <std::
size_t N=std::variant_size_v< measurement_container_variant_t > >
50 static constexpr std::size_t
dimMax(std::size_t max_dim=0
ul) {
53 return dimMax<
N-1>(
std::max( this_variant_type::dimension(), max_dim ) );
58 template <
typename container_t, std::
size_t N>
65 template <
typename container_t, std::
size_t N= std::variant_size_v< measurement_container_variant_t > >
71 return countVariants<container_t,
N-1>()+ isSameContainer<container_t, N-1>();
74 template <
typename container_t, std::
size_t N= std::variant_size_v< measurement_container_variant_t > >
80 if constexpr(isSameContainer<container_t, N-1>()) {
85 using this_container_type =
typename this_variant_type::container_type;
86 if constexpr(std::is_base_of_v<container_t, this_container_type>
87 && std::has_virtual_destructor_v<this_container_type> && std::has_virtual_destructor_v<container_t>) {
97 template <std::
size_t N= std::variant_size_v< measurement_container_variant_t > >
101 out <<
N-1 <<
": " <<
typeid(a_type).
name() << std::endl;
107 std::stringstream
msg;
108 msg <<
"Container " <<
a <<
" not in variant:" << std::endl;
110 throw std::runtime_error(
msg.str());
113 template <
typename container_t,
bool check_dimension, std::
size_t N >
120 return this_variant_type();
124 using this_container_type =
typename this_variant_type::container_type ;
125 DEBUG_TRACE( std::cout <<
"DEBUG search option for " <<
typeid(container_t).
name() <<
" (aka " <<
typeid(
a).
name() <<
")"
126 <<
" option: " <<
N <<
" " <<
typeid(this_container_type).
name() <<
" dim " << this_variant_type::dimension()
127 <<
" check dimension ? " << check_dimension <<
" desired dimension " << dimension
129 if constexpr(std::is_same_v<this_container_type, container_t>) {
131 if constexpr(!check_dimension && countVariants<container_t>()==1) {
136 assert( (countVariants<this_container_type,N-1>()) == 0 );
137 DEBUG_TRACE( std::cout <<
"DEBUG --> for " <<
typeid(container_t).
name() <<
" (aka " <<
typeid(
a).
name() <<
")"
138 <<
" foumd unambiguous option: " <<
N <<
" " <<
typeid(this_container_type).
name() <<
" dim " << this_variant_type::dimension()
145 if (this_variant_type::dimension() == dimension) {
146 DEBUG_TRACE( std::cout <<
"DEBUG --> for " <<
typeid(container_t).
name() <<
" (aka " <<
typeid(
a).
name() <<
")"
147 <<
" foumd dimension option: " <<
N <<
" " <<
typeid(this_container_type).
name() <<
" dim " << this_variant_type::dimension()
153 else if constexpr(std::is_base_of_v<container_t, this_container_type>) {
155 if constexpr(std::has_virtual_destructor_v<this_container_type> && std::has_virtual_destructor_v<container_t>) {
158 const this_container_type *derived_container =
dynamic_cast<const this_container_type *
>(&
a);
159 if (derived_container) {
162 if constexpr(!check_dimension) {
166 if constexpr(countVariants<container_t,N-1>() != 0) {
170 DEBUG_TRACE( std::cout <<
"DEBUG --> for " <<
typeid(this_container_type).
name() <<
" (aka " <<
typeid(
a).
name() <<
")"
171 <<
" foumd derived option: " <<
N <<
" " <<
typeid(this_container_type).
name() <<
" dim " << this_variant_type::dimension()
177 if (this_variant_type::dimension() == dimension) {
178 DEBUG_TRACE( std::cout <<
"DEBUG --> for " <<
typeid(this_container_type).
name() <<
" (aka " <<
typeid(
a).
name() <<
")"
179 <<
" derived with dimension option: " <<
N <<
" " <<
typeid(this_container_type).
name()
180 <<
" dim " << this_variant_type::dimension()
192 template <
typename container_t, std::
size_t N>
200 using this_container_type =
typename this_variant_type::container_type;
202 DEBUG_TRACE( std::cout <<
"DEBUG determin dimension for " <<
typeid(container_t).
name() <<
" (aka " <<
typeid(
a).
name() <<
")"
203 <<
" option: " <<
N <<
" " <<
typeid(this_container_type).
name() <<
" dim " << this_variant_type::dimension()
207 DEBUG_TRACE( std::cout <<
"DEBUG get dimension for " <<
typeid(container_t).
name() <<
" (aka " <<
typeid(
a).
name() <<
")"
208 <<
" option: " <<
N <<
" " <<
typeid(this_container_type).
name() <<
" dim " << this_variant_type::dimension()
210 return derived_t::getDimension(
a);
212 else if constexpr(std::is_base_of_v<container_t, this_container_type>) {
213 DEBUG_TRACE( std::cout <<
"DEBUG try get dimension for derived " <<
typeid(container_t).
name() <<
" (aka " <<
typeid(
a).
name() <<
")"
214 <<
" option: " <<
N <<
" " <<
typeid(this_container_type).
name() <<
" dim " << this_variant_type::dimension()
217 if constexpr(std::has_virtual_destructor_v<this_container_type> && std::has_virtual_destructor_v<container_t>) {
221 if constexpr(countVariants<this_container_type>() > 1) {
224 const this_container_type *derived_container =
dynamic_cast<const this_container_type *
>(&
a);
225 if (derived_container) {
226 return derived_t::getDimension(*derived_container);
235 template <
typename container_t, std::
size_t = std::variant_size_v< measurement_container_variant_t > >
237 constexpr
unsigned int variant_multiplicity = countVariants<container_t>();
239 static constexpr std::size_t NVariants = std::variant_size_v< measurement_container_variant_t >;
240 if constexpr( variant_multiplicity == 1) {
241 return getContainerWithDimensionNoAmbiguities<container_t, false, NVariants>(
a);
244 if (variant_multiplicity==0) {
245 if (countDerivedVariants<container_t>(
a) == 1) {
246 return getContainerWithDimensionNoAmbiguities<container_t, false, NVariants>(
a);
249 DEBUG_TRACE( std::cout <<
"DEBUG need to search with dimension check for " <<
typeid(container_t).
name() <<
" (aka " <<
typeid(
a).
name() <<
")"
250 <<
" multiplicity : " << variant_multiplicity <<
" derived " << countDerivedVariants<container_t>(
a)
252 return getContainerWithDimensionNoAmbiguities<container_t, true, NVariants>(
a, getDimensionOfDerivedVariantOption<container_t,NVariants>(
a));
257 template <
typename derived_t,
typename... T_Container>
282 template <
typename container_t>
283 void setContainer(std::size_t container_index,
const container_t &container) {
289 && std::get<0>(
m_containerList[container_index]).containerPtr() ==
nullptr) {
291 std::runtime_error(
"Unhandled measurement type");