mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[shared] Fix references to Poincare
This commit is contained in:
@@ -10,35 +10,17 @@ namespace Shared {
|
||||
|
||||
ExpressionModel::ExpressionModel() :
|
||||
m_text{0},
|
||||
m_expression(nullptr),
|
||||
m_layoutRef(nullptr)
|
||||
m_expression(),
|
||||
m_layoutRef()
|
||||
{
|
||||
}
|
||||
|
||||
ExpressionModel::~ExpressionModel() {
|
||||
/* We cannot call tidy here because tidy is a virtual function and does not
|
||||
* do the same thing for all children class. */
|
||||
if (m_layoutRef.isDefined()) {
|
||||
m_layoutRef = LayoutRef(nullptr);
|
||||
}
|
||||
if (m_expression != nullptr) {
|
||||
delete m_expression;
|
||||
m_expression = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
ExpressionModel& ExpressionModel::operator=(const ExpressionModel& other) {
|
||||
// Self-assignment is benign
|
||||
setContent(other.m_text);
|
||||
return *this;
|
||||
}
|
||||
|
||||
const char * ExpressionModel::text() const {
|
||||
return m_text;
|
||||
}
|
||||
|
||||
Poincare::Expression * ExpressionModel::expression(Poincare::Context * context) const {
|
||||
if (m_expression == nullptr) {
|
||||
Poincare::Expression ExpressionModel::expression(Poincare::Context * context) const {
|
||||
if (!m_expression.isDefined()) {
|
||||
m_expression = PoincareHelpers::ParseAndSimplify(m_text, *context);
|
||||
}
|
||||
return m_expression;
|
||||
@@ -46,11 +28,8 @@ Poincare::Expression * ExpressionModel::expression(Poincare::Context * context)
|
||||
|
||||
LayoutRef ExpressionModel::layoutRef() {
|
||||
if (!m_layoutRef.isDefined()) {
|
||||
Expression * nonSimplifiedExpression = Expression::parse(m_text);
|
||||
if (nonSimplifiedExpression != nullptr) {
|
||||
m_layoutRef = PoincareHelpers::CreateLayout(nonSimplifiedExpression);
|
||||
delete nonSimplifiedExpression;
|
||||
}
|
||||
Expression nonSimplifiedExpression = Expression::parse(m_text);
|
||||
m_layoutRef = PoincareHelpers::CreateLayout(nonSimplifiedExpression);
|
||||
}
|
||||
return m_layoutRef;
|
||||
}
|
||||
@@ -68,6 +47,8 @@ void ExpressionModel::setContent(const char * c) {
|
||||
/* 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. */
|
||||
// TODO: the previous expression and layout are going to be destroyed as soon as we call expression(). Should we optimize this?
|
||||
#if 0
|
||||
if (m_layoutRef.isDefined()) {
|
||||
m_layoutRef = LayoutRef(nullptr);
|
||||
}
|
||||
@@ -75,9 +56,16 @@ void ExpressionModel::setContent(const char * c) {
|
||||
delete m_expression;
|
||||
m_expression = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void ExpressionModel::tidy() {
|
||||
// TODO: what do we want to do? Delete layout and ref?
|
||||
#if 0
|
||||
m_layoutRef = LayoutRef(); ?
|
||||
m_expression = Expression(); ?
|
||||
|
||||
|
||||
if (m_layoutRef.isDefined()) {
|
||||
m_layoutRef = LayoutRef(nullptr);
|
||||
}
|
||||
@@ -85,6 +73,7 @@ void ExpressionModel::tidy() {
|
||||
delete m_expression;
|
||||
m_expression = nullptr;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user