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

#include <milo.h>

Collaboration diagram for Equation:
Collaboration graph
[legend]

Public Member Functions

std::string toString () const
 
void xml_out (std::ostream &os) const
 
void xml_out (std::string &str) const
 
void draw (UI::Graphics &gc, bool fRefresh=false)
 
Equation * clone ()
 
bool blink ()
 
void getCursorOrig (int &x, int &y)
 
void setCurrentInput (int in_sn)
 
void addInput (Input *in)
 
void removeInput (Input *in)
 
Input * getCurrentInput ()
 
void nextInput (bool fShift)
 
FactorIterator disableCurrentInput ()
 
void setSelectStart (Node *start)
 
void setSelectEnd (Node *end)
 
void clearSelect ()
 Clear current selection.
 
void setSelect (Node *start, Node *end=nullptr)
 
void selectNodeOrInput (Node *node)
 
void setSelectFromNode (Node *node)
 
Node * findNode (UI::Graphics &gc, int x, int y)
 
Node * findNode (UI::Graphics &gc, Box b)
 
void selectBox (UI::Graphics &gc, Node *start, Box b)
 
void eraseSelection (Node *node)
 
bool simplify ()
 
void normalize ()
 
NodeIterator begin ()
 
NodeIterator end ()
 
NodeIterator last ()
 
void insert (FactorIterator &it, const std::string &text)
 
Node * getRoot ()
 
Node * getSelectStart ()
 
Node * getSelectEnd ()
 
Constructors and Virtual Destructor
 Equation (const std::string &eq)
 
 Equation (std::istream &is)
 
 Equation (const Equation &eqn)
 
 ~Equation ()
 
Overloaded Equal Operators
Equation & operator= (const Equation &eqn)
 
 Equation (Equation &&eqn)=delete
 No move copy constructor.
 
Equation & operator= (Equation &&eqn)=delete
 No move equal operator.
 

Private Member Functions

void setSelect (UI::Graphics &gc)
 
void factor (std::string text, NodeVector &factors, Node *parent)
 
void xml_out (XML::Stream &xml) const
 
void xml_in (EqnXMLParser &in)
 

Private Attributes

NodePtr m_root
 Equation owns this tree.
 
std::vector< Input * > m_inputs
 List of input nodes in equation.
 
int m_input_index = -1
 Index of current input.
 
Node * m_selectStart = nullptr
 Node at start of selection.
 
Node * m_selectEnd = nullptr
 Node at end of selection.
 

Detailed Description

Holds the node tree that represents a mathematical equation. It also provides an interface for manipulating the nodes to algebraically transform the equation and to save, load and draw an equation.

Constructor & Destructor Documentation

Equation::Equation ( const std::string &  eq)

Constructor to load an equation represented by string such as 'a+b/c'.

Parameters
eqString containing equation to be created.
Equation::Equation ( std::istream &  is)

Constructor to load an equation from xml.

Parameters
isInput stream containing xml.
Equation::Equation ( const Equation &  eqn)
inline

Copy constructor based on overloaded equal operator.

Parameters
eqnEquation class object to be copied
Equation::~Equation ( )
inline

Destructor deletes node tree to clean up after itself.

Member Function Documentation

void Equation::addInput ( Input *  in)
inline

Add new input node to this equation's list of inputs.

Parameters
inNew input node.
NodeIterator Equation::begin ( )
inline

Get left most node of equation.

bool Equation::blink ( )
inline

Check where there is an active input in this equation object.

Returns
If true, there is an active input.
Equation * Equation::clone ( )

Get equation object that is copy of this equation object.

Returns
Cloned equation object.
FactorIterator Equation::disableCurrentInput ( )

Remove current input node.

void Equation::draw ( UI::Graphics &  gc,
bool  fRefresh = false 
)

Draw equation in given graphic context.

Parameters
gcGrahics context.
fRefreshIf true, complete all drawing to graphics context.
NodeIterator Equation::end ( )
inline

Get end iterator of equation.

void Equation::eraseSelection ( Node *  node)

Erase current selection and replace with new node. If node parameter is null, selection will just be erased.

