amath  1.8.5
Simple command line calculator
SaveStatement Class Reference

#include <save.h>

Inheritance diagram for SaveStatement:
Collaboration diagram for SaveStatement:

Public Member Functions

 SaveStatement (const char *file)
 
 ~SaveStatement ()
 
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

char * file
 

Additional Inherited Members

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

Detailed Description

Definition at line 35 of file save.h.

Constructor & Destructor Documentation

◆ SaveStatement()

SaveStatement::SaveStatement ( const char *  file)
explicit

Definition at line 35 of file save.cpp.

References AllocAndCopy(), file, and StatementNode::StatementNode().

Referenced by Parser::ParseFileStatement().

36  : StatementNode()
37 {
38  AllocAndCopy(&this->file, file);
39 }
unsigned int AllocAndCopy(char **destination, const char *source)
Allocate memory and copy a string into the array.
Definition: alloccpy.c:40
char * file
Definition: save.h:43
StatementNode()
Definition: node.cpp:34
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~SaveStatement()

SaveStatement::~SaveStatement ( )

Definition at line 41 of file save.cpp.

References file.

42 {
43  delete [] file;
44 }
char * file
Definition: save.h:43

Member Function Documentation

◆ Execute()

char * SaveStatement::Execute ( )
virtual

Implements StatementNode.

Definition at line 46 of file save.cpp.

References CharBuffer::Append(), CharBuffer::CharBuffer(), CharBuffer::Empty(), file, Program::Filesystem, Program::Functions, CharBuffer::GetString(), FunctionList::ListDefinitions(), VariableList::ListDefinitions(), FilesystemBase::SaveTextFile(), StrLen(), and Program::Variables.

47 {
48  const char* vars = Program->Variables->ListDefinitions();
49  const char* funcs = Program->Functions->ListDefinitions();
50 
51  if (vars == nullptr && funcs == nullptr)
52  {
53  return static_cast<char*>(HELPSAVENOTH);
54  }
55 
56  int len = 1;
57  len += vars != nullptr ? StrLen(vars) : 0;
58  len += funcs != nullptr ? StrLen(funcs) : 0;
59 
60  CharBuffer* text = new CharBuffer(len);
61  text->Empty();
62 
63  if (vars != nullptr)
64  {
65  text->Append(vars);
66  }
67  if (funcs != nullptr)
68  {
69  text->Append(funcs);
70  }
71 
72  bool success = Program->Filesystem->SaveTextFile(file, text->GetString());
73  delete text;
74 
75  return static_cast<char*>(success ? HELPSAVESUCC : HELPSAVEFAIL);
76 }
Master control class.
Definition: program.h:55
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
class FilesystemBase * Filesystem
Definition: program.h:74
void Append(const char *source)
Definition: charbuf.cpp:262
char * ListDefinitions() const
Definition: values.cpp:223
char * file
Definition: save.h:43
class FunctionList * Functions
Definition: program.h:78
#define HELPSAVESUCC
Definition: text.h:94
class VariableList * Variables
Definition: program.h:77
#define HELPSAVENOTH
Definition: text.h:96
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
#define HELPSAVEFAIL
Definition: text.h:95
virtual bool SaveTextFile(const char *name, const char *text)=0
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
char * ListDefinitions() const
Here is the call graph for this function:

Member Data Documentation

◆ file

char* SaveStatement::file
private

Definition at line 43 of file save.h.

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


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