codac 2.0.0
Loading...
Searching...
No Matches
codac2_AnalyticExprWrapper.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include "codac2_AnalyticExpr.h"
13#include "codac2_ExprType.h"
15#include "codac2_component.h"
16#include "codac2_subvector.h"
18
19namespace codac2
20{
21 class ScalarVar;
22 class VectorVar;
23
24 template<typename T>
25 struct AnalyticExprWrapper : public std::shared_ptr<AnalyticExpr<T>>
26 {
27 AnalyticExprWrapper(const AnalyticExprWrapper<T>& e)
28 : std::shared_ptr<AnalyticExpr<T>>(e)
29 { }
30
31 AnalyticExprWrapper(const std::shared_ptr<AnalyticExpr<T>>& e)
32 : std::shared_ptr<AnalyticExpr<T>>(e)
33 { }
34
35 AnalyticExprWrapper<T>& operator=(const AnalyticExprWrapper<T>&) = default;
36 AnalyticExprWrapper<T>& operator=(AnalyticExprWrapper<T>&&) noexcept = default;
37
38 template<typename V>
39 requires std::is_base_of_v<AnalyticVarExpr<T>,V>
40 AnalyticExprWrapper(const V& e)
41 : std::shared_ptr<AnalyticExpr<T>>({ std::dynamic_pointer_cast<AnalyticExpr<T>>(e.copy()) })
42 { }
43
44 template<typename C>
45 requires (!std::is_base_of_v<AnalyticVarExpr<T>,C>)
46 AnalyticExprWrapper(const C& e)
47 requires std::is_same_v<typename ExprType<C>::Type,T>
48 : std::shared_ptr<AnalyticExpr<T>>(const_value(e))
49 { }
50
51 inline AnalyticExprWrapper<ScalarType> operator[](Index i) const
52 requires std::is_same_v<T,VectorType>
53 {
54 return { std::make_shared<AnalyticOperationExpr<ComponentOp,ScalarType,VectorType>>(*this,i) };
55 }
56
57 inline AnalyticExprWrapper<VectorType> subvector(Index i, Index j) const
58 requires std::is_same_v<T,VectorType>
59 {
60 return { std::make_shared<AnalyticOperationExpr<SubvectorOp,VectorType,VectorType>>(*this,i,j) };
61 }
62
63 inline AnalyticExprWrapper<ScalarType> operator()(Index i, Index j) const
64 requires std::is_same_v<T,MatrixType>
65 {
66 return { std::make_shared<AnalyticOperationExpr<ComponentOp,ScalarType,MatrixType>>(*this,i,j) };
67 }
68 };
69
70 using ScalarExpr = AnalyticExprWrapper<ScalarType>;
71 using VectorExpr = AnalyticExprWrapper<VectorType>;
72 using MatrixExpr = AnalyticExprWrapper<MatrixType>;
73
74 template<class X>
75 concept IsScalarExprOrVar = (std::is_base_of_v<VarBase,X> || std::is_base_of_v<ScalarExpr,X>);
76
77 template<class X>
78 concept IsVectorExprOrVar = (std::is_base_of_v<VarBase,X> || std::is_base_of_v<VectorExpr,X>);
79
80 template<class X>
81 concept IsMatrixExprOrVar = (std::is_base_of_v<VarBase,X> || std::is_base_of_v<MatrixExpr,X>);
82}
Definition codac2_OctaSym.h:21