amath  1.8.5
Simple command line calculator
DeleteStatement Class Reference

Delete variable or function. More...

#include <delete.h>

Inheritance diagram for DeleteStatement:
Collaboration diagram for DeleteStatement:

Public Member Functions

 DeleteStatement (Symbol symbol)
 Constructor used to delete either all variable or functions. More...
 
 DeleteStatement (const char *name)
 Constructor used to delete a Variable. More...
 
 DeleteStatement (const char *name, const char *argument)
 Constructor used to delete a function. More...
 
 ~DeleteStatement ()
 
char * Execute ()
 
- Public Member Functions inherited from StatementNode
 StatementNode ()
 
 StatementNode (const char *text)
 
virtual ~StatementNode ()
 
NodeType GetNodeType ()
 
virtual SyntaxNodeGetNext ()
 
virtual char * GetTextCode ()
 
void Attach (SyntaxNode *node)
 
void Detach (SyntaxNode *node)
 
void Replace (SyntaxNode *n, SyntaxNode *x)
 
- 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 ()
 

Private Attributes

Symbol type
 
char * name
 
char * argument
 

Additional Inherited Members

- Protected Attributes inherited from StatementNode
char * statementText
 
- Protected Attributes inherited from SyntaxNode
CharBufferoutput
 
SyntaxNodeparent
 
SyntaxNodeiterator
 
bool leftBottom
 

Detailed Description

Delete variable or function.

Definition at line 39 of file delete.h.

Constructor & Destructor Documentation

◆ DeleteStatement() [1/3]

DeleteStatement::DeleteStatement ( Symbol  symbol)
explicit

Constructor used to delete either all variable or functions.

Definition at line 40 of file delete.cpp.

References argument, name, StatementNode::StatementNode(), and type.

Referenced by Parser::ParseDeleteStatement().

40  :
42 {
43  type = symbol;
44  name = nullptr;
45  argument = nullptr;
46 }
char * name
Definition: delete.h:50
char * argument
Definition: delete.h:51
Symbol type
Definition: delete.h:49
StatementNode()
Definition: node.cpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeleteStatement() [2/3]

DeleteStatement::DeleteStatement ( const char *  name)
explicit

Constructor used to delete a Variable.

Definition at line 52 of file delete.cpp.

References AllocAndCopy(), argument, name, StatementNode::StatementNode(), symvariable, and type.

Referenced by Parser::ParseDeleteStatement().

52  :
54 {
55  type = symvariable;
56  AllocAndCopy(&this->name, name);
57  argument = nullptr;
58 }
char * name
Definition: delete.h:50
char * argument
Definition: delete.h:51
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
Symbol type
Definition: delete.h:49
StatementNode()
Definition: node.cpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ DeleteStatement() [3/3]

DeleteStatement::DeleteStatement ( const char *  name,
const char *  argument 
)

Constructor used to delete a function.

Definition at line 64 of file delete.cpp.

References AllocAndCopy(), argument, name, StatementNode::StatementNode(), symfunction, and type.

Referenced by Parser::ParseDeleteStatement().

64  :
66 {
67  type = symfunction;
68  AllocAndCopy(&this->name, name);
70 }
char * name
Definition: delete.h:50
char * argument
Definition: delete.h:51
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
Symbol type
Definition: delete.h:49
StatementNode()
Definition: node.cpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~DeleteStatement()

DeleteStatement::~DeleteStatement ( )

Definition at line 73 of file delete.cpp.

References argument, and name.

74 {
75  if (name != nullptr)
76  {
77  delete [] name;
78  }
79 
80  if (argument != nullptr)
81  {
82  delete [] argument;
83  }
84 }
char * name
Definition: delete.h:50
char * argument
Definition: delete.h:51

Member Function Documentation

◆ Execute()

char * DeleteStatement::Execute ( )
virtual

Implements StatementNode.

Definition at line 86 of file delete.cpp.

References CharBuffer::Append(), argument, FunctionList::Clear(), VariableList::Clear(), FunctionList::Delete(), CharBuffer::Empty(), CharBuffer::EnsureSize(), Program::Functions, CharBuffer::GetString(), name, SyntaxNode::output, StatementNode::statementText, StrLen(), symfunction, symvariable, type, Variable::VariableList::Delete, and Program::Variables.

87 {
88  bool success = true;
89  output->Empty();
90 
91  if (type == symvariable && name == nullptr)
92  {
94  }
95  else if (type == symvariable && name != nullptr)
96  {
97  success = Program->Variables->Delete(name);
98  const char* msg = HELPVARNDEF;
99 
101  StrLen(msg) +
102  StrLen(name) +
103  StrLen(NEWLINE) + 1);
104 
105  output->Append(msg);
106  output->Append(name);
108  }
109  else if (type == symfunction && name == nullptr)
110  {
111  Program->Functions->Clear();
112  }
113  else if (type == symfunction && name != nullptr)
114  {
115  success = Program->Functions->Delete(name, argument);
116  const char* msg = HELPFUNNDEF;
117 
119  StrLen(msg) +
120  StrLen(name) + 2 +
121  StrLen(argument) +
122  StrLen(NEWLINE) + 1);
123 
124  output->Append(msg);
125  output->Append(name);
126  output->Append("(");
128  output->Append(")");
130  }
131 
132  char* temp = success
133  ? statementText
134  : output->GetString();
135 
136  return temp;
137 }
#define NEWLINE
Definition: amath.h:222
Master control class.
Definition: program.h:55
char * name
Definition: delete.h:50
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
char * statementText
Definition: node.h:55
char * argument
Definition: delete.h:51
void Append(const char *source)
Definition: charbuf.cpp:262
class FunctionList * Functions
Definition: program.h:78
#define HELPVARNDEF
Definition: text.h:80
void Clear()
Definition: values.cpp:109
#define HELPFUNNDEF
Definition: text.h:81
Symbol type
Definition: delete.h:49
bool Delete(const char *name)
Definition: values.cpp:120
class VariableList * Variables
Definition: program.h:77
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
CharBuffer * output
Definition: nodes.h:85
bool Delete(const char *name, const char *argument)
void EnsureSize(unsigned int size)
Ensure a memory block of specified size is allocated.
Definition: charbuf.cpp:114
Here is the call graph for this function:

Member Data Documentation

◆ argument

char* DeleteStatement::argument
private

Definition at line 51 of file delete.h.

Referenced by DeleteStatement(), Execute(), and ~DeleteStatement().

◆ name

char* DeleteStatement::name
private

Definition at line 50 of file delete.h.

Referenced by DeleteStatement(), Execute(), and ~DeleteStatement().

◆ type

Symbol DeleteStatement::type
private

Definition at line 49 of file delete.h.

Referenced by DeleteStatement(), and Execute().


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