Files
Upsilon/apps/graph/function.cpp
Émilie Feral 96a9ac3a9c [apps/graph] Wrap in namespace Graph
Change-Id: I08b37438f42749ff86e105770cd5aa566f84a237
2016-10-14 11:47:19 +02:00

70 lines
1.2 KiB
C++

#include "function.h"
#include <string.h>
namespace Graph {
Function::Function(const char * text, KDColor color) :
m_name(text),
m_color(color),
m_expression(nullptr),
m_layout(nullptr),
m_active(true)
{
}
void Function::setContent(const char * c) {
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();
}
void Function::setColor(KDColor color) {
m_color = color;
}
Function::~Function() {
if (m_layout != nullptr) {
delete m_layout;
}
if (m_expression != nullptr) {
delete m_expression;
}
}
const char * Function::text() {
return m_text;
}
const char * Function::name() {
return m_name;
}
Expression * Function::expression() {
return m_expression;
}
ExpressionLayout * Function::layout() {
return m_layout;
}
bool Function::isActive() {
return m_active;
}
void Function::setActive(bool active) {
m_active = active;
}
float Function::evaluateAtAbscissa(float x, EvaluateContext * context) {
context->setOverridenValueForSymbolX(x);
return m_expression->approximate(*context);
}
}