mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 22:00:28 +01:00
[apps/calcul] create a model of a calcul
Change-Id: I5d5515f8d59f7259890425a3cde4e44d15cd5eba
This commit is contained in:
@@ -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
55
apps/calcul/calcul.cpp
Normal 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
27
apps/calcul/calcul.h
Normal 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
|
||||
Reference in New Issue
Block a user