amath  1.8.5
Simple command line calculator
UnaryNode Class Reference

#include <operators.h>

Inheritance diagram for UnaryNode:
Collaboration diagram for UnaryNode:

Public Member Functions

 UnaryNode (ExpressionNode *expression)
 
 ~UnaryNode ()
 
ReductionType GetReductionType ()
 
int GetPrecedence ()
 
SyntaxNodeGetNext ()
 
char * GetText ()
 
NumberEvaluate ()
 
void Attach (SyntaxNode *node)
 
void Detach (SyntaxNode *node)
 
void Replace (SyntaxNode *n, SyntaxNode *x)
 
- Public Member Functions inherited from ExpressionNode
 ExpressionNode ()
 
 ExpressionNode (Number *value)
 
virtual ~ExpressionNode ()
 
NodeType GetNodeType ()
 
virtual bool IsSilent ()
 
char * GetTextCode ()
 
char * Execute ()
 
- Public Member Functions inherited from SyntaxNode
 SyntaxNode ()
 
virtual ~SyntaxNode ()
 
void SetFirstNode ()
 
bool GetFirstNode () const
 
SyntaxNodeGetParent () const
 
void SetParent (SyntaxNode *node)
 
virtual void ResetIterator ()
 

Protected Member Functions

char * GetNodeText ()
 

Private Attributes

ExpressionNodeexpression
 

Additional Inherited Members

- Protected Attributes inherited from ExpressionNode
Numberresult
 
- Protected Attributes inherited from SyntaxNode
CharBufferoutput
 
SyntaxNodeparent
 
SyntaxNodeiterator
 
bool leftBottom
 

Detailed Description

Definition at line 42 of file operators.h.

Constructor & Destructor Documentation

◆ UnaryNode()

UnaryNode::UnaryNode ( ExpressionNode expression)

Definition at line 39 of file operators.cpp.

References expression, and ExpressionNode::ExpressionNode().

Referenced by Parser::ParseUnary().

39  :
40  ExpressionNode(), expression(expression)
41 {
42 }
ExpressionNode * expression
Definition: operators.h:61
ExpressionNode()
Definition: nodes.cpp:89
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~UnaryNode()

UnaryNode::~UnaryNode ( )

Definition at line 44 of file operators.cpp.

References expression.

45 {
46  if (expression != nullptr)
47  {
48  delete expression;
49  }
50 }
ExpressionNode * expression
Definition: operators.h:61

Member Function Documentation

◆ Attach()

void UnaryNode::Attach ( SyntaxNode node)
virtual

Implements SyntaxNode.

Definition at line 109 of file operators.cpp.

References expression, and SyntaxNode::SetParent().

110 {
111  if (expression == nullptr)
112  {
113  expression = static_cast<ExpressionNode*>(node);
114  node->SetParent(this);
115  }
116 }
ExpressionNode * expression
Definition: operators.h:61
void SetParent(SyntaxNode *node)
Definition: nodes.cpp:75
Base class for all nodes related to mathematical expressions.
Definition: nodes.h:99
Here is the call graph for this function:

◆ Detach()

void UnaryNode::Detach ( SyntaxNode node)
virtual

Implements SyntaxNode.

Definition at line 118 of file operators.cpp.

References expression.

119 {
120  if (expression == node)
121  {
122  expression = nullptr;
123  }
124 }
ExpressionNode * expression
Definition: operators.h:61

◆ Evaluate()

Number * UnaryNode::Evaluate ( )
virtual

Implements ExpressionNode.

Definition at line 92 of file operators.cpp.

References ExpressionNode::Evaluate(), expression, ExpressionNode::result, and Number::Unary().

93 {
95  return result;
96 }
ExpressionNode * expression
Definition: operators.h:61
virtual Number * Unary()=0
virtual Number * Evaluate()=0
Number * result
Definition: nodes.h:116
Here is the call graph for this function:

◆ GetNext()

SyntaxNode * UnaryNode::GetNext ( )
virtual

Implements SyntaxNode.

Definition at line 98 of file operators.cpp.

References expression, and SyntaxNode::iterator.

99 {
100  if (iterator == nullptr)
101  {
103  return iterator;
104  }
105 
106  return nullptr;
107 }
ExpressionNode * expression
Definition: operators.h:61
SyntaxNode * iterator
Definition: nodes.h:87

◆ GetNodeText()

char * UnaryNode::GetNodeText ( )
protectedvirtual

Implements ExpressionNode.

Definition at line 62 of file operators.cpp.

Referenced by GetText().

63 {
64  static char* ret = (char*)"-";
65  return ret;
66 }
Here is the caller graph for this function:

◆ GetPrecedence()

int UnaryNode::GetPrecedence ( )
virtual

Implements ExpressionNode.

Definition at line 57 of file operators.cpp.

Referenced by GetText().

58 {
59  return 7;
60 }
Here is the caller graph for this function:

◆ GetReductionType()

ReductionType UnaryNode::GetReductionType ( )
virtual

Reimplemented from SyntaxNode.

Definition at line 52 of file operators.cpp.

References unaryreduc.

53 {
54  return unaryreduc;
55 }

◆ GetText()

char * UnaryNode::GetText ( )
virtual

Implements ExpressionNode.

Definition at line 68 of file operators.cpp.

References CharBuffer::Append(), CharBuffer::Empty(), CharBuffer::EnsureSize(), expression, GetNodeText(), GetPrecedence(), ExpressionNode::GetPrecedence(), CharBuffer::GetString(), ExpressionNode::GetText(), SyntaxNode::output, and StrLen().

69 {
70  const char* expText = expression->GetText();
71  const char* nodeText = GetNodeText();
72 
73  output->Empty();
74  output->EnsureSize(StrLen(expText) + StrLen(nodeText) + 2 + 1);
75 
77  {
78  output->Append(nodeText);
79  output->Append("(");
80  output->Append(expText);
81  output->Append(")");
82  }
83  else
84  {
85  output->Append(nodeText);
86  output->Append(expText);
87  }
88 
89  return output->GetString();
90 }
ExpressionNode * expression
Definition: operators.h:61
void Empty()
Definition: charbuf.cpp:218
char * GetNodeText()
Definition: operators.cpp:62
char * GetString() const
Definition: charbuf.cpp:306
void Append(const char *source)
Definition: charbuf.cpp:262
int GetPrecedence()
Definition: operators.cpp:57
virtual int GetPrecedence()=0
int StrLen(const char *string)
Get the length of a null terminated string.
Definition: strlen.c:34
virtual char * GetText()=0
CharBuffer * output
Definition: nodes.h:85
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:

◆ Replace()

void UnaryNode::Replace ( SyntaxNode n,
SyntaxNode x 
)
virtual

Implements SyntaxNode.

Definition at line 126 of file operators.cpp.

References expression.

127 {
128  if (expression == n)
129  {
130  delete expression;
131  expression = static_cast<ExpressionNode*>(x);
132  }
133 }
ExpressionNode * expression
Definition: operators.h:61
Base class for all nodes related to mathematical expressions.
Definition: nodes.h:99

Member Data Documentation

◆ expression

ExpressionNode* UnaryNode::expression
private

Definition at line 61 of file operators.h.

Referenced by Attach(), Detach(), Evaluate(), GetNext(), GetText(), Replace(), UnaryNode(), and ~UnaryNode().


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