Update functions to use the clone interface.

Change-Id: I6b4d6be5b1d963bc7d97851432e40844d3619d8d
This commit is contained in:
Felix Raimundo
2016-03-24 16:54:53 +01:00
parent f5f5399e92
commit 4707459a19
8 changed files with 46 additions and 4 deletions

View File

@@ -5,9 +5,10 @@
class Cosinus : public Function {
public:
Cosinus(Expression * arg): Function(arg, (char*) "cos") {}
Cosinus(Expression * arg, bool clone_arg=true): Function(arg, (char*) "cos", clone_arg) {}
float approximate(Context& context) override;
Type type() override;
Expression * clone() override;
};
#endif

View File

@@ -5,9 +5,11 @@
class Function : public Expression {
public:
Function(Expression * arg, char* function_name): m_arg(arg), m_function_name(function_name) {}
Function(Expression * arg, char* function_name, bool clone_operands=true);
~Function();
ExpressionLayout * createLayout(ExpressionLayout * parent) override;
Expression * operand(int i) override;
int numberOfOperands() override;
protected:
Expression * m_arg;
private:

View File

@@ -5,9 +5,10 @@
class Sinus : public Function {
public:
Sinus(Expression * arg): Function(arg, (char*) "sin") {}
Sinus(Expression * arg, bool clone_arg=true): Function(arg, (char*) "sin", clone_arg) {}
float approximate(Context& context) override;
Type type() override;
Expression * clone() override;
};
#endif

View File

@@ -5,9 +5,10 @@
class Tangent : public Function {
public:
Tangent(Expression * arg): Function(arg, (char*) "tan") {}
Tangent(Expression * arg, bool clone_arg=true): Function(arg, (char*) "tan", clone_arg) {}
float approximate(Context& context) override;
Type type() override;
Expression * clone() override;
};
#endif

View File

@@ -1,6 +1,10 @@
#include <poincare/cosinus.h>
#include "layout/horizontal_layout.h"
Expression * Cosinus::clone() {
return new Cosinus(m_arg, true);
}
Expression::Type Cosinus::type() {
return Expression::Type::Cosinus;
}

View File

@@ -1,6 +1,19 @@
extern "C" {
#include <stdlib.h>
}
#include <poincare/function.h>
#include "layout/function_layout.h"
Function::Function(Expression * arg, char* function_name, bool clone_operands) {
m_arg = (Expression *)malloc(sizeof(Expression));
m_function_name = function_name;
if (clone_operands) {
m_arg = arg->clone();
} else {
m_arg = arg;
}
}
Function::~Function() {
delete m_arg;
}
@@ -8,3 +21,15 @@ Function::~Function() {
ExpressionLayout * Function::createLayout(ExpressionLayout * parent) {
return new FunctionLayout(parent, m_function_name, m_arg);
}
Expression * Function::operand(int i) {
if (i==0) {
return m_arg;
} else {
return nullptr;
}
}
int Function::numberOfOperands() {
return 1;
}

View File

@@ -1,6 +1,10 @@
#include <poincare/sinus.h>
#include "layout/horizontal_layout.h"
Expression * Sinus::clone() {
return new Sinus(m_arg, true);
}
Expression::Type Sinus::type() {
return Expression::Type::Sinus;
}

View File

@@ -1,6 +1,10 @@
#include <poincare/tangent.h>
#include "layout/horizontal_layout.h"
Expression * Tangent::clone() {
return new Tangent(m_arg, true);
}
Expression::Type Tangent::type() {
return Expression::Type::Tangent;
}