mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[solver] Make Equation inherits from ExpressionModelHandle instead of
ExpressionModel
This commit is contained in:
@@ -74,12 +74,16 @@ bool ExpressionModelHandle::isEmpty() {
|
||||
return value().size <= metaDataSize();
|
||||
}
|
||||
|
||||
void ExpressionModelHandle::tidy() {
|
||||
void ExpressionModelHandle::tidyExpressionModel() {
|
||||
m_layout = Layout();
|
||||
m_expression = Expression();
|
||||
m_circular = 0;
|
||||
}
|
||||
|
||||
void ExpressionModelHandle::tidy() {
|
||||
tidyExpressionModel();
|
||||
}
|
||||
|
||||
Ion::Storage::Record::ErrorStatus ExpressionModelHandle::setContent(const char * c) {
|
||||
Expression expressionToStore;
|
||||
// if c = "", we want to reinit the Expression
|
||||
@@ -113,10 +117,8 @@ Ion::Storage::Record::ErrorStatus ExpressionModelHandle::setExpressionContent(Ex
|
||||
}
|
||||
/* We cannot call tidy here because tidy is a virtual function and does not
|
||||
* do the same thing for all children class. And here we want to delete only
|
||||
* the m_layout and m_expression. */
|
||||
m_layout = Layout();
|
||||
m_expression = Expression();
|
||||
m_circular = 0;
|
||||
* the elements relative to the ExpressionModel. */
|
||||
tidyExpressionModel();
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,13 @@ public:
|
||||
virtual bool isDefined();
|
||||
virtual bool isEmpty();
|
||||
virtual bool shouldBeClearedBeforeRemove() { return !isEmpty(); }
|
||||
/* tidy is responsible to tidy the whole model whereas tidyExpressionModel
|
||||
* tidies only the members associated with the ExpressionModel. In
|
||||
* ExpressionModelHandle, tidy and tidyExpressionModel trigger the same
|
||||
* behaviour but it is not true for its child classes (for example, in
|
||||
* Sequence). */
|
||||
virtual void tidy();
|
||||
virtual void tidyExpressionModel();
|
||||
virtual Ion::Storage::Record::ErrorStatus setContent(const char * c);
|
||||
Ion::Storage::Record::ErrorStatus setExpressionContent(Poincare::Expression & e);
|
||||
protected:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "equation.h"
|
||||
#include <poincare/constant.h>
|
||||
#include <poincare/equal.h>
|
||||
#include <poincare/undefined.h>
|
||||
#include <poincare/unreal.h>
|
||||
@@ -6,29 +7,27 @@
|
||||
#include <ion/unicode/utf8_helper.h>
|
||||
|
||||
using namespace Poincare;
|
||||
using namespace Shared;
|
||||
|
||||
namespace Solver {
|
||||
|
||||
Equation::Equation() :
|
||||
Shared::ExpressionModel(),
|
||||
constexpr char Equation::extension[];
|
||||
|
||||
Equation::Equation(Ion::Storage::Record record) :
|
||||
ExpressionModelHandle(record),
|
||||
m_standardForm()
|
||||
{
|
||||
}
|
||||
|
||||
void Equation::setContent(const char * c) {
|
||||
/* ExpressionModel::setContent takes care of tidying m_expression and m_layout. */
|
||||
tidyStandardForm();
|
||||
ExpressionModel::setContent(c);
|
||||
}
|
||||
|
||||
void Equation::tidy() {
|
||||
ExpressionModel::tidy();
|
||||
tidyStandardForm();
|
||||
void Equation::tidyExpressionModel() {
|
||||
ExpressionModelHandle::tidyExpressionModel();
|
||||
// Free the pool of the m_standardForm
|
||||
m_standardForm = Expression();
|
||||
}
|
||||
|
||||
Expression Equation::standardForm(Context * context) const {
|
||||
if (m_standardForm.isUninitialized()) {
|
||||
const Expression e = expression(context);
|
||||
const Expression e = expressionReduced(context);
|
||||
if (e.type() == ExpressionNode::Type::Unreal) {
|
||||
m_standardForm = Unreal::Builder();
|
||||
return m_standardForm;
|
||||
@@ -39,7 +38,7 @@ Expression Equation::standardForm(Context * context) const {
|
||||
}
|
||||
if (e.type() == ExpressionNode::Type::Equal) {
|
||||
Preferences * preferences = Preferences::sharedPreferences();
|
||||
m_standardForm = static_cast<const Equal&>(e).standardEquation(*context, Expression::UpdatedComplexFormatWithTextInput(preferences->complexFormat(), text()), preferences->angleUnit());
|
||||
m_standardForm = static_cast<const Equal&>(e).standardEquation(*context, Expression::UpdatedComplexFormatWithExpressionInput(preferences->complexFormat(), expressionClone(), *context), preferences->angleUnit());
|
||||
} else {
|
||||
assert(e.type() == ExpressionNode::Type::Rational && static_cast<const Rational&>(e).isOne());
|
||||
// The equality was reduced which means the equality was always true.
|
||||
@@ -49,13 +48,8 @@ Expression Equation::standardForm(Context * context) const {
|
||||
return m_standardForm;
|
||||
}
|
||||
|
||||
bool Equation::containsIComplex() const {
|
||||
return *(UTF8Helper::CodePointSearch(text(), UCodePointMathematicalBoldSmallI)) != 0;
|
||||
}
|
||||
|
||||
void Equation::tidyStandardForm() {
|
||||
// Free the pool of the m_standardForm
|
||||
m_standardForm = Expression();
|
||||
bool Equation::containsIComplex(Context * context) const {
|
||||
return expressionClone().recursivelyMatches([](const Expression e, Context & context, bool replaceSymbols) { return e.type() == ExpressionNode::Type::Constant && static_cast<const Constant &>(e).isIComplex(); }, *context, true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,22 +1,23 @@
|
||||
#ifndef SOLVER_EQUATION_h
|
||||
#define SOLVER_EQUATION_h
|
||||
|
||||
#include "../shared/expression_model.h"
|
||||
#include "../shared/expression_model_handle.h"
|
||||
|
||||
namespace Solver {
|
||||
|
||||
class Equation : public Shared::ExpressionModel {
|
||||
class Equation : public Shared::ExpressionModelHandle {
|
||||
public:
|
||||
Equation();
|
||||
void setContent(const char * c) override;
|
||||
void tidy() override;
|
||||
Equation(Ion::Storage::Record record = Record());
|
||||
void tidyExpressionModel() override;
|
||||
bool shouldBeClearedBeforeRemove() override {
|
||||
return false;
|
||||
}
|
||||
Poincare::Expression standardForm(Poincare::Context * context) const;
|
||||
bool containsIComplex() const;
|
||||
bool containsIComplex(Poincare::Context * context) const;
|
||||
|
||||
static constexpr char extension[] = "eq"; // TODO: store this elsewhere?
|
||||
private:
|
||||
void tidyStandardForm();
|
||||
size_t metaDataSize() const override { return 0; }
|
||||
mutable Poincare::Expression m_standardForm;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user