[apps/calcul] create a model of a calcul

Change-Id: I5d5515f8d59f7259890425a3cde4e44d15cd5eba
This commit is contained in:
Émilie Feral
2016-10-21 13:38:29 +01:00
parent 0907794091
commit 7fdc7de746
3 changed files with 83 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
app_objs += $(addprefix apps/calcul/,\
app.o\
calcul_controller.o\
calcul.o\
)
inline_images += apps/calcul/calcul_icon.png

55
apps/calcul/calcul.cpp Normal file
View File

@@ -0,0 +1,55 @@
#include "calcul.h"
#include <string.h>
namespace Calcul {
Calcul::Calcul() :
m_text("1+3"),
m_expression(nullptr),
m_layout(nullptr),
m_evaluation(Float(3.0f))
{
// TODO: this is temporary. To test the render.
m_expression = Expression::parse(m_text);
m_layout = expression()->createLayout();
}
void Calcul::setContent(const char * c, Context * context) {
strlcpy(m_text, c, sizeof(m_text));
if (m_expression != nullptr) {
delete m_expression;
}
m_expression = Expression::parse(m_text);
if (m_layout != nullptr) {
delete m_layout;
}
m_layout = expression()->createLayout();
m_evaluation = m_expression->approximate(*context);
}
Calcul::~Calcul() {
if (m_layout != nullptr) {
delete m_layout;
}
if (m_expression != nullptr) {
delete m_expression;
}
}
const char * Calcul::text() {
return m_text;
}
Expression * Calcul::expression() {
return m_expression;
}
ExpressionLayout * Calcul::layout() {
return m_layout;
}
Float * Calcul::evaluation() {
return &m_evaluation;
}
}

27
apps/calcul/calcul.h Normal file
View File

@@ -0,0 +1,27 @@
#ifndef CALCUL_CALCUL_H
#define CALCUL_CALCUL_H
#include <poincare.h>
namespace Calcul {
class Calcul {
public:
Calcul();
~Calcul(); // Delete expression and layout, if needed
const char * text();
Expression * expression();
ExpressionLayout * layout();
Float * evaluation();
void setContent(const char * c, Context * context);
private:
constexpr static int k_bodyLength = 255;
char m_text[k_bodyLength];
Expression * m_expression;
ExpressionLayout * m_layout;
Float m_evaluation;
};
}
#endif