parenthesis.cpp
1.58 KB
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
extern "C" {
#include <assert.h>
#include <stdlib.h>
}
#include <poincare/parenthesis.h>
#include "layout/parenthesis_layout.h"
namespace Poincare {
Parenthesis::Parenthesis(Expression * operand, bool cloneOperands) {
assert(operand != nullptr);
if (cloneOperands) {
m_operand = operand->clone();
} else {
m_operand = operand;
}
}
Parenthesis::~Parenthesis() {
delete m_operand;
}
bool Parenthesis::hasValidNumberOfArguments() const {
return m_operand->hasValidNumberOfArguments();
}
int Parenthesis::numberOfOperands() const {
return 1;
}
const Expression * Parenthesis::operand(int i) const {
assert(i == 0);
return m_operand;
}
Expression * Parenthesis::clone() const {
return this->cloneWithDifferentOperands((Expression**) &m_operand, 1, true);
}
ExpressionLayout * Parenthesis::privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const {
assert(floatDisplayMode != FloatDisplayMode::Default);
assert(complexFormat != ComplexFormat::Default);
return new ParenthesisLayout(m_operand->createLayout(floatDisplayMode, complexFormat));
}
template<typename T>
Evaluation<T> * Parenthesis::templatedEvaluate(Context& context, AngleUnit angleUnit) const {
return m_operand->evaluate<T>(context, angleUnit);
}
Expression::Type Parenthesis::type() const {
return Type::Parenthesis;
}
Expression * Parenthesis::cloneWithDifferentOperands(Expression** newOperands,
int numberOfOperands, bool cloneOperands) const {
assert(numberOfOperands == 1);
assert(newOperands != nullptr);
return new Parenthesis(newOperands[0], cloneOperands);
}
}