mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
Update functions to use the clone interface.
Change-Id: I6b4d6be5b1d963bc7d97851432e40844d3619d8d
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user