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

#include <nodes.h>

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

Public Types

using func_ptr = Complex(*)(Complex)
 
using func_map = std::unordered_map< std::string, func_ptr >
 Map that associates function name with its function call.
 
- Public Types inherited from Node
enum  Select { NONE, START, END, ALL }
 

Public Member Functions

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 less (NodePtr b) const
 
const std::string & getName () const
 
std::type_index getType () const
 
Constructor and Virtual Destructor
 Function (const std::string &name, func_ptr fp, Parser &p, Node *parent, bool neg=false, Node::Select s=Node::Select::NONE)
 
 Function (EqnXMLParser &in, Node *parent)
 
 ~Function ()
 
- 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 simplify ()
 

Static Public Member Functions

static Function * 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 = "function"
 Name of Function class.
 
static const std::type_index type = typeid(Function)
 Type of Function type.
 
- Static Public Attributes inherited from Node
static const std::vector< std::string > select_tags = { "NONE", "START", "END", "ALL" }
 

Private Member Functions

Virtual Private Member Functions
Node * downLeft ()
 
Node * downRight ()
 
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
 

Static Private Member Functions

static Complex sinZ (Complex z)
 Function for sin.
 
static Complex cosZ (Complex z)
 Function for cos.
 
static Complex tanZ (Complex z)
 Function for tan.
 
static Complex logZ (Complex z)
 Function for log.
 
static Complex expZ (Complex z)
 Function for exp.
 

Private Attributes

std::string m_name
 Name of function.
 
func_ptr m_func
 Function pointer to evaluate function.
 
NodePtr m_arg
 Function own this tree.
 
Box m_internal
 Bounding box of this node.
 

Static Private Attributes

static const func_map functions
 

Detailed Description

Represents a function by containing an expression passed to a mathematical function.

Member Typedef Documentation

Function pointer that takes a single complex argument and returns a complex value.

Constructor & Destructor Documentation

Function::Function ( const std::string &  name,
func_ptr  fp,
Parser &  p,
Node *  parent,
bool  neg = false,
Node::Select  s = Node::Select::NONE 
)
inline

Constructor for Function class.

Parameters
nameName of function.
fpPointer to function to evaluate arguments.
pParser object.
parentParent node.
negIf true, node is negative.
sSelection state of node.
Function::Function ( EqnXMLParser &  in,
Node *  parent 
)

XML constructor for Function class. Read in XML for Function class.

Parameters
inXML input stream.
parentParent node object.
Function::~Function ( )
inline

Abstract base class needs virtual destructor.

Member Function Documentation

void Function::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 Function::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* Function::downLeft ( )
inlineprivatevirtual

Get left node. For Function class left most node of argument.

Returns
Left node.

Reimplemented from Node.

Node* Function::downRight ( )
inlineprivatevirtual

Get right node. For Function class right most node of argument.

Returns
Right node.

Reimplemented from Node.

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

Draw this node in the given graphical context.

Parameters
gcGraphical context.

Implements Node.

Node * Function::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 * Function::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.

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

Get name of this class.

Returns
Name of this class.

Implements Node.

Complex Function::getNodeValue ( ) const
privatevirtual

Get value of this subtree.

Returns
Complex value of this subtree.

Implements Node.

std::type_index Function::getType ( ) const
inlinevirtual

Get name of this class.

Returns
Name of this class.

Implements Node.

bool Function::isLeaf ( ) const
inlinevirtual

Override for isLeaf virtual function.

Returns
False, this node has child nodes.

Reimplemented from Node.

bool Function::less ( NodePtr  b) const
virtual

Function class specialization of default virtural member function. Sort functions in reverse alphabetical order.

Parameters
bReference node.
Returns
True, if b is less than this node.

Reimplemented from Node.

void Function::normalize ( )
inlinevirtual

Refactor subtree to a standard form. For Function class, normalize argument.

Reimplemented from Node.

int Function::numFactors ( ) const
inlinevirtual

Get number of factors in this node.

Returns
Number of factors of argument plus this node.

Reimplemented from Node.

Function * Function::parse ( Parser &  p,
Node *  parent 
)
static

Get function object from Parser.

Parameters
pParser object.
parentParent for new Function object.
Returns
Function object or null if no function found in parser.
std::string Function::toString ( ) const
inlinevirtual

Get representation of Function as string. String representation is function_name(argument).

Returns
String representation of Function.

Implements Node.

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

Output XML of this node.

Parameters
xmlXML output stream.

Implements Node.

Member Data Documentation

const Function::func_map Function::functions
staticprivate
Initial value:
= {
{ "sin", &sinZ },
{ "cos", &cosZ },
{ "tan", &tanZ },
{ "log", &logZ },
{ "exp", &expZ }
}

Association of function names with their function pointers.


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