mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-19 22:00:28 +01:00
56 lines
1.0 KiB
C++
56 lines
1.0 KiB
C++
#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;
|
|
}
|
|
|
|
}
|