[poincare] Create a header for SimplificationRoot

Change-Id: I83f23c0b7b036e193510eb2c31943e9b6c32a2bc
This commit is contained in:
Émilie Feral
2017-10-13 17:41:47 +02:00
parent 35ebf781df
commit 0743e91ed5
2 changed files with 35 additions and 24 deletions

View File

@@ -0,0 +1,34 @@
#ifndef POINCARE_SIMPLIFICATION_ROOT_H
#define POINCARE_SIMPLIFICATION_ROOT_H
#include <poincare/static_hierarchy.h>
namespace Poincare {
class SimplificationRoot : public StaticHierarchy<1> {
public:
SimplificationRoot(Expression * e) : StaticHierarchy<1>(&e, false) {
e->setParent(this);
}
~SimplificationRoot() {
detachOperand(operand(0));
/* We don't want to clone the expression provided at construction.
* So we don't want it to be deleted when we're destroyed (parent destructor). */
}
Expression * clone() const override { return nullptr; }
Type type() const override { return Expression::Type::Undefined; }
Expression * immediateSimplify() override { return this; }
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
return nullptr;
}
Evaluation<float> * privateEvaluate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override {
return nullptr;
}
Evaluation<double> * privateEvaluate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override {
return nullptr;
}
};
}
#endif

View File

@@ -7,6 +7,7 @@
#include <poincare/matrix_data.h>
#include <poincare/evaluation.h>
#include <poincare/undefined.h>
#include <poincare/simplification_root.h>
#include <cmath>
#include "expression_parser.hpp"
#include "expression_lexer.hpp"
@@ -67,30 +68,6 @@ ExpressionLayout * Expression::createLayout(FloatDisplayMode floatDisplayMode, C
}
}
class SimplificationRoot : public StaticHierarchy<1> {
public:
SimplificationRoot(Expression * e) : StaticHierarchy<1>(&e, false) {
e->setParent(this);
}
~SimplificationRoot() {
detachOperand(operand(0));
/* We don't want to clone the expression provided at construction.
* So we don't want it to be deleted when we're destroyed (parent destructor). */
}
Expression * clone() const override { return nullptr; }
Type type() const override { return Expression::Type::Undefined; }
Expression * immediateSimplify() override { return this; }
ExpressionLayout * privateCreateLayout(FloatDisplayMode floatDisplayMode, ComplexFormat complexFormat) const override {
return nullptr;
}
Evaluation<float> * privateEvaluate(SinglePrecision p, Context& context, AngleUnit angleUnit) const override {
return nullptr;
}
Evaluation<double> * privateEvaluate(DoublePrecision p, Context& context, AngleUnit angleUnit) const override {
return nullptr;
}
};
void Expression::simplifyAndBeautify(Expression ** expressionAddress) {
SimplificationRoot root(*expressionAddress);
root.simplify();