Milo  0.1
Milo:EquationManipulationProgram
Public Member Functions | Static Public Member Functions | Static Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Expression Class Reference

#include <milo.h>

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

Public Member Functions

int numTerms () const
 
void setParent ()
 
TermVector::iterator begin ()
 
TermVector::iterator end ()
 
void add (double n)
 
void add (ExpressionPtr old_expr)
 
Constructor and Virtual Destructor
 Expression (EqnXMLParser &in, Node *parent=nullptr)
 
 Expression (Parser &p, Node *parent=nullptr)
 
 Expression (Term *term, Node *parent=nullptr)
 
 Expression (Node *factor, Node *parent=nullptr)
 
 ~Expression ()
 
Virtual Public Member Functions
std::string toString () const
 
bool isLeaf () const
 
Node * findNode (int x, int y)
 
Node * findNode (const Box &b)
 
int numFactors () const
 
void normalize ()
 
bool simplify ()
 
const std::string & getName () const
 
std::type_index getType () const
 
- Public Member Functions inherited from Node
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 ()
 
 Node (Node *parent=nullptr, bool fNeg=false, Select s=NONE)
 
 Node (EqnXMLParser &in, Node *parent)
 
virtual ~Node ()
 Abstract base class needs virtual desctructor.
 
virtual bool isFactor () const
 
virtual bool less (NodePtr b) const
 

Static Public Member Functions

static Term * getTerm (Equation &eqn, const std::string &text, Expression *parent=nullptr)
 
static Term * getTerm (Parser &p, Expression *parent)
 
static Node * parse (Parser &p, Node *parent)
 
- Static Public Member Functions inherited from Node
static bool createNodeByName (std::string name, Equation &eqn)
 

Static Public Attributes

static const std::string name = "expression"
 Name of this class.
 
static const std::type_index type = typeid(Expression)
 Type of this class.
 
- Static Public Attributes inherited from Node
static const std::vector< std::string > select_tags = { "NONE", "START", "END", "ALL" }
 

Private Member Functions

bool add (Parser &p)
 
Virtual Private Member Functions
Node * downLeft ()
 
Node * downRight ()
 
Node * getLeftSibling (Node *node)
 
Node * getRightSibling (Node *node)
 
void xml_out (XML::Stream &xml) const
 
Frame calcSize (UI::Graphics &gc)
 
void calcOrig (UI::Graphics &gc, int x, int y)
 
void drawNode (UI::Graphics &gc) const
 
Complex getNodeValue () const
 

Private Attributes

TermVector terms
 Expression owns this tree a list of terms.
 
Box m_internal
 Bounding box of this node.
 

Friends

class FactorIterator
 

Additional Inherited Members

- Public Types inherited from Node
enum  Select { NONE, START, END, ALL }
 

Detailed Description

Represents an expression as a vector of terms which are added together. Subtract happens by setting nodes to a negative sign. A vector of (ac,-b,2,i,3) is equivalent to ac-b+2+i3.

Constructor & Destructor Documentation

Expression::Expression ( EqnXMLParser &  in,
Node *  parent = nullptr 
)

XML constructor for Expression class. Read in XML for Expression class.

Parameters
inXML input stream.
parentParent node object.
Expression::Expression ( Parser &  p,
Node *  parent = nullptr 
)
inline

Parser constructor for Expression class.

Parameters
pParser object.
parentParent node.
Expression::Expression ( Term *  term,
Node *  parent = nullptr 
)
inline

Constructor for Expression class.

Parameters
termInitialize term vector with this term.
parentParent expresion.
Expression::Expression ( Node *  factor,
Node *  parent = nullptr 
)
inline

Constructor for Expression class.

Parameters
factorInitialize term vector with new term containing node.
parentParent expresion.
Expression::~Expression ( )
inline

Abstract base class needs virtual destructor.

Member Function Documentation

void Expression::add ( double  n)

Add a Number to expression.

Parameters
nNumeric value to be added.
Returns
Expression + n.
void Expression::add ( ExpressionPtr  old_expr)

Add terms from Expression object.

Parameters
old_exprExpression object.
bool Expression::add ( Parser &  p)
private

Add terms to expression from parser.

Parameters
pParser object.
Returns
True, if term was added.
TermVector::iterator Expression::begin ( )
inline

Get iterator to first term of Expression.

Returns
Iterator of first term.
void Expression::calcOrig ( UI::Graphics &  gc,
int  x,
int  y 
)
privatevirtual

Calculate origin of this node offset from the point (x,y) given it.

Parameters
gcGraphics context.
xHorizontal origin.
yVertical origin.

Implements Node.

Node::Frame Expression::calcSize ( UI::Graphics &  gc)
privatevirtual

Calculate size of this node in given graphics context.

Parameters
gcGraphics context.
Returns
Return frame containing size of this node.

Implements Node.

Node* Expression::downLeft ( )
inlineprivatevirtual

Get left node. For Expression class is its first term.

Returns
Left node.

Reimplemented from Node.

Node* Expression::downRight ( )
inlineprivatevirtual

Get right node. For Expression class is its last term.

Returns
Right node.

Reimplemented from Node.

void Expression::drawNode ( UI::Graphics &  gc) const
privatevirtual

Draw this node in the given graphical context.

Parameters
gcGraphical context.

Implements Node.

TermVector::iterator Expression::end ( )
inline

Get iterator to end of Expression.

Returns
Last term iterator.
Node * Expression::findNode ( int  x,
int  y 
)
virtual

Rescursive search to find deepest node at point (x,y).

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

Reimplemented from Node.

Node * Expression::findNode ( const Box &  b)
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 from Node.

Node * Expression::getLeftSibling ( Node *  node)
privatevirtual

Left sibiling of given node.

Parameters
nodeReference node.
Returns
Left sibiling or null.

Reimplemented from Node.

const std::string& Expression::getName ( ) const
inlinevirtual

Get name of this class.

Returns
Name of this class.

Implements Node.

Complex Expression::getNodeValue ( ) const
privatevirtual

Get value of this subtree.

Returns
Complex value of this subtree.

Implements Node.

Node * Expression::getRightSibling ( Node *  node)
privatevirtual

Right sibiling of given node.

Parameters
nodeReference node.
Returns
Right sibiling or null.

Reimplemented from Node.

static Term* Expression::getTerm ( Equation &  eqn,
const std::string &  text,
Expression *  parent = nullptr 
)
static

Helper static function to parse term from string value.

Parameters
eqnEquation containg parent expression.
textString value to be parsed.
parentParent expression.
Returns
Created Term object.
Term * Expression::getTerm ( Parser &  p,
Expression *  parent 
)
static

Helper static function to parse term.

Parameters
pParser object.
parentParent expression.
Returns
Created Term object.
std::type_index Expression::getType ( ) const
inlinevirtual

Get name of this class.

Returns
Name of this class.

Implements Node.

bool Expression::isLeaf ( ) const
inlinevirtual

Override for isLeaf virtual function.

Returns
False, this node has child nodes.

Reimplemented from Node.

void Expression::normalize ( )
virtual

Refactor subtree to a standard form. For Expression class, reorder terms in alphabetical order and combine common terms. ab+3ba normalized to 4ab.

Reimplemented from Node.

int Expression::numFactors ( ) const
virtual

Get number of factors in this node.

Returns
Number of factors.

Reimplemented from Node.

int Expression::numTerms ( ) const
inline

Get number of terms.

Returns
Number of terms.
Node * Expression::parse ( Parser &  p,
Node *  parent 
)
static

Helper static function to parse Expression.

Parameters
pParser object.
parentParent expression.
Returns
Created Expression object.
void Expression::setParent ( )
inline

Set parent of all terms to this expression.

bool Expression::simplify ( )
virtual

Attempt to algebraically simplify the subtree this node is the root.

Returns
True, if subtree was changed.

Reimplemented from Node.

string Expression::toString ( ) const
virtual

Get representation of expression as string. String are terms separated by '+' or '-'.

Returns
String representation of expression.

Implements Node.

void Expression::xml_out ( XML::Stream &  xml) const
privatevirtual

Output XML of this node.

Parameters
xmlXML output stream.

Implements Node.


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