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