[poincare] Create a class n_context

Change-Id: Icce8f8fe79c07e73587d8c0563e930c1b1e6b308
This commit is contained in:
Émilie Feral
2017-01-13 15:21:39 +01:00
parent 479213668f
commit 8860902444
5 changed files with 45 additions and 2 deletions

View File

@@ -23,6 +23,7 @@ objs += $(addprefix poincare/src/,\
logarithm.o\
matrix.o\
matrix_data.o\
n_context.o\
nth_root.o\
opposite.o\
parenthesis.o\

View File

@@ -18,6 +18,7 @@
#include <poincare/logarithm.h>
#include <poincare/matrix.h>
#include <poincare/matrix_data.h>
#include <poincare/n_context.h>
#include <poincare/nth_root.h>
#include <poincare/opposite.h>
#include <poincare/parenthesis.h>

View File

@@ -0,0 +1,17 @@
#ifndef POINCARE_N_CONTEXT_H
#define POINCARE_N_CONTEXT_H
#include <poincare/context.h>
#include <poincare/float.h>
class NContext : public Context {
public:
NContext(Context * parentContext = nullptr);
void setExpressionForSymbolName(Expression * expression, const Symbol * symbol) override;
const Expression * expressionForSymbol(const Symbol * symbol) override;
private:
Float m_nValue;
Context * m_parentContext;
};
#endif

View File

@@ -1,5 +1,5 @@
#ifndef POINCARE_LOCAL_CONTEXT_H
#define POINCARE_LOCAL_CONTEXT_H
#ifndef POINCARE_X_CONTEXT_H
#define POINCARE_X_CONTEXT_H
#include <poincare/context.h>
#include <poincare/float.h>

View File

@@ -0,0 +1,24 @@
#include <poincare/n_context.h>
NContext::NContext(::Context * parentContext) :
m_nValue(Float(0.0f)),
m_parentContext(parentContext)
{
}
void NContext::setExpressionForSymbolName(Expression * expression, const Symbol * symbol) {
if (symbol->name() == 'n') {
m_nValue = Float((int)expression->approximate(*m_parentContext));
} else {
m_parentContext->setExpressionForSymbolName(expression, symbol);
}
}
const Expression * NContext::expressionForSymbol(const Symbol * symbol) {
if (symbol->name() == 'n') {
return &m_nValue;
} else {
return m_parentContext->expressionForSymbol(symbol);
}
}