-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexpression.hpp
185 lines (142 loc) · 5.18 KB
/
expression.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
#ifndef EXPRESSION
#define EXPRESSION
/// Indicates the type of an expression
enum class expression_type
{
/// The expression is a time expression
time,
/// The expression is a frequency expression
frequency,
/// The expression involves neither time nor frequency
invariant
};
/// Exception thrown when a laplace or inverse laplace transform is unknown
class expression_unknown_transform_exception : public exception
{
public:
expression_unknown_transform_exception(const string &what);
};
/// An expression is a symbolic representation of some quantity in terms of
/// voltages and currents between pins. It may also involve time and frequency.
class expression
{
public:
/// Get the type of the expression
virtual expression_type type() const = 0;
/// Convert this expression to a frequency-domain expression
virtual unique_ptr<expression> to_frequency() const = 0;
/// Convert this expression to a time-domain expression.
virtual unique_ptr<expression> to_time() const = 0;
};
/// An expression that represents a constant
class constant_expression : public expression
{
public:
/// Construct the expression "1"
constant_expression();
/// Construct the expression "constant"
constant_expression(double constant);
virtual expression_type type() const override;
virtual unique_ptr<expression> to_frequency() const override;
virtual unique_ptr<expression> to_time() const override;
private:
enum class mode
{
e,
one,
minus_one,
arbitrary
};
/// Is this constant operating as a special or arbitrary value?
mode mMode;
/// If operating in arbitrary mode, this is the value of the constant.
double mArbitraryVal;
};
/// An expression that represents an exponentiation "a^b"
class exponent_expression : public expression
{
public:
exponent_expression(const expression &base, const expression &exponent);
virtual expression_type type() const override;
virtual unique_ptr<expression> to_frequency() const override;
virtual unique_ptr<expression> to_time() const override;
const unique_ptr<expression> mBase;
const unique_ptr<expression> mExponent;
};
/// An expression that represents a sum "a + b + ..."
class sum_expression : public expression
{
public:
sum_expression(const expression &left, const expression &right);
sum_expression(const product_expression &left, const expression &right);
const vector<const expression> mTerms;
};
/// An expression that represents a product "a*b"
class product_expression : public expression
{
public:
product_expression(const expression &left, const expression &right);
product_expression(const product_expression &left, const expression &right);
virtual expression_type type() const override;
virtual unique_ptr<expression> to_frequency() const override;
virtual unique_ptr<expression> to_time() const override;
const vector<const expression> mTerms;
};
/// An expression that represents a definite integral
class integral_expression : public expression
{
public:
integral_expression(const expression &integrand,
const expression &lower,
const expression &upper);
virtual expression_type type() const override;
virtual unique_ptr<expression> to_frequency() const override;
virtual unique_ptr<expression> to_time() const override;
const expression mIntegrand;
const expression mLower;
const expression mUpper;
};
/// An expression that represents a time differentiation
class derivative_expression : public expression
{
public:
derivative_expression(const expression &subject);
virtual expression_type type() const override;
virtual unique_ptr<expression> to_frequency() const override;
virtual unique_ptr<expression> to_time() const override;
const expression mSubject;
};
/// An expression representing an independent variable, either t or s
class independent_expression : public expression
{
public:
independent_expression(const expression_type &type);
virtual expression_type type() const override;
virtual unique_ptr<expression> to_frequency() const override;
virtual unique_ptr<expression> to_time() const override;
private:
const expression_type mType;
};
/// An expression representing a voltage, whether as a function of time,
/// frequency, or invariant
class voltage_expression : public expression
{
public:
voltage_expression(const voltage &which, const expression_type &type);
virtual expression_type type() const override;
virtual unique_ptr<expression> to_frequency() const override;
virtual unique_ptr<expression> to_time() const override;
const voltage mWhich;
};
/// An expression representing a current, whether as a function of time,
/// frequency, or invariant
class current_expression : public expression
{
public:
current_expression(const current &which, const expression_type &type);
virtual expression_type type() const override;
virtual unique_ptr<expression> to_frequency() const override;
virtual unique_ptr<expression> to_time() const override;
const current mWhich;
};
#endif