Parameters
nodeNode to replace current selection.
void Equation::factor ( std::string  text,
NodeVector &  factors,
Node *  parent 
)
private

Helper static function that parses term in string, load factors into array.

Node * Equation::findNode ( UI::Graphics &  gc,
int  x,
int  y 
)

Query root node for deepest node at coordinates x, y in given graphics context. Call findNode method of root node. If input node found, delete it and search again.

Parameters
gcGraphics context.
xHorizontal coordinate.
yVertical coordinate.
Returns
Node found at x,y coordinates. Null if none found.
Node * Equation::findNode ( UI::Graphics &  gc,
Box  b 
)

Query root node for shallowest factor node at inside rectangle box in given graphics context. Call findNode(UI::Graphics&, Box&) method of root node.

Parameters
gcGraphics context.
bBounding box
Returns
Node found inside bounding box b. Null if none found.
Input* Equation::getCurrentInput ( )
inline

Get current input node.

Returns
Current input node.
void Equation::getCursorOrig ( int &  x,
int &  y 
)

Get coordinates of current active input.

Parameters
[out]xHorizontal origin of curosr.
[out]yVertical origin cursor.
void Equation::insert ( FactorIterator &  it,
const std::string &  text 
)

Use iterator to insert factors from parsed string.

Parameters
[in,out]itIterator to position to insert factors. On exit points to factor after last factor inserted.
textString to get parsed factors.
NodeIterator Equation::last ( )
inline

Get right most node of equation.

void Equation::nextInput ( bool  fShift)

Get next input in list after current input node.

void Equation::normalize ( )
inline

Normalize equation to standard format.

Equation & Equation::operator= ( const Equation &  eqn)

Overloaded equal operator that copies node tree from another object. Given equation object is serialized to xml and then deserialized into this object.

Parameters
eqnEquation class object to be copied.
void Equation::removeInput ( Input *  in)

Remove input node from equation's list of input nodes.

Parameters
inInput node to be removed.
void Equation::selectBox ( UI::Graphics &  gc,
Node *  start,
Box  b 
)

Select region starting from Node object start to last node still in bounding rectangle b.

Parameters
gcGraphics context.
startStarting node.
bBounding box.
void Equation::selectNodeOrInput ( Node *  node)

Either select single node or if Input node make current input.

Parameters
nodeNode to be selected or input to be activated.
void Equation::setCurrentInput ( int  in_sn)

Set current active input node.

Parameters
in_snSerial number of new active input.
void Equation::setSelect ( Node *  start,
Node *  end = nullptr 
)

Set start and end of selection. If end parameter is null, then only start node is selected.

Parameters
startNode that starts selection.
endNode that ends selection.
void Equation::setSelect ( UI::Graphics &  gc)
private

Draw current selection in graphics context.

Parameters
gcGraphics context.
void Equation::setSelectEnd ( Node *  end)
inline

Set end of selection.

Returns
end Node to be end of selection.
void Equation::setSelectFromNode ( Node *  node)

Set selection of this equation from selection state of node. If node has selection set to start, set as start of selection. If node has selection set to end, set as end of selection. If node has selection set to all, set as start and end of selection. return node Node whose selection state is referenced.

void Equation::setSelectStart ( Node *  start)
inline

Set start of selection.

Returns
start Node to be start of selection.
bool Equation::simplify ( )
inline

Simplify equation algebracially. Call normalize() method of root node and then simplifly().

Returns
Return result of m_root->simplify().
std::string Equation::toString ( ) const
inline

Get string representation of equation. Example: '(a+b/c)'.

Returns
String representation of equation.
void Equation::xml_in ( EqnXMLParser &  in)
private

Load equation from input xml stream.

Parameters
inInput XML stream.
void Equation::xml_out ( std::ostream &  os) const

Serialize equation as xml to output stream.

Parameters
osOutput stream.
void Equation::xml_out ( std::string &  str) const

Serialize equation as xml to string.

Parameters
strOutput string object.
void Equation::xml_out ( XML::Stream &  xml) const
private

Output equation into output xml stream.

Returns
xml XML output stream.

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