OASIS
Open Algebra Software
Loading...
Searching...
No Matches
Visit.hpp
Go to the documentation of this file.
1//
2// Created by Matthew McCall on 4/28/24.
3//
4
5#ifndef OASIS_SERIALIZATION_HPP
6#define OASIS_SERIALIZATION_HPP
7
8#include "Expression.hpp"
9
10namespace Oasis {
11
12class Real;
13class Imaginary;
14class Matrix;
15class Variable;
16class Undefined;
17class EulerNumber;
18class Pi;
19
20template <IExpression, IExpression>
21class Add;
22
23template <IExpression MinuendT, IExpression SubtrahendT>
24class Subtract;
25
26template <IExpression MultiplicandT, IExpression MultiplierT>
27class Multiply;
28
29template <IExpression DividendT, IExpression DivisorT>
30class Divide;
31
32template <IExpression BaseT, IExpression PowerT>
33class Exponent;
34
35template <IExpression BaseT, IExpression ArgumentT>
36class Log;
37
38template <typename OperandT>
39class Negate;
40
41template <typename OperandT>
42class Magnitude;
43
44template <IExpression, IExpression>
45class Derivative;
46
47template <IExpression Integrand, IExpression Differential>
48class Integral;
49
50class Visitor {
51public:
52 virtual any Visit(const Real& real) = 0;
53 virtual any Visit(const Imaginary& imaginary) = 0;
54 virtual any Visit(const Matrix& matrix) = 0;
55 virtual any Visit(const Variable& variable) = 0;
56 virtual any Visit(const Undefined& undefined) = 0;
57 virtual any Visit(const EulerNumber&) = 0;
58 virtual any Visit(const Pi&) = 0;
59 virtual any Visit(const Add<Expression, Expression>& add) = 0;
60 virtual any Visit(const Subtract<Expression, Expression>& subtract) = 0;
61 virtual any Visit(const Multiply<Expression, Expression>& multiply) = 0;
62 virtual any Visit(const Divide<Expression, Expression>& divide) = 0;
63 virtual any Visit(const Exponent<Expression, Expression>& exponent) = 0;
64 virtual any Visit(const Log<Expression, Expression>& log) = 0;
65 virtual any Visit(const Negate<Expression>& negate) = 0;
66 virtual any Visit(const Magnitude<Expression>& magnitude) = 0;
67 virtual any Visit(const Derivative<Expression, Expression>& derivative) = 0;
68 virtual any Visit(const Integral<Expression, Expression>& integral) = 0;
69
70 virtual ~Visitor() = default;
71};
72
73template <typename T>
74class TypedVisitor : public Visitor {
75public:
76 using RetT = T;
77
78 auto Visit(const Real& real) -> any final { return TypedVisit(real); }
79 auto Visit(const Imaginary& imaginary) -> any final { return TypedVisit(imaginary); }
80 auto Visit(const Matrix& matrix) -> any final { return TypedVisit(matrix); }
81 auto Visit(const Variable& variable) -> any final { return TypedVisit(variable); }
82 auto Visit(const Undefined& undefined) -> any final { return TypedVisit(undefined); }
83 auto Visit(const EulerNumber& e) -> any final { return TypedVisit(e); }
84 auto Visit(const Pi& pi) -> any final { return TypedVisit(pi); }
85 auto Visit(const Add<Expression, Expression>& add) -> any final { return TypedVisit(add); }
86 auto Visit(const Subtract<Expression, Expression>& subtract) -> any final { return TypedVisit(subtract); }
87 auto Visit(const Multiply<Expression, Expression>& multiply) -> any final { return TypedVisit(multiply); }
88 auto Visit(const Divide<Expression, Expression>& divide) -> any final { return TypedVisit(divide); }
89 auto Visit(const Exponent<Expression, Expression>& exponent) -> any final { return TypedVisit(exponent); }
90 auto Visit(const Log<Expression, Expression>& log) -> any final { return TypedVisit(log); }
91 auto Visit(const Negate<Expression>& negate) -> any final { return TypedVisit(negate); }
92 auto Visit(const Magnitude<Expression>& magnitude) -> any final { return TypedVisit(magnitude); }
93 auto Visit(const Derivative<Expression, Expression>& derivative) -> any final { return TypedVisit(derivative); }
94 auto Visit(const Integral<Expression, Expression>& integral) -> any final { return TypedVisit(integral); }
95
96protected:
97 virtual auto TypedVisit(const Real& real) -> RetT = 0;
98 virtual auto TypedVisit(const Imaginary& imaginary) -> RetT = 0;
99 virtual auto TypedVisit(const Matrix& matrix) -> RetT = 0;
100 virtual auto TypedVisit(const Variable& variable) -> RetT = 0;
101 virtual auto TypedVisit(const Undefined& undefined) -> RetT = 0;
102 virtual auto TypedVisit(const EulerNumber&) -> RetT = 0;
103 virtual auto TypedVisit(const Pi&) -> RetT = 0;
104 virtual auto TypedVisit(const Add<Expression, Expression>& add) -> RetT = 0;
105 virtual auto TypedVisit(const Subtract<Expression, Expression>& subtract) -> RetT = 0;
106 virtual auto TypedVisit(const Multiply<Expression, Expression>& multiply) -> RetT = 0;
107 virtual auto TypedVisit(const Divide<Expression, Expression>& divide) -> RetT = 0;
108 virtual auto TypedVisit(const Exponent<Expression, Expression>& exponent) -> RetT = 0;
109 virtual auto TypedVisit(const Log<Expression, Expression>& log) -> RetT = 0;
110 virtual auto TypedVisit(const Negate<Expression>& negate) -> RetT = 0;
111 virtual auto TypedVisit(const Magnitude<Expression>& magnitude) -> RetT = 0;
112 virtual auto TypedVisit(const Derivative<Expression, Expression>& derivative) -> RetT = 0;
113 virtual auto TypedVisit(const Integral<Expression, Expression>& integral) -> RetT = 0;
114};
115
116}
117
118#endif // OASIS_SERIALIZATION_HPP
The Add expression adds two expressions together.
Definition Add.hpp:40
The Derivative class template calculates the derivative of given expressions.
Definition Derivative.hpp:40
The Divide expression divides two expressions.
Definition Divide.hpp:42
An 'EulerNumber' number.
Definition EulerNumber.hpp:15
The exponent expression creates an exponent two expressions.
Definition Exponent.hpp:43
An 'imaginary' number.
Definition Imaginary.hpp:15
The Integral expression integrates the two expressions together.
Definition Integral.hpp:41
The Log expression represents the logarithm of a base and an argument.
Definition Log.hpp:42
Definition Magnitude.hpp:28
A matrix.
Definition Matrix.hpp:16
The Multiply expression multiplies two expressions.
Definition Multiply.hpp:40
Definition Negate.hpp:14
Mathematical Constant Pi.
Definition Pi.hpp:15
A real number.
Definition Real.hpp:15
The Subtract expression subtracts two expressions.
Definition Subtract.hpp:43
Definition Visit.hpp:74
virtual auto TypedVisit(const Add< Expression, Expression > &add) -> RetT=0
auto Visit(const Negate< Expression > &negate) -> any final
Definition Visit.hpp:91
virtual auto TypedVisit(const Integral< Expression, Expression > &integral) -> RetT=0
virtual auto TypedVisit(const Real &real) -> RetT=0
virtual auto TypedVisit(const EulerNumber &) -> RetT=0
virtual auto TypedVisit(const Pi &) -> RetT=0
auto Visit(const Pi &pi) -> any final
Definition Visit.hpp:84
virtual auto TypedVisit(const Exponent< Expression, Expression > &exponent) -> RetT=0
virtual auto TypedVisit(const Variable &variable) -> RetT=0
virtual auto TypedVisit(const Matrix &matrix) -> RetT=0
auto Visit(const Real &real) -> any final
Definition Visit.hpp:78
auto Visit(const Log< Expression, Expression > &log) -> any final
Definition Visit.hpp:90
auto Visit(const Subtract< Expression, Expression > &subtract) -> any final
Definition Visit.hpp:86
virtual auto TypedVisit(const Multiply< Expression, Expression > &multiply) -> RetT=0
auto Visit(const Variable &variable) -> any final
Definition Visit.hpp:81
auto Visit(const Divide< Expression, Expression > &divide) -> any final
Definition Visit.hpp:88
virtual auto TypedVisit(const Log< Expression, Expression > &log) -> RetT=0
auto Visit(const Add< Expression, Expression > &add) -> any final
Definition Visit.hpp:85
auto Visit(const Derivative< Expression, Expression > &derivative) -> any final
Definition Visit.hpp:93
T RetT
Definition Visit.hpp:76
auto Visit(const Matrix &matrix) -> any final
Definition Visit.hpp:80
auto Visit(const Integral< Expression, Expression > &integral) -> any final
Definition Visit.hpp:94
virtual auto TypedVisit(const Divide< Expression, Expression > &divide) -> RetT=0
virtual auto TypedVisit(const Derivative< Expression, Expression > &derivative) -> RetT=0
virtual auto TypedVisit(const Undefined &undefined) -> RetT=0
auto Visit(const Imaginary &imaginary) -> any final
Definition Visit.hpp:79
auto Visit(const Multiply< Expression, Expression > &multiply) -> any final
Definition Visit.hpp:87
auto Visit(const Exponent< Expression, Expression > &exponent) -> any final
Definition Visit.hpp:89
virtual auto TypedVisit(const Imaginary &imaginary) -> RetT=0
virtual auto TypedVisit(const Magnitude< Expression > &magnitude) -> RetT=0
auto Visit(const EulerNumber &e) -> any final
Definition Visit.hpp:83
auto Visit(const Undefined &undefined) -> any final
Definition Visit.hpp:82
virtual auto TypedVisit(const Subtract< Expression, Expression > &subtract) -> RetT=0
auto Visit(const Magnitude< Expression > &magnitude) -> any final
Definition Visit.hpp:92
virtual auto TypedVisit(const Negate< Expression > &negate) -> RetT=0
An undefined expression.
Definition Undefined.hpp:15
An algebraic variable.
Definition Variable.hpp:21
Definition Visit.hpp:50
virtual any Visit(const Log< Expression, Expression > &log)=0
virtual any Visit(const Imaginary &imaginary)=0
virtual any Visit(const Pi &)=0
virtual any Visit(const Exponent< Expression, Expression > &exponent)=0
virtual any Visit(const Magnitude< Expression > &magnitude)=0
virtual ~Visitor()=default
virtual any Visit(const Subtract< Expression, Expression > &subtract)=0
virtual any Visit(const Integral< Expression, Expression > &integral)=0
virtual any Visit(const EulerNumber &)=0
virtual any Visit(const Negate< Expression > &negate)=0
virtual any Visit(const Variable &variable)=0
virtual any Visit(const Divide< Expression, Expression > &divide)=0
virtual any Visit(const Matrix &matrix)=0
virtual any Visit(const Multiply< Expression, Expression > &multiply)=0
virtual any Visit(const Derivative< Expression, Expression > &derivative)=0
virtual any Visit(const Add< Expression, Expression > &add)=0
virtual any Visit(const Real &real)=0
virtual any Visit(const Undefined &undefined)=0
Definition Add.hpp:11
boost::anys::unique_any any
Definition Expression.hpp:15