amath  1.8.5
Simple command line calculator
PromptStatement Class Reference

Set prompt string. More...

#include <prompt.h>

Inheritance diagram for PromptStatement:
Collaboration diagram for PromptStatement:

Public Member Functions

 PromptStatement (char *prompt)
 
 ~PromptStatement ()
 
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 * prompt
 

Additional Inherited Members

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

Detailed Description

Set prompt string.

Definition at line 40 of file prompt.h.

Constructor & Destructor Documentation

◆ PromptStatement()

PromptStatement::PromptStatement ( char *  prompt)

Definition at line 34 of file prompt.cpp.

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

Referenced by Parser::ParsePromptStatement().

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

◆ ~PromptStatement()

PromptStatement::~PromptStatement ( )

Definition at line 40 of file prompt.cpp.

References prompt.

41 {
42  delete prompt;
43 }
char * prompt
Definition: prompt.h:48

Member Function Documentation

◆ Execute()

char * PromptStatement::Execute ( )
virtual

Implements StatementNode.

Definition at line 45 of file prompt.cpp.

References CharBuffer::Append(), CharBuffer::CharBuffer(), CharBuffer::ClearAndCopy(), CharBuffer::GetString(), prompt, CharBuffer::RemoveTrailing(), Program::SetPrompt(), and StatementNode::statementText.

46 {
47  CharBuffer* buf = new CharBuffer();
48  buf->ClearAndCopy(prompt);
49  // ReSharper disable once CppPossiblyErroneousEmptyStatements
50  while (buf->RemoveTrailing(' '));
51  buf->Append(' ');
52  Program->SetPrompt(buf->GetString());
53  delete buf;
54  return statementText;
55 }
void SetPrompt(const char *text) const
Definition: program.cpp:113
Master control class.
Definition: program.h:55
char * GetString() const
Definition: charbuf.cpp:306
char * statementText
Definition: node.h:55
bool RemoveTrailing(const char c)
Definition: charbuf.cpp:270
void Append(const char *source)
Definition: charbuf.cpp:262
char * prompt
Definition: prompt.h:48
void ClearAndCopy(const char *source)
Release memory, allocate and copy source.
Definition: charbuf.cpp:81
Encapsulate an character array which can be used as a string.
Definition: charbuf.h:44
Here is the call graph for this function:

Member Data Documentation

◆ prompt

char* PromptStatement::prompt
private

Definition at line 48 of file prompt.h.

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


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