[apps/probability] Create a class evaluate context for probability app

Change-Id: I38448ddeec25225edad1d96bf89d32d1eb86915d
This commit is contained in:
Émilie Feral
2016-12-06 11:01:16 +01:00
parent eeb17625d1
commit 620b64a583
5 changed files with 69 additions and 1 deletions

View File

@@ -1,6 +1,7 @@
app_objs += $(addprefix apps/probability/,\
app.o\
cell.o\
evaluate_context.o\
law.o\
law_controller.o\
parameters_controller.o\

View File

@@ -0,0 +1,39 @@
#include "evaluate_context.h"
#include <string.h>
namespace Probability {
EvaluateContext::EvaluateContext(::Context * parentContext) :
m_tValue(Float(0.0f)),
m_firstParameterValue(Float(0.0f)),
m_secondParameterValue(Float(0.0f)),
m_context(parentContext)
{
}
void EvaluateContext::setOverridenValueForSymbolT(float f) {
m_tValue = Float(f);
}
void EvaluateContext::setOverridenValueForFirstParameter(float f) {
m_firstParameterValue = Float(f);
}
void EvaluateContext::setOverridenValueForSecondParameter(float f) {
m_secondParameterValue = Float(f);
}
const Expression * EvaluateContext::expressionForSymbol(const Symbol * symbol) {
if (symbol->name() == 't') {
return &m_tValue;
}
if (symbol->name() == Symbol::SpecialSymbols::p1) {
return &m_firstParameterValue;
}
if (symbol->name() == Symbol::SpecialSymbols::p2) {
return &m_secondParameterValue;
}
return m_context->expressionForSymbol(symbol);
}
}

View File

@@ -0,0 +1,24 @@
#ifndef PROBABILITY_EVALUATECONTEXT_H
#define PROBABILITY_EVALUATECONTEXT_H
#include <poincare.h>
namespace Probability {
class EvaluateContext : public ::Context {
public:
EvaluateContext(Context * parentContext);
void setOverridenValueForSymbolT(float f);
void setOverridenValueForFirstParameter(float f);
void setOverridenValueForSecondParameter(float f);
const Expression * expressionForSymbol(const Symbol * symbol) override;
private:
Float m_tValue;
Float m_firstParameterValue;
Float m_secondParameterValue;
::Context * m_context;
};
}
#endif

View File

@@ -6,7 +6,9 @@
class Symbol : public LeafExpression {
public:
enum SpecialSymbols : char {
Ans = '^'
Ans = '^',
p1 = '*',
p2 = '$'
};
Symbol(char name);
ExpressionLayout * createLayout() const override;

View File

@@ -69,6 +69,8 @@
[0-9]+ { poincare_expression_yylval.string = yytext; return(INTEGER); }
[A-Zxnt] { poincare_expression_yylval.character = yytext[0]; return SYMBOL; }
ans { poincare_expression_yylval.character = Symbol::Ans; return SYMBOL; }
p1 { poincare_expression_yylval.character = Symbol::p1; return SYMBOL; }
p2 { poincare_expression_yylval.character = Symbol::p2; return SYMBOL; }
sin { poincare_expression_yylval.expression = new Sine(); return FUNCTION; }
cos { poincare_expression_yylval.expression = new Cosine(); return FUNCTION; }
tan { poincare_expression_yylval.expression = new Tangent(); return FUNCTION; }