mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-29 19:49:58 +02:00
[poincare] VariableContext
This commit is contained in:
@@ -35,6 +35,7 @@ objs += $(addprefix poincare/src/,\
|
||||
layout_helper.o\
|
||||
simplification_helper.o\
|
||||
global_context.o\
|
||||
variable_context.o\
|
||||
)
|
||||
|
||||
objsExpected += $(addprefix poincare/src/,\
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#define POINCARE_VARIABLE_CONTEXT_H
|
||||
|
||||
#include <poincare/context.h>
|
||||
#include <poincare/approximation.h>
|
||||
#include <poincare/float.h>
|
||||
|
||||
namespace Poincare {
|
||||
|
||||
@@ -11,11 +11,14 @@ class VariableContext : public Context {
|
||||
public:
|
||||
VariableContext(char name, Context * parentContext = nullptr);
|
||||
void setApproximationForVariable(T value);
|
||||
void setExpressionForSymbolName(const Expression * expression, const Symbol * symbol, Context & context) override;
|
||||
const Expression * expressionForSymbol(const Symbol * symbol) override;
|
||||
|
||||
// Context
|
||||
void setExpressionForSymbolName(const Expression expression, const Symbol symbol, Context & context) override;
|
||||
const Expression expressionForSymbol(const Symbol symbol) override;
|
||||
|
||||
private:
|
||||
char m_name;
|
||||
Approximation<T> m_value;
|
||||
Float<T> m_value;
|
||||
Context * m_parentContext;
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <poincare/variable_context.h>
|
||||
#include <poincare/preferences.h>
|
||||
#include <assert.h>
|
||||
#include <poincare/symbol.h>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
namespace Poincare {
|
||||
@@ -8,32 +9,32 @@ namespace Poincare {
|
||||
template<typename T>
|
||||
VariableContext<T>::VariableContext(char name, Context * parentContext) :
|
||||
m_name(name),
|
||||
m_value(Approximation<T>(NAN)),
|
||||
m_value(Float<T>(NAN)),
|
||||
m_parentContext(parentContext)
|
||||
{
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void VariableContext<T>::setApproximationForVariable(T value) {
|
||||
m_value = Approximation<T>(value);
|
||||
m_value = Float<T>(value);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
void VariableContext<T>::setExpressionForSymbolName(const Expression * expression, const Symbol * symbol, Context & context) {
|
||||
if (symbol->name() == m_name) {
|
||||
if (expression == nullptr) {
|
||||
void VariableContext<T>::setExpressionForSymbolName(const Expression expression, const Symbol symbol, Context & context) {
|
||||
if (symbol.name() == m_name) {
|
||||
if (!expression.isDefined()) {
|
||||
return;
|
||||
}
|
||||
m_value = Approximation<T>(expression->approximateToScalar<T>(context, Preferences::sharedPreferences()->angleUnit()));
|
||||
m_value = Float<T>(expression.approximateToScalar<T>(context, Preferences::sharedPreferences()->angleUnit()));
|
||||
} else {
|
||||
m_parentContext->setExpressionForSymbolName(expression, symbol, context);
|
||||
}
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
const Expression * VariableContext<T>::expressionForSymbol(const Symbol * symbol) {
|
||||
if (symbol->name() == m_name) {
|
||||
return &m_value;
|
||||
const Expression VariableContext<T>::expressionForSymbol(const Symbol symbol) {
|
||||
if (symbol.name() == m_name) {
|
||||
return m_value;
|
||||
} else {
|
||||
return m_parentContext->expressionForSymbol(symbol);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user