expression_match.cpp
1.15 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
#include "expression_match.h"
extern "C" {
#include <assert.h>
#include <stdlib.h>
}
namespace Poincare {
ExpressionMatch::ExpressionMatch() {
m_numberOfExpressions = 0;
m_expressions = nullptr;
}
ExpressionMatch::ExpressionMatch(const Expression ** expressions, int numberOfExpressions) {
m_numberOfExpressions = numberOfExpressions;
m_expressions = (const Expression**) malloc(m_numberOfExpressions * sizeof(Expression*));
for (int i(0); i<numberOfExpressions; i++) {
m_expressions[i] = expressions[i];
}
}
ExpressionMatch::~ExpressionMatch() {
if (m_numberOfExpressions != 0) {
free(m_expressions);
}
}
const Expression * ExpressionMatch::expression(int i) {
assert(i < m_numberOfExpressions);
return m_expressions[i];
}
int ExpressionMatch::numberOfExpressions() {
return m_numberOfExpressions;
}
ExpressionMatch& ExpressionMatch::operator=(ExpressionMatch&& other) {
m_numberOfExpressions = other.m_numberOfExpressions;
// Here we make sure that the memory containing the expressions is not freed
// in order to avoid a double free
other.m_numberOfExpressions = 0;
m_expressions = other.m_expressions;
return *this;
}
}