[escher] [apps] Implement app snapshot

Change-Id: I24d7eed7cef964af8be1c85222e758c297dc0da1
This commit is contained in:
Émilie Feral
2017-05-17 14:44:00 +02:00
parent 06de0dd9db
commit 71284311bb
51 changed files with 568 additions and 340 deletions

View File

@@ -27,16 +27,13 @@ Function& Function::operator=(const Function& other) {
void Function::setContent(const char * c) {
strlcpy(m_text, c, sizeof(m_text));
if (m_expression != nullptr) {
delete m_expression;
}
m_expression = Poincare::Expression::parse(m_text);
if (m_layout != nullptr) {
delete m_layout;
m_layout = nullptr;
}
m_layout = nullptr;
if (m_expression) {
m_layout = expression()->createLayout(Expression::FloatDisplayMode::Decimal);
if (m_expression != nullptr) {
delete m_expression;
m_expression = nullptr;
}
}
@@ -64,15 +61,21 @@ const char * Function::name() const {
}
Poincare::Expression * Function::expression() {
if (m_expression == nullptr) {
m_expression = Expression::parse(m_text);
}
return m_expression;
}
Poincare::ExpressionLayout * Function::layout() {
if (m_layout == nullptr && expression() != nullptr) {
m_layout = expression()->createLayout(Expression::FloatDisplayMode::Decimal);
}
return m_layout;
}
bool Function::isDefined() {
return m_expression != nullptr;
return strlen(m_text) != 0;
}
bool Function::isActive() {
@@ -95,4 +98,15 @@ float Function::evaluateAtAbscissa(float x, Poincare::Context * context) const {
return m_expression->approximate(variableContext);
}
void Function::tidy() {
if (m_layout != nullptr) {
delete m_layout;
m_layout = nullptr;
}
if (m_expression != nullptr) {
delete m_expression;
m_expression = nullptr;
}
}
}