Files
Upsilon/poincare/src/simplify/expression_match.cpp
Émilie Feral 680c84e413 Clean with clang analyzer
Change-Id: I4897b3a88795d76f4ac7e6f788a7e6d19397dbfd
2017-03-28 14:49:28 +02:00

48 lines
1.1 KiB
C++

#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;
}
}