mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 16:57:31 +01:00
- CreateLayout depends on the float display mode and the number of significant digits - Float display mode does not have a default value anymore
94 lines
2.1 KiB
C++
94 lines
2.1 KiB
C++
#include "function.h"
|
|
#include "poincare_helpers.h"
|
|
#include <string.h>
|
|
#include <cmath>
|
|
#include <assert.h>
|
|
|
|
using namespace Poincare;
|
|
|
|
namespace Shared {
|
|
|
|
ExpressionModel::ExpressionModel() :
|
|
m_text{0},
|
|
m_expression(nullptr),
|
|
m_layout(nullptr)
|
|
{
|
|
}
|
|
|
|
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_layout != nullptr) {
|
|
delete m_layout;
|
|
m_layout = 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) {
|
|
m_expression = Expression::ParseAndSimplify(m_text, *context);
|
|
}
|
|
return m_expression;
|
|
}
|
|
|
|
Poincare::ExpressionLayout * ExpressionModel::layout() {
|
|
if (m_layout == nullptr) {
|
|
Expression * nonSimplifiedExpression = Expression::parse(m_text);
|
|
if (nonSimplifiedExpression != nullptr) {
|
|
m_layout = PoincareHelpers::CreateLayout(nonSimplifiedExpression);
|
|
delete nonSimplifiedExpression;
|
|
}
|
|
}
|
|
return m_layout;
|
|
}
|
|
|
|
bool ExpressionModel::isDefined() {
|
|
return m_text[0] != 0;
|
|
}
|
|
|
|
bool ExpressionModel::isEmpty() {
|
|
return m_text[0] == 0;
|
|
}
|
|
|
|
void ExpressionModel::setContent(const char * c) {
|
|
strlcpy(m_text, c, sizeof(m_text));
|
|
/* 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. */
|
|
if (m_layout != nullptr) {
|
|
delete m_layout;
|
|
m_layout = nullptr;
|
|
}
|
|
if (m_expression != nullptr) {
|
|
delete m_expression;
|
|
m_expression = nullptr;
|
|
}
|
|
}
|
|
|
|
void ExpressionModel::tidy() {
|
|
if (m_layout != nullptr) {
|
|
delete m_layout;
|
|
m_layout = nullptr;
|
|
}
|
|
if (m_expression != nullptr) {
|
|
delete m_expression;
|
|
m_expression = nullptr;
|
|
}
|
|
}
|
|
|
|
}
|