amath  1.8.5
Simple command line calculator
AbsoluteNode Class Reference

#include <operators.h>

Inheritance diagram for AbsoluteNode:
Collaboration diagram for AbsoluteNode:

Public Member Functions

 AbsoluteNode (ExpressionNode *expression)
 
 ~AbsoluteNode ()
 
char * GetText ()
 
NumberEvaluate ()
 
int GetPrecedence ()
 
SyntaxNodeGetNext ()
 
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 ReductionType GetReductionType ()
 
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 64 of file operators.h.

Constructor & Destructor Documentation

◆ AbsoluteNode()

AbsoluteNode::AbsoluteNode ( ExpressionNode expression)

Definition at line 139 of file operators.cpp.

References expression, and ExpressionNode::ExpressionNode().

Referenced by Parser::ParseAtomic().

139  :
140  ExpressionNode(), expression(expression)
141 {
142 }
ExpressionNode()
Definition: nodes.cpp:89
ExpressionNode * expression
Definition: operators.h:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~AbsoluteNode()

AbsoluteNode::~AbsoluteNode ( )

Definition at line 144 of file operators.cpp.

References expression.

145 {
146  if (expression != nullptr)
147  {
148  delete expression;
149  }
150 }
ExpressionNode * expression
Definition: operators.h:82

Member Function Documentation

◆ Attach()

void AbsoluteNode::Attach ( SyntaxNode node)
virtual

Implements SyntaxNode.

Definition at line 194 of file operators.cpp.

References expression, and SyntaxNode::SetParent().

195 {
196  if (expression == nullptr)
197  {
198  expression = static_cast<ExpressionNode*>(node);
199  node->SetParent(this);
200  }
201 }
void SetParent(SyntaxNode *node)
Definition: nodes.cpp:75
ExpressionNode * expression
Definition: operators.h:82
Base class for all nodes related to mathematical expressions.
Definition: nodes.h:99
Here is the call graph for this function:

◆ Detach()

void AbsoluteNode::Detach ( SyntaxNode node)
virtual

Implements SyntaxNode.

Definition at line 203 of file operators.cpp.

References expression.

204 {
205  if (expression == node)
206  {
207  expression = nullptr;
208  }
209 }
ExpressionNode * expression
Definition: operators.h:82

◆ Evaluate()

Number * AbsoluteNode::Evaluate ( )
virtual

Implements ExpressionNode.

Definition at line 171 of file operators.cpp.

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

172 {
174  return result;
175 }
virtual Number * Absolute()=0
virtual Number * Evaluate()=0
Number * result
Definition: nodes.h:116
ExpressionNode * expression
Definition: operators.h:82
Here is the call graph for this function:

◆ GetNext()

SyntaxNode * AbsoluteNode::GetNext ( )
virtual

Implements SyntaxNode.

Definition at line 183 of file operators.cpp.

References expression, and SyntaxNode::iterator.

184 {
185  if (iterator == nullptr)
186  {
188  return iterator;
189  }
190 
191  return nullptr;
192 }
ExpressionNode * expression
Definition: operators.h:82
SyntaxNode * iterator
Definition: nodes.h:87

◆ GetNodeText()

char * AbsoluteNode::GetNodeText ( )
protectedvirtual

Implements ExpressionNode.

Definition at line 177 of file operators.cpp.

Referenced by GetText().

178 {
179  static char* ret = (char*)"|";
180  return ret;
181 }
Here is the caller graph for this function:

◆ GetPrecedence()

int AbsoluteNode::GetPrecedence ( )
virtual

Implements ExpressionNode.

Definition at line 166 of file operators.cpp.

167 {
168  return 8;
169 }

◆ GetText()

char * AbsoluteNode::GetText ( )
virtual

Implements ExpressionNode.

Definition at line 152 of file operators.cpp.

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

153 {
154  const char* expText = expression->GetText();
155  const char* nodeText = GetNodeText();
156 
157  output->Empty();
158  output->EnsureSize(StrLen(expText) + StrLen(nodeText) * 2 + 1);
159  output->Append(nodeText);
160  output->Append(expText);
161  output->Append(nodeText);
162 
163  return output->GetString();
164 }
void Empty()
Definition: charbuf.cpp:218
char * GetString() const
Definition: charbuf.cpp:306
void Append(const char *source)
Definition: charbuf.cpp:262
char * GetNodeText()
Definition: operators.cpp:177
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
ExpressionNode * expression
Definition: operators.h:82
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 AbsoluteNode::Replace ( SyntaxNode n,
SyntaxNode x 
)
virtual

Implements SyntaxNode.

Definition at line 211 of file operators.cpp.

References expression.

212 {
213  if (expression == n)
214  {
215  delete expression;
216  expression = static_cast<ExpressionNode*>(x);
217  }
218 }
ExpressionNode * expression
Definition: operators.h:82
Base class for all nodes related to mathematical expressions.
Definition: nodes.h:99

Member Data Documentation

◆ expression

ExpressionNode* AbsoluteNode::expression
private

Definition at line 82 of file operators.h.

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


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