codac 1.5.6
Loading...
Searching...
No Matches
codac2_CtcInter.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <type_traits>
13#include "codac2_CtcWrapper.h"
14#include "codac2_Collection.h"
16
17namespace codac2
18{
19 template<typename... X>
20 class CtcInter : public Ctc<CtcInter<X...>,X...>
21 {
22 public:
23
24 explicit CtcInter(Index n)
25 : Ctc<CtcInter<X...>,X...>(n)
26 {
27 if constexpr(std::is_same_v<X...,Interval>)
28 {
29 assert(n == 1);
30 }
31 }
32
33 template<typename C>
34 requires (IsCtcBaseOrPtr<C,X...> && !std::is_same_v<CtcInter<X...>,C>)
35 CtcInter(const C& c)
36 : Ctc<CtcInter<X...>,X...>(size_of(c)), _ctcs(c)
37 { }
38
39 template<typename... C>
40 requires (IsCtcBaseOrPtr<C,X...> && ...)
41 CtcInter(const C&... c)
42 : Ctc<CtcInter<X...>,X...>(size_first_item(c...)), _ctcs(c...)
43 {
44 assert_release(all_same_size(c...));
45 }
46
47 template<typename X_> // single type
48 void contract_impl(X_& x) const
49 {
50 for(const auto& ci : _ctcs)
51 {
52 ci->contract(x);
53 if(x.is_empty())
54 return;
55 }
56 }
57
58 void contract(X&... x) const
59 {
60 // contract_impl(..) method for multiple types is not yet implemented
61 contract_impl(x...);
62 }
63
64 template<typename C>
65 requires std::is_base_of_v<CtcBase<X...>,C>
66 CtcInter<X...>& operator&=(const C& c)
67 {
68 assert_release(c.size() == this->size());
69 _ctcs.push_object_back(c);
70 return *this;
71 }
72
73 CtcInter<X...>& operator&=(const std::shared_ptr<CtcBase<X...>>& c)
74 {
75 assert_release(c->size() == this->size());
76 _ctcs.push_back(c);
77 return *this;
78 }
79
80 protected:
81
82 Collection<CtcBase<X...>> _ctcs;
83 };
84
85 template <>
86 class CtcInter<> : public CtcInter<IntervalVector>
87 { };
88
89 template<typename Tuple>
90 struct CtcInterType;
91
92 template<typename... T>
93 struct CtcInterType<std::tuple<T...>> {
94 using Ctc = CtcInter<T...>;
95 };
96
97 template<typename C1, typename C2>
98 typename CtcInterType<typename C1::ContractedTypes>::Ctc operator&(const C1& c1, const C2& c2)
99 {
100 return { c1, c2 };
101 }
102
103 template<typename C2>
104 requires std::is_base_of_v<CtcBase<IntervalVector>,C2>
105 inline CtcInter<IntervalVector> operator&(const IntervalVector& c1, const C2& c2)
106 {
107 assert_release(c1.size() == c2.size());
108 return CtcInter<IntervalVector>(CtcWrapper(c1),c2);
109 }
110
111 template<typename C1>
112 requires std::is_base_of_v<CtcBase<IntervalVector>,C1>
113 inline CtcInter<IntervalVector> operator&(const C1& c1, const IntervalVector& c2)
114 {
115 assert_release(c1.size() == c2.size());
116 return CtcInter<IntervalVector>(c1,CtcWrapper(c2));
117 }
118}