amath  1.8.5
Simple command line calculator
UserFunction Class Reference

A user defined function. More...

#include <userfunction.h>

Collaboration diagram for UserFunction:

Public Member Functions

 UserFunction (const char *name, const char *variable, ExpressionNode *expression)
 
 UserFunction (const char *name)
 
 ~UserFunction ()
 
char * GetName () const
 
char * GetDefinitionName () const
 
char * GetDefinitionText () const
 
VariableGetVariable () const
 
VariableCreateVariable (const char *name)
 
ExpressionNodeGetExpression () const
 
void SetExpression (ExpressionNode *expression)
 

Public Attributes

UserFunctionNext
 

Private Member Functions

void InitializeTexts () const
 

Private Attributes

char * name
 
Variablevariable
 
ExpressionNodeexpression
 
bool chainDelete
 
CharBufferdefname
 
CharBufferdefinition
 

Friends

bool FunctionList::Delete (const char *name, const char *argument)
 

Detailed Description

A user defined function.

Definition at line 44 of file userfunction.h.

Constructor & Destructor Documentation

◆ UserFunction() [1/2]

UserFunction::UserFunction ( const char *  name,
const char *  variable,
ExpressionNode expression 
)

Definition at line 34 of file userfunction.cpp.

References AllocAndCopy(), chainDelete, CharBuffer::CharBuffer(), definition, defname, expression, InitializeTexts(), name, Next, variable, and Variable::Variable().

35 {
36  AllocAndCopy(&this->name, name);
37  this->variable = new Variable(variable);
38  this->expression = expression;
39  this->Next = nullptr;
40 
41  defname = new CharBuffer();
42  definition = new CharBuffer();
44 
45  chainDelete = true;
46 }
void InitializeTexts() const
UserFunction * Next
Definition: userfunction.h:51
A user defined variable.
Definition: values.h:76
Variable * variable
Definition: userfunction.h:63
CharBuffer * definition
Definition: userfunction.h:70
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
CharBuffer * defname
Definition: userfunction.h:69
ExpressionNode * expression
Definition: userfunction.h:64
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
bool chainDelete
Definition: userfunction.h:65
Here is the call graph for this function:

◆ UserFunction() [2/2]

UserFunction::UserFunction ( const char *  name)
explicit

Definition at line 48 of file userfunction.cpp.

References AllocAndCopy(), chainDelete, CharBuffer::CharBuffer(), definition, defname, expression, name, Next, and variable.

Referenced by FunctionList::GetFunctionDef().

49 {
50  AllocAndCopy(&this->name, name);
51  this->variable = nullptr;
52  this->expression = nullptr;
53  this->Next = nullptr;
54 
55  defname = new CharBuffer();
56  definition = new CharBuffer();
57 
58  chainDelete = true;
59 }
UserFunction * Next
Definition: userfunction.h:51
Variable * variable
Definition: userfunction.h:63
CharBuffer * definition
Definition: userfunction.h:70
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
CharBuffer * defname
Definition: userfunction.h:69
ExpressionNode * expression
Definition: userfunction.h:64
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
bool chainDelete
Definition: userfunction.h:65
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~UserFunction()

UserFunction::~UserFunction ( )

Definition at line 61 of file userfunction.cpp.

References chainDelete, definition, defname, expression, name, Next, and variable.

62 {
63  delete [] name;
64  delete defname;
65  delete definition;
66 
67  if (variable != nullptr)
68  {
69  delete variable;
70  }
71 
72  if (expression != nullptr)
73  {
74  delete expression;
75  }
76 
77  if (chainDelete && Next != nullptr)
78  {
79  delete Next;
80  }
81 }
UserFunction * Next
Definition: userfunction.h:51
Variable * variable
Definition: userfunction.h:63
CharBuffer * definition
Definition: userfunction.h:70
CharBuffer * defname
Definition: userfunction.h:69
ExpressionNode * expression
Definition: userfunction.h:64
bool chainDelete
Definition: userfunction.h:65

Member Function Documentation

◆ CreateVariable()

Variable * UserFunction::CreateVariable ( const char *  name)

Definition at line 117 of file userfunction.cpp.

References InitializeTexts(), variable, and Variable::Variable().

Referenced by Parser::ParseFunctionDef().

118 {
119  if (variable != nullptr)
120  {
121  delete variable;
122  }
123 
124  variable = new Variable(name);
125  InitializeTexts();
126 
127  return variable;
128 }
void InitializeTexts() const
A user defined variable.
Definition: values.h:76
Variable * variable
Definition: userfunction.h:63
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetDefinitionName()

char * UserFunction::GetDefinitionName ( ) const

Definition at line 102 of file userfunction.cpp.

References defname, and CharBuffer::GetString().

103 {
104  return defname->GetString();
105 }
char * GetString() const
Definition: charbuf.cpp:306
CharBuffer * defname
Definition: userfunction.h:69
Here is the call graph for this function:

◆ GetDefinitionText()

char * UserFunction::GetDefinitionText ( ) const

Definition at line 107 of file userfunction.cpp.

References definition, and CharBuffer::GetString().

108 {
109  return definition->GetString();
110 }
char * GetString() const
Definition: charbuf.cpp:306
CharBuffer * definition
Definition: userfunction.h:70
Here is the call graph for this function:

◆ GetExpression()

ExpressionNode * UserFunction::GetExpression ( ) const

Definition at line 130 of file userfunction.cpp.

References expression.

Referenced by UserFunctionNode::Evaluate(), Grid::FunctionValue(), UserFunctionNode::GetNext(), and FunctionList::ListContent().

131 {
132  return expression;
133 }
ExpressionNode * expression
Definition: userfunction.h:64
Here is the caller graph for this function:

◆ GetName()

char * UserFunction::GetName ( ) const

Definition at line 97 of file userfunction.cpp.

References name.

Referenced by FunctionList::Delete(), FunctionList::GetFunctionCall(), FunctionList::GetFunctionDef(), UserFunctionNode::GetNodeText(), and FunctionList::ListContent().

98 {
99  return name;
100 }
Here is the caller graph for this function:

◆ GetVariable()

Variable * UserFunction::GetVariable ( ) const

Definition at line 112 of file userfunction.cpp.

References variable.

Referenced by FunctionList::Delete(), UserFunctionNode::Evaluate(), Grid::FunctionValue(), FunctionList::GetFunctionDef(), and FunctionList::ListContent().

113 {
114  return variable;
115 }
Variable * variable
Definition: userfunction.h:63
Here is the caller graph for this function:

◆ InitializeTexts()

void UserFunction::InitializeTexts ( ) const
private

Definition at line 83 of file userfunction.cpp.

References CharBuffer::Append(), definition, defname, CharBuffer::Empty(), expression, Variable::GetName(), CharBuffer::GetString(), ExpressionNode::GetText(), name, and variable.

Referenced by CreateVariable(), SetExpression(), and UserFunction().

84 {
85  defname->Empty();
87  defname->Append('(');
88  defname->Append(variable != nullptr ? variable->GetName() : EMPTYSTRING);
89  defname->Append(')');
90 
91  definition->Empty();
93  definition->Append('=');
95 }
#define EMPTYSTRING
Definition: amath.h:213
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
Variable * variable
Definition: userfunction.h:63
CharBuffer * definition
Definition: userfunction.h:70
void Append(const char *source)
Definition: charbuf.cpp:262
char * GetName() const
Definition: values.cpp:69
CharBuffer * defname
Definition: userfunction.h:69
ExpressionNode * expression
Definition: userfunction.h:64
virtual char * GetText()=0
Here is the call graph for this function:
Here is the caller graph for this function:

◆ SetExpression()

void UserFunction::SetExpression ( ExpressionNode expression)

Definition at line 135 of file userfunction.cpp.

References expression, and InitializeTexts().

Referenced by Parser::ParseFunctionDef().

136 {
137  delete this->expression;
138  this->expression = expression;
139  InitializeTexts();
140 }
void InitializeTexts() const
ExpressionNode * expression
Definition: userfunction.h:64
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ FunctionList::Delete

bool FunctionList::Delete ( const char *  name,
const char *  argument 
)
friend

Member Data Documentation

◆ chainDelete

bool UserFunction::chainDelete
private

Definition at line 65 of file userfunction.h.

Referenced by FunctionList::Delete(), UserFunction(), and ~UserFunction().

◆ definition

CharBuffer* UserFunction::definition
private

Definition at line 70 of file userfunction.h.

Referenced by GetDefinitionText(), InitializeTexts(), UserFunction(), and ~UserFunction().

◆ defname

CharBuffer* UserFunction::defname
private

Definition at line 69 of file userfunction.h.

Referenced by GetDefinitionName(), InitializeTexts(), UserFunction(), and ~UserFunction().

◆ expression

ExpressionNode* UserFunction::expression
private

◆ name

char* UserFunction::name
private

Definition at line 62 of file userfunction.h.

Referenced by GetName(), InitializeTexts(), UserFunction(), and ~UserFunction().

◆ Next

◆ variable

Variable* UserFunction::variable
private

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