[apps/calculation] Change names: expression->input, evaluation->output

Change-Id: I9d65a9fc7d1b7132ae3aaa8a86e4511286b7e3da
This commit is contained in:
Émilie Feral
2016-12-09 09:58:14 +01:00
parent c96fe1c708
commit e1f808e7da
5 changed files with 68 additions and 68 deletions

View File

@@ -4,78 +4,78 @@
namespace Calculation {
Calculation::Calculation() :
m_expression(nullptr),
m_layout(nullptr),
m_evaluation(nullptr),
m_evaluationLayout(nullptr)
m_input(nullptr),
m_inputLayout(nullptr),
m_output(nullptr),
m_outputLayout(nullptr)
{
}
Calculation & Calculation::operator= (const Calculation & other) {
strlcpy(m_text, other.m_text, sizeof(m_text));
if (m_expression != nullptr) {
delete m_expression;
if (m_input != nullptr) {
delete m_input;
}
m_expression = nullptr;
if (other.m_expression) {
m_expression = Expression::parse(m_text);
m_input = nullptr;
if (other.m_input) {
m_input = Expression::parse(m_text);
}
if (m_layout != nullptr) {
delete m_layout;
if (m_inputLayout != nullptr) {
delete m_inputLayout;
}
m_layout = nullptr;
if (m_expression && other.m_layout) {
m_layout = m_expression->createLayout();
m_inputLayout = nullptr;
if (m_input && other.m_inputLayout) {
m_inputLayout = m_input->createLayout();
}
if (m_evaluation != nullptr) {
delete m_evaluation;
if (m_output != nullptr) {
delete m_output;
}
m_evaluation = nullptr;
if (other.m_evaluation) {
m_evaluation = other.m_evaluation->clone();
m_output = nullptr;
if (other.m_output) {
m_output = other.m_output->clone();
}
if (m_evaluationLayout != nullptr) {
delete m_evaluationLayout;
if (m_outputLayout != nullptr) {
delete m_outputLayout;
}
m_evaluationLayout = nullptr;
if (m_evaluation && other.m_evaluationLayout) {
m_evaluationLayout = m_evaluation->createLayout();
m_outputLayout = nullptr;
if (m_output && other.m_outputLayout) {
m_outputLayout = m_output->createLayout();
}
return *this;
}
void Calculation::setContent(const char * c, Context * context) {
strlcpy(m_text, c, sizeof(m_text));
if (m_expression != nullptr) {
delete m_expression;
if (m_input != nullptr) {
delete m_input;
}
m_expression = Expression::parse(m_text);
if (m_layout != nullptr) {
delete m_layout;
m_input = Expression::parse(m_text);
if (m_inputLayout != nullptr) {
delete m_inputLayout;
}
m_layout = m_expression->createLayout();
if (m_evaluation != nullptr) {
delete m_evaluationLayout;
m_inputLayout = m_input->createLayout();
if (m_output != nullptr) {
delete m_outputLayout;
}
m_evaluation = m_expression->evaluate(*context);
if (m_evaluationLayout != nullptr) {
delete m_evaluationLayout;
m_output = m_input->evaluate(*context);
if (m_outputLayout != nullptr) {
delete m_outputLayout;
}
m_evaluationLayout = m_evaluation->createLayout();
m_outputLayout = m_output->createLayout();
}
Calculation::~Calculation() {
if (m_layout != nullptr) {
delete m_layout;
if (m_inputLayout != nullptr) {
delete m_inputLayout;
}
if (m_expression != nullptr) {
delete m_expression;
if (m_input != nullptr) {
delete m_input;
}
if (m_evaluation != nullptr) {
delete m_evaluation;
if (m_output != nullptr) {
delete m_output;
}
if (m_evaluationLayout != nullptr) {
delete m_evaluationLayout;
if (m_outputLayout != nullptr) {
delete m_outputLayout;
}
}
@@ -83,24 +83,24 @@ const char * Calculation::text() {
return m_text;
}
Expression * Calculation::expression() {
return m_expression;
Expression * Calculation::input() {
return m_input;
}
ExpressionLayout * Calculation::layout() {
return m_layout;
ExpressionLayout * Calculation::inputLayout() {
return m_inputLayout;
}
Expression * Calculation::evaluation() {
return m_evaluation;
Expression * Calculation::output() {
return m_output;
}
ExpressionLayout * Calculation::evaluationLayout() {
return m_evaluationLayout;
ExpressionLayout * Calculation::outputLayout() {
return m_outputLayout;
}
bool Calculation::isEmpty() {
if (m_expression == nullptr) {
if (m_input == nullptr) {
return true;
}
return false;

View File

@@ -11,19 +11,19 @@ public:
~Calculation(); // Delete expression and layout, if needed
Calculation & operator= (const Calculation & other);
const char * text();
Expression * expression();
ExpressionLayout * layout();
Expression * evaluation();
ExpressionLayout * evaluationLayout();
Expression * input();
ExpressionLayout * inputLayout();
Expression * output();
ExpressionLayout * outputLayout();
void setContent(const char * c, Context * context);
bool isEmpty();
constexpr static int k_maximalExpressionTextLength = 255;
private:
char m_text[k_maximalExpressionTextLength];
Expression * m_expression;
ExpressionLayout * m_layout;
Expression * m_evaluation;
ExpressionLayout * m_evaluationLayout;
Expression * m_input;
ExpressionLayout * m_inputLayout;
Expression * m_output;
ExpressionLayout * m_outputLayout;
};
}

View File

@@ -15,7 +15,7 @@ Expression * EvaluateContext::ansValue() {
return defaultExpression();
}
Calculation * lastCalculation = m_calculationStore->calculationAtIndex(m_calculationStore->numberOfCalculations()-1);
m_ansValue = lastCalculation->evaluation();
m_ansValue = lastCalculation->output();
return m_ansValue;
}

View File

@@ -47,7 +47,7 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
editController->setTextBody(calculation->text());
} else {
char resultText[Calculation::k_maximalExpressionTextLength];
calculation->evaluation()->writeTextInBuffer(resultText, Calculation::k_maximalExpressionTextLength);
calculation->output()->writeTextInBuffer(resultText, Calculation::k_maximalExpressionTextLength);
editController->setTextBody(resultText);
}
m_selectableTableView.deselectTable();
@@ -65,7 +65,7 @@ bool HistoryController::handleEvent(Ion::Events::Event event) {
newCalculation = *calculation;
} else {
char resultText[Calculation::k_maximalExpressionTextLength];
calculation->evaluation()->writeTextInBuffer(resultText, Calculation::k_maximalExpressionTextLength);
calculation->output()->writeTextInBuffer(resultText, Calculation::k_maximalExpressionTextLength);
/* TODO: this will work when we will parse float */
//App * calculationApp = (App *)app();
//newCalculation.setContent(resultText, calculationApp->evaluateContext());
@@ -151,8 +151,8 @@ void HistoryController::willDisplayCellForIndex(TableViewCell * cell, int index)
KDCoordinate HistoryController::rowHeight(int j) {
Calculation * calculation = m_calculationStore->calculationAtIndex(j);
KDCoordinate prettyPrintHeight = calculation->layout()->size().height();
KDCoordinate resultHeight = calculation->evaluationLayout()->size().height();
KDCoordinate prettyPrintHeight = calculation->inputLayout()->size().height();
KDCoordinate resultHeight = calculation->outputLayout()->size().height();
return prettyPrintHeight + resultHeight + 3*HistoryViewCell::k_digitVerticalMargin;
}

View File

@@ -51,8 +51,8 @@ void HistoryViewCell::layoutSubviews() {
}
void HistoryViewCell::setCalculation(Calculation * calculation) {
m_prettyPrint.setExpression(calculation->layout());
m_result.setExpression(calculation->evaluationLayout());
m_prettyPrint.setExpression(calculation->inputLayout());
m_result.setExpression(calculation->outputLayout());
}
void HistoryViewCell::reloadCell() {