amath  1.8.5 Simple command line calculator
FunctionNode Class Reference

Represents a mathematical function in a syntax tree. More...

`#include <node.h>`

Inheritance diagram for FunctionNode:
Collaboration diagram for FunctionNode:

## Public Member Functions

FunctionNode (ExpressionNode *expression, char *text, char *sys)

~FunctionNode ()

int GetPrecedence ()

char * GetText ()

virtual SyntaxNodeGetNext ()

virtual void Attach (SyntaxNode *node)

virtual void Detach (SyntaxNode *node)

virtual void Replace (SyntaxNode *n, SyntaxNode *x)

Public Member Functions inherited from ExpressionNode
ExpressionNode ()

ExpressionNode (Number *value)

virtual ~ExpressionNode ()

NodeType GetNodeType ()

virtual bool IsSilent ()

virtual NumberEvaluate ()=0

char * GetTextCode ()

char * Execute ()

Public Member Functions inherited from SyntaxNode
SyntaxNode ()

virtual ~SyntaxNode ()

void SetFirstNode ()

bool GetFirstNode () const

SyntaxNodeGetParent () const

void SetParent (SyntaxNode *node)

virtual ReductionType GetReductionType ()

virtual void ResetIterator ()

## Protected Member Functions

virtual char * GetNodeText ()

## Protected Attributes

ExpressionNodeexpression

char * name

char * sysname

Protected Attributes inherited from ExpressionNode
Numberresult

Protected Attributes inherited from SyntaxNode
CharBufferoutput

SyntaxNodeparent

SyntaxNodeiterator

bool leftBottom

## Detailed Description

Represents a mathematical function in a syntax tree.

Function nodes in syntax trees can both be well known functions like cosine (cos) and also user defined functions. The function node represents a function call and not a function definition.

A formal description of mathematical functions can be found at Wikipedia: https://wikipedia.org/wiki/Function_(mathematics)

When instantiating a function node an argument must be supplied. The argument is a pointer to an expression node representing the value which should be used when computing the function value.

Definition at line 50 of file node.h.

## ◆ FunctionNode()

 FunctionNode::FunctionNode ( ExpressionNode * expression, char * text, char * sys )
explicit

Definition at line 34 of file node.cpp.

References AllocAndCopy(), expression, ExpressionNode::ExpressionNode(), name, and sysname.

34  :
35  ExpressionNode(), expression(expression)
36 {
37  AllocAndCopy(&this->name, text);
38  AllocAndCopy(&this->sysname, sys);
39 }
ExpressionNode()
Definition: nodes.cpp:89
char * sysname
Definition: node.h:68
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
char * name
Definition: node.h:67
ExpressionNode * expression
Definition: node.h:66
Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ ~FunctionNode()

 FunctionNode::~FunctionNode ( )

Definition at line 41 of file node.cpp.

References expression, name, and sysname.

42 {
43  if (expression != nullptr)
44  {
45  delete expression;
46  }
47
48  if (name != nullptr)
49  {
50  delete name;
51  }
52
53  if (sysname != nullptr)
54  {
55  delete sysname;
56  }
57 }
char * sysname
Definition: node.h:68
char * name
Definition: node.h:67
ExpressionNode * expression
Definition: node.h:66

## ◆ Attach()

 void FunctionNode::Attach ( SyntaxNode * node )
virtual

Implements SyntaxNode.

Reimplemented in UserFunctionNode.

Definition at line 97 of file node.cpp.

References expression, and SyntaxNode::SetParent().

98 {
99  if (expression == nullptr)
100  {
101  expression = static_cast<ExpressionNode*>(node);
102  node->SetParent(this);
103  }
104 }
void SetParent(SyntaxNode *node)
Definition: nodes.cpp:75
Base class for all nodes related to mathematical expressions.
Definition: nodes.h:99
ExpressionNode * expression
Definition: node.h:66
Here is the call graph for this function:

## ◆ Detach()

 void FunctionNode::Detach ( SyntaxNode * node )
virtual

Implements SyntaxNode.

Reimplemented in UserFunctionNode.

Definition at line 106 of file node.cpp.

References expression.

107 {
108  if (expression == node)
109  {
110  expression = nullptr;
111  }
112 }
ExpressionNode * expression
Definition: node.h:66

## ◆ GetNext()

 SyntaxNode * FunctionNode::GetNext ( )
virtual

Implements SyntaxNode.

Reimplemented in UserFunctionNode.

Definition at line 86 of file node.cpp.

References expression, and SyntaxNode::iterator.

87 {
88  if (iterator == nullptr)
89  {
91  return expression;
92  }
93
94  return nullptr;
95 }
SyntaxNode * iterator
Definition: nodes.h:87
ExpressionNode * expression
Definition: node.h:66

## ◆ GetNodeText()

 char * FunctionNode::GetNodeText ( )
protectedvirtual

Implements ExpressionNode.

Reimplemented in UserFunctionNode.

Definition at line 79 of file node.cpp.

References PreferencesBase::GetRefactorNames(), name, Program::Preferences, and sysname.

Referenced by GetText().

80 {
82  ? sysname
83  : name;
84 }
Master control class.
Definition: program.h:55
char * sysname
Definition: node.h:68
char * name
Definition: node.h:67
bool GetRefactorNames()
class PreferencesBase * Preferences
Definition: program.h:73
Here is the call graph for this function:
Here is the caller graph for this function:

## ◆ GetPrecedence()

 int FunctionNode::GetPrecedence ( )
virtual

Implements ExpressionNode.

Definition at line 59 of file node.cpp.

60 {
61  return 5;
62 }

## ◆ GetText()

 char * FunctionNode::GetText ( )
virtual

Implements ExpressionNode.

Definition at line 64 of file node.cpp.

65 {
66  const char* functionText = GetNodeText();
67  const char* expText = expression->GetText();
68
69  output->EnsureSize(StrLen(functionText) + StrLen(expText) + 2 + 1);
70  output->Empty();
71  output->Append(functionText);
72  output->Append("(");
73  output->Append(expText);
74  output->Append(")");
75
76  return output->GetString();
77 }
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
void Append(const char *source)
Definition: charbuf.cpp:262
virtual char * GetNodeText()
Definition: node.cpp:79
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
virtual char * GetText()=0
CharBuffer * output
Definition: nodes.h:85
void EnsureSize(unsigned int size)
Ensure a memory block of specified size is allocated.
Definition: charbuf.cpp:114
ExpressionNode * expression
Definition: node.h:66
Here is the call graph for this function:

## ◆ Replace()

 void FunctionNode::Replace ( SyntaxNode * n, SyntaxNode * x )
virtual

Implements SyntaxNode.

Reimplemented in UserFunctionNode.

Definition at line 114 of file node.cpp.

References expression.

115 {
116  if (expression == n)
117  {
118  delete expression;
119  expression = static_cast<ExpressionNode*>(x);
120  }
121 }
Base class for all nodes related to mathematical expressions.
Definition: nodes.h:99
ExpressionNode * expression
Definition: node.h:66

## ◆ name

 char* FunctionNode::name
protected

Definition at line 67 of file node.h.

Referenced by FunctionNode(), GetNodeText(), and ~FunctionNode().

## ◆ sysname

 char* FunctionNode::sysname
protected

Definition at line 68 of file node.h.

Referenced by FunctionNode(), GetNodeText(), and ~FunctionNode().

The documentation for this class was generated from the following files: