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
Term Class Reference

#include <milo.h>

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

Public Member Functions

void simplify (NodePtr ref, TermPtr new_term)
 
void setParent ()
 
void setParent (Expression *parent)
 
NodeIter begin ()
 
NodeIter end ()
 
void multiply (double n)
 
void multiply (TermPtr old_term)
 
std::shared_ptr< Term > getSharedPtr ()
 
Constructor and Virtual Destructor
 Term (Parser &p, Expression *parent=nullptr)
 
 Term (EqnXMLParser &in, Node *parent=nullptr)
 
 Term (NodeVector &f, Expression *parent)
 
 Term (Node *node, Expression *parent=nullptr, bool fNeg=false)
 
 ~Term ()
 
Virtual Public Member Functions
std::string toString () const
 
bool isLeaf () const
 
bool isFactor () 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 less (NodePtr b) const
 

Static Public Member Functions

static Node * parse (Parser &p, Node *parent=nullptr)
 
static bool simplify (TermVector &terms, TermVector::iterator a, TermVector::iterator b)
 
static void insertAfterMe (Node *me, NodePtr node)
 
static NodeIter pos (Node *me)
 
- Static Public Member Functions inherited from Node
static bool createNodeByName (std::string name, Equation &eqn)
 

Static Public Attributes

static const std::string name = "term"
 Name of Term class.
 
static const std::type_index type = typeid(Term)
 Type of Term 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)
 
Complex getNodeValue () const
 
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
 

Private Attributes

NodeVector factors
 Term owns this tree.
 
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 a term as a vector of factors which are multiplied together.

Constructor & Destructor Documentation

Term::Term ( Parser &  p,
Expression *  parent = nullptr 
)
inline

Parser constructor for Term class.

Parameters
pParser object.
parentParent node.
Term::Term ( EqnXMLParser &  in,
Node *  parent = nullptr 
)

XML constructor for Term class. Read in XML for Term class.

Parameters
inXML input stream.
parentParent node object.
Term::Term ( NodeVector &  f,
Expression *  parent 
)
inline

Constructor for Term class loading in factors from a node vector.

Parameters
fFactors to be loaded into new Term object.
parentParent expresion.
Term::Term ( Node *  node,
Expression *  parent = nullptr,
bool  fNeg = false 
)
inline

Constructor for Term class.

Parameters
nodeInitialize node vector with this node.
parentParent expresion.
fNegIf true, node is negative.
Term::~Term ( )
inline

Abstract base class needs virtual destructor.

Member Function Documentation

bool Term::add ( Parser &  p)
private

Add factors to this Term object from parser.

Returns
True if factors were added.
NodeIter Term::begin ( )
inline

Get iterator to first factor of Term.

Returns
Iterator of first factor.
void Term::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 Term::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* Term::downLeft ( )
inlineprivatevirtual

Get left node. For Term class is its first factor.

Returns
Left node.

Reimplemented from Node.

Node* Term::downRight ( )
inlineprivatevirtual

Get right node. For Term class is its last factor.

Returns
Right node.

Reimplemented from Node.

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

Draw this node in the given graphical context.

Parameters
gcGraphical context.

Implements Node.

NodeIter Term::end ( )
inline

Get iterator to end of Term.

Returns
Last factor iterator.
Node * Term::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 * Term::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 * Term::getLeftSibling ( Node *  node)
privatevirtual

Left sibiling of given node.

Parameters
nodeReference node.
Returns
Left sibiling or null.

Reimplemented from Node.

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

Get name of this class.

Returns
Name of this class.

Implements Node.

Complex Term::getNodeValue ( ) const
privatevirtual

Get value of this subtree.

Returns
Complex value of this subtree.

Implements Node.

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

Right sibiling of given node.

Parameters
nodeReference node.
Returns
Right sibiling or null.

Reimplemented from Node.

std::shared_ptr<Term> Term::getSharedPtr ( )
inline

Return shared_ptr for this Term object. Downcast it from base Node shared pointer.

Returns
Shared pointer for this Term object
std::type_index Term::getType ( ) const
inlinevirtual

Get name of this class.

Returns
Name of this class.

Implements Node.

void Term::insertAfterMe ( Node *  me,
NodePtr  node 
)
static

Insert new node after a reference node in node vector.

Parameters
meReference node.
nodeNew node.
bool Term::isFactor ( ) const
inlinevirtual

Override for isFactor virtual function.

Returns
False, this node is not a factor.

Reimplemented from Node.

bool Term::isLeaf ( ) const
inlinevirtual

Override for isLeaf virtual function.

Returns
False, this node has child nodes.

Reimplemented from Node.

void Term::multiply ( double  n)

Multiply this term by a number by inserting Number object.

Parameters
nValue to multiply term by.
void Term::multiply ( TermPtr  old_term)

Mulitiply this by term by another term.

Parameters
old_termMove factors into this Term object.
void Term::normalize ( )
virtual

Refactor subtree to a standard form. For Term class, reorder factors in a standard order and combine common factors. 2cb(3a)^4 normalized to 162bc(a^4)

Reimplemented from Node.

int Term::numFactors ( ) const
virtual

Get number of factor in this subtree.

Returns
Return total number of factors in term.

Reimplemented from Node.

Node * Term::parse ( Parser &  p,
Node *  parent = nullptr 
)
static

Static helper function to parse Term class.

Parameters
pParser object pointing to operator.
parentParent node.
Returns
Number object or null if number not present.
NodeIter Term::pos ( Node *  me)
static

Helper static function to get iterator to given node.

Parameters
mePointer to a factor.
Returns
Iterator to node.
void Term::setParent ( )
inline

Set all factor's parent to this Term.

void Term::setParent ( Expression *  parent)
inline

Reset parent expression of this Term.

Parameters
parentNew parent expression.
bool Term::simplify ( )
virtual

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

Returns
True, if subtree was changed.

Reimplemented from Node.

void Term::simplify ( NodePtr  ref,
TermPtr  new_term 
)

Helper function to take factors from a term and insert into this term.

Parameters
refNode in this term where new factors will be inserted.
new_termTerm object with factors to be transferred.
bool Term::simplify ( TermVector &  terms,
TermVector::iterator  a,
TermVector::iterator  b 
)
static

Compare every term to every other term to see if can combined. If terms are the same excpet for a number, they are combined.

Parameters
termsReference to term vector.
aIterator to first term to be compared.
bIterator to second term to be compared. If terms are combined this is deleted.
Returns
True if terms were combined.
string Term::toString ( ) const
virtual

Get string representation of Term class. The factors are concatenated into one string.

Returns
String representation of Term class.

Implements Node.

void Term::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: