Milo  0.1
Milo:EquationManipulationProgram
Classes | Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | List of all members
Node Class Referenceabstract

#include <milo.h>

Inheritance diagram for Node:
Inheritance graph
[legend]
Collaboration diagram for Node:
Collaboration graph
[legend]

Classes

struct  Frame
 

Public Types

enum  Select { NONE, START, END, ALL }
 

Public Member Functions

void calculateSize (UI::Graphics &gc)
 
void out (XML::Stream &xml)
 
void calculateOrigin (UI::Graphics &gc, int x, int y)
 
void setUpDraw (UI::Graphics &gc)
 
void draw (UI::Graphics &gc) const
 
void setSelect (Select s)
 
Select getSelect () const
 
void setDrawParenthesis (bool fDrawPar)
 
bool getDrawParenthesis () const
 
const Frame & getFrame () const
 
Node * first ()
 
Node * last ()
 
Node * getNextLeft ()
 
Node * getNextRight ()
 
void setParent (Node *parent)
 
Node * getParent () const
 
int getDepth () const
 
int getNth () const
 
void addNth (int n)
 
void multNth (int n)
 
void setNth (int n)
 
void negative ()
 
bool getSign () const
 
Complex getValue () const
 
std::shared_ptr< Node > getSharedPtr ()
 
Constructors and Virtual Destructor
 Node (Node *parent=nullptr, bool fNeg=false, Select s=NONE)
 
 Node (EqnXMLParser &in, Node *parent)
 
virtual ~Node ()
 Abstract base class needs virtual desctructor.
 
Virtual Public Member Functions
virtual std::string toString () const =0
 
virtual bool isLeaf () const
 
virtual bool isFactor () const
 
virtual Node * findNode (int x, int y)
 
virtual Node * findNode (const Box &b)
 
virtual int numFactors () const
 
virtual void normalize ()
 
virtual bool simplify ()
 
virtual bool less (NodePtr b) const
 
virtual const std::string & getName () const =0
 
virtual std::type_index getType () const =0
 

Static Public Member Functions

static bool createNodeByName (std::string name, Equation &eqn)
 

Static Public Attributes

static const std::vector< std::string > select_tags = { "NONE", "START", "END", "ALL" }
 

Private Member Functions

int getDepth (int depth) const
 
Virtual Private Member Functions
virtual Node * downLeft ()
 
virtual Node * downRight ()
 
virtual Node * getLeftSibling (Node *)
 
virtual Node * getRightSibling (Node *)
 
virtual Frame calcSize (UI::Graphics &gc)=0
 
virtual void calcOrig (UI::Graphics &gc, int x, int y)=0
 
virtual void drawNode (UI::Graphics &gc) const =0
 
virtual Complex getNodeValue () const =0
 
virtual void xml_out (XML::Stream &xml) const =0
 

Private Attributes

Node * m_parent
 Parent node of this node. Can be null if root.
 
bool m_sign
 True if positve.
 
Select m_select
 Select state of this node.
 
Frame m_frame
 Frame of this node includes enclosing rect and vertical offset.
 
Box m_parenthesis
 Rectangle that contains paranthesis of this node.
 
int m_nth = 1
 Integer power of ths node.
 
bool m_fDrawParenthesis = false
 If true, draw paranthesis around this node.
 

Detailed Description

Abstract base class for symbolic classes that make up an equation. Any class that will be part of the equation tree structor derives from this class.

Member Enumeration Documentation

Possible selection states for a node:

NONE - not selected

START - node starts selection

END - node ends selection

ALL- just this node selected

Constructor & Destructor Documentation

Node::Node ( Node *  parent = nullptr,
bool  fNeg = false,
Select  s = NONE 
)
inline

Constructor for Node class. Directly initialize the Node class private data members.

Parameters
parentNode object that is parent of this node. If NULL, this node is root.
fNegTrue, if node is negated.
sNode selection state.
Node::Node ( EqnXMLParser &  in,
Node *  parent 
)

XML constructor for Node class. Initialize the constructor from XML input stream.

Parameters
inXML input stream.
parentParent node object.

Member Function Documentation

void Node::addNth ( int  n)
inline

Add integer n to power value of this node.

Parameters
nInteget power to be added.
virtual void Node::calcOrig ( UI::Graphics &  gc,
int  x,
int  y 
)
privatepure virtual

Calculate origin of the nodes in the subtree relative to point x,y.

Parameters
gcGraphics context.
xHorizontal origin.
yVertical origin.

Implemented in Input, Differential, Function, Expression, Number, Term, Variable, Constant, Power, and Divide.

virtual Frame Node::calcSize ( UI::Graphics &  gc)
privatepure virtual

Calculate frame of this node's subtree in graphics context. Frame includes size and vertical offset.

Parameters
gcGraphics context.
Returns
Return frame of this subtree.

Implemented in Input, Differential, Function, Expression, Number, Term, Variable, Constant, Power, and Divide.

void Node::calculateOrigin ( UI::Graphics &  gc,
int  x,
int  y 
)

Calculate origin of each node in subtree. The size of each node in subtree needs to be precalculated.

Parameters
gcGraphics context to calculate origin.
xHorizontal origin of root node in subtree.
yVertical origin of root node in subtree.
void Node::calculateSize ( UI::Graphics &  gc)

Calculate size of node subtree in given graphics context.

Parameters
gcGraphics context used to calculate size.
bool Node::createNodeByName ( std::string  name,
Equation &  eqn 
)
static

Create node by its name in the given equation

Parameters
nameName of node to be created.
eqnEquation that has current input to take node
Returns
True, if node was created
virtual Node* Node::downLeft ( )
inlineprivatevirtual

Get left most node of this node's subtree. Default function returns NULL assuming it is leaf node.

Returns
Left most node of this node's subtree.

Reimplemented in Differential, Function, Expression, Term, and Binary.

virtual Node* Node::downRight ( )
inlineprivatevirtual

Get right most node of this node's subtree. Default function returns NULL assuming it is leaf node.

Returns
Righ most node of this node's subtree.

Reimplemented in Differential, Function, Expression, Term, and Binary.

void Node::draw ( UI::Graphics &  gc) const

Draw equation subtree whose root is this node.

Parameters
gcGraphics context class object.
virtual void Node::drawNode ( UI::Graphics &  gc) const
privatepure virtual

Draw subtree in this graphics context.

Parameters
gcGraphics context.

Implemented in Input, Differential, Function, Expression, Number, Term, Variable, Constant, Power, and Divide.

Node * Node::findNode ( int  x,
int  y 
)
virtual

Virtual recursive function to return deepest node at point (x,y). Leaf nodes will return true or false depending on whether (x,y) is inside their box. Non-leaf nodes will query their children.

Parameters
xhorizontal coordinate.
yvertical coordinate.
Returns
Deepest node at point (x,y).

Reimplemented in Differential, Function, Expression, Term, and Binary.

Node * Node::findNode ( const Box &  b)
virtual

Virtual recursive function to return first node from a top to bottom search whose frame is inside Box b.

Parameters
bBounding box.
Returns
Top node inside bounding box.

Reimplemented in Differential, Function, Expression, Term, and Binary.

Node * Node::first ( )

Get left most node of this node's subtree.

Returns
Left mode node.
int Node::getDepth ( ) const
inline

Get depth from root of this node. 0 is root.

Returns
Depth of this node.
int Node::getDepth ( int  depth) const
inlineprivate

Recursively calculate the depth of this node.

Parameters
depthCurrent calculated depth.
Returns
Return depth of this node.
bool Node::getDrawParenthesis ( ) const
inline

Get draw parenthesis flag of this node.

Returns
Draw parenthesis flag value.
const Frame& Node::getFrame ( ) const
inline

Get frame of this node.

Returns
Frame of this node.
virtual Node* Node::getLeftSibling ( Node *  )
inlineprivatevirtual

Get left sibiling of node argument. Default function returns NULL assuming this is a leaf node.

Returns
Left sibling node.

Reimplemented in Expression, Term, and Binary.

virtual const std::string& Node::getName ( ) const
pure virtual

Get final class name of node class object.

Returns
Class name of node object.

Implemented in Input, Differential, Function, Expression, Number, Variable, Term, Constant, Power, and Divide.

Node * Node::getNextLeft ( )

Get next left node, going up if necessary.

Returns
Next left node.
Node * Node::getNextRight ( )

Get next right node, going up if necessary.

Returns
Next right node.
virtual Complex Node::getNodeValue ( ) const
privatepure virtual

Get value of this node's subtree.

Returns
Subtree value.

Implemented in Input, Differential, Function, Expression, Number, Term, Variable, Constant, Power, and Divide.

int Node::getNth ( ) const
inline

Get value of integer power of this node.

Returns
Value of m_nth.
Node* Node::getParent ( ) const
inline

Get parent of this node.

Returns
Parent node.
virtual Node* Node::getRightSibling ( Node *  )
inlineprivatevirtual

Get right sibiling of node argument. Default function returns NULL assuming this is a leaf node.

Returns
Right sibling node.

Reimplemented in Expression, Term, and Binary.

Select Node::getSelect ( ) const
inline

Get selection state of this node.

Returns
Selection state of this node.
std::shared_ptr<Node> Node::getSharedPtr ( )
inline

Return shared_ptr for this Node object. If none exists, create one.

Returns
Shared pointer for this Node object
bool Node::getSign ( ) const
inline

Get sign of this node.

Returns
True if positive.
virtual std::type_index Node::getType ( ) const
pure virtual

Get final class type of node class object.

Returns
Class type of node object.

Implemented in Input, Differential, Function, Expression, Number, Variable, Term, Constant, Power, and Divide.

Complex Node::getValue ( ) const

Calculate value of this node and it subtree.

Returns
Calculated value of this node's subtree.
virtual bool Node::isFactor ( ) const
inlinevirtual

Virtual function to query whether this node is a factor. Default function returns true. Only class Term returns false.

Returns
True if a factor.

Reimplemented in Term.

virtual bool Node::isLeaf ( ) const
inlinevirtual

Virtual function to query whether this is a leaf node or subtree. Default function returns true. Override to return false.

Returns
True if there are no child nodes.

Reimplemented in Differential, Function, Expression, Term, and Binary.

Node * Node::last ( )

Get right most node of this node's subtree.

Returns
Right mode node.
virtual bool Node::less ( NodePtr  b) const
inlinevirtual

Compare this node string representation to the given node's string representation. Default function works for most nodes but some are overridden.

Parameters
bNode to compare. @
Returns
True if this node is less than given node.

Reimplemented in Function.

void Node::multNth ( int  n)
inline

Multiply integer n to power value of this node.

Parameters
nInteger power to be multiplied.
void Node::negative ( )
inline

Negate this node.

virtual void Node::normalize ( )
inlinevirtual

Put node's subtree to a standard algebraic form.

Reimplemented in Differential, Function, Expression, Term, Power, and Divide.

virtual int Node::numFactors ( ) const
inlinevirtual

Virtual function that queries node of number of factor in its subtree. Default function returns 1 which is correct for leaf node. Non-leaf node queries its children.

Returns
Number of factors in node's subtree.

Reimplemented in Input, Differential, Function, Expression, Term, and Binary.

void Node::out ( XML::Stream &  xml)

Serialize this node and child nodes to XML output stream.

Parameters
xmlXML ouput stream.
void Node::setDrawParenthesis ( bool  fDrawPar)
inline

Set draw parenthesis flag of this node.

Parameters
fDrawParIf true, draw a parenthesises around node.
void Node::setNth ( int  n)
inline

Set integer power value of this node.

Parameters
nInteger power to be set.
void Node::setParent ( Node *  parent)
inline

Set parent of this node.

void Node::setSelect ( Select  s)
inline

Set selection state of this node.

Parameters
sNew selection state of node.
void Node::setUpDraw ( UI::Graphics &  gc)

Calculate the size and origin of the subtree of this node.

Parameters
gcGraphics context class object.
virtual bool Node::simplify ( )
inlinevirtual

Simplify node's subtree algebraiclly.

Returns
True if node's subtree was changed.

Reimplemented in Differential, Expression, Number, Term, Power, and Divide.

virtual std::string Node::toString ( ) const
pure virtual

Recursive virtual function to represent this subtree as string.

Returns
String representing this node and child nodes.

Implemented in Input, Differential, Function, Expression, Number, Variable, Term, Constant, and Binary.

virtual void Node::xml_out ( XML::Stream &  xml) const
privatepure virtual

Stream subtree to XML stream.

Parameters
xmlXML stream.

Implemented in Input, Differential, Function, Expression, Number, Term, Variable, Constant, and Binary.

Member Data Documentation

const vector< string > Node::select_tags = { "NONE", "START", "END", "ALL" }
static

List of strings corresponding to enum Select. Use enum State as index into select_tags to get its strings.


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