codac 2.0.0
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=IntervalVector>
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 void contract(X& x) const
48 {
49 for(const auto& ci : _ctcs)
50 {
51 ci->contract(x);
52 if(x.is_empty())
53 return;
54 }
55 }
56
57 template<typename C>
58 requires std::is_base_of_v<CtcBase<X>,C>
59 CtcInter<X>& operator&=(const C& c)
60 {
61 assert_release(c.size() == this->size());
62 _ctcs.push_object_back(c);
63 return *this;
64 }
65
66 CtcInter<X>& operator&=(const std::shared_ptr<CtcBase<X>>& c)
67 {
68 assert_release(c->size() == this->size());
69 _ctcs.push_back(c);
70 return *this;
71 }
72
73 protected:
74
75 Collection<CtcBase<X>> _ctcs;
76 };
77
78 template<typename C1, typename C2>
79 requires (std::is_same_v<typename C1::ContractedType,typename C2::ContractedType>
80 && std::is_base_of_v<CtcBase<typename C1::ContractedType>,C1>
81 && std::is_base_of_v<CtcBase<typename C1::ContractedType>,C2>)
82 inline CtcInter<typename C1::ContractedType> operator&(const C1& c1, const C2& c2)
83 {
84 return CtcInter<typename C1::ContractedType>(c1,c2);
85 }
86
87 template<typename C2>
88 requires std::is_base_of_v<CtcBase<IntervalVector>,C2>
89 inline CtcInter<IntervalVector> operator&(const IntervalVector& c1, const C2& c2)
90 {
91 assert_release(c1.size() == c2.size());
92 return CtcInter<IntervalVector>(CtcWrapper(c1),c2);
93 }
94
95 template<typename C1>
96 requires std::is_base_of_v<CtcBase<IntervalVector>,C1>
97 inline CtcInter<IntervalVector> operator&(const C1& c1, const IntervalVector& c2)
98 {
99 assert_release(c1.size() == c2.size());
100 return CtcInter<IntervalVector>(c1,CtcWrapper(c2));
101 }
102}