amath  1.8.5
Simple command line calculator
Variable Class Reference

A user defined variable. More...

#include <values.h>

Collaboration diagram for Variable:

Public Member Functions

 Variable (const char *name)
 
 ~Variable ()
 
char * GetName () const
 
NumberGetValue () const
 
void AssignValue (Number *value)
 

Public Attributes

VariableNext
 

Private Attributes

char * name
 
Numbervalue
 
bool chainDelete
 

Friends

bool VariableList::Delete (const char *name)
 

Detailed Description

A user defined variable.

Definition at line 76 of file values.h.

Constructor & Destructor Documentation

◆ Variable()

Variable::Variable ( const char *  name)
explicit

Definition at line 46 of file values.cpp.

References AllocAndCopy(), chainDelete, name, Next, and value.

Referenced by UserFunction::CreateVariable(), VariableList::CreateVariable(), and UserFunction::UserFunction().

47 {
48  AllocAndCopy(&this->name, name);
49  value = nullptr;
50  Next = nullptr;
51  chainDelete = true;
52 }
bool chainDelete
Definition: values.h:91
Number * value
Definition: values.h:90
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
char * name
Definition: values.h:89
Variable * Next
Definition: values.h:86
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~Variable()

Variable::~Variable ( )

Definition at line 54 of file values.cpp.

References chainDelete, name, Next, and value.

55 {
56  delete [] name;
57 
58  if (value != nullptr)
59  {
60  delete value;
61  }
62 
63  if (chainDelete && Next != nullptr)
64  {
65  delete Next;
66  }
67 }
bool chainDelete
Definition: values.h:91
Number * value
Definition: values.h:90
char * name
Definition: values.h:89
Variable * Next
Definition: values.h:86

Member Function Documentation

◆ AssignValue()

void Variable::AssignValue ( Number value)

Definition at line 79 of file values.cpp.

References Number::Clone(), and value.

Referenced by VariableNode::AssignValue(), UserFunctionNode::Evaluate(), and Grid::FunctionValue().

80 {
81  if (this->value != nullptr)
82  {
83  delete this->value;
84  }
85 
86  this->value = value->Clone();
87 }
virtual Number * Clone()=0
Number * value
Definition: values.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetName()

char * Variable::GetName ( ) const

◆ GetValue()

Number * Variable::GetValue ( ) const

Definition at line 74 of file values.cpp.

References Number::Clone(), and value.

Referenced by VariableNode::Evaluate(), and VariableList::ListContent().

75 {
76  return value->Clone();;
77 }
virtual Number * Clone()=0
Number * value
Definition: values.h:90
Here is the call graph for this function:
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ VariableList::Delete

bool VariableList::Delete ( const char *  name)
friend

Member Data Documentation

◆ chainDelete

bool Variable::chainDelete
private

Definition at line 91 of file values.h.

Referenced by VariableList::Delete(), Variable(), and ~Variable().

◆ name

char* Variable::name
private

Definition at line 89 of file values.h.

Referenced by GetName(), Variable(), and ~Variable().

◆ Next

◆ value

Number* Variable::value
private

Definition at line 90 of file values.h.

Referenced by AssignValue(), GetValue(), Variable(), and ~Variable().


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