# MathFunction Class Reference

Abstract base class for mathematical functions. More...

`#include <Function.h>`

Inheritance diagram for MathFunction:

List of all members.

## Public Member Functions
| MathFunction (string name_, int argc_, int max_argc_=0, string cat_="", string title_="", string descr_="", bool is_active=true)
| MathFunction (const MathFunction *function)
virtual ExpressionItem * | copy () const =0
virtual void | set (const ExpressionItem *item)
virtual int | type () const
virtual int | subtype () const
bool | testArgumentCount (int itmp)
virtual MathStructure | calculate (const string &eq, const EvaluationOptions &eo=default_evaluation_options)
virtual MathStructure | parse (const string &eq, const ParseOptions &po=default_parse_options)
virtual int | parse (MathStructure &mstruct, const string &eq, const ParseOptions &po=default_parse_options)
virtual MathStructure | calculate (MathStructure &vargs, const EvaluationOptions &eo=default_evaluation_options)
virtual int | calculate (MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo)
string | condition () const
string | printCondition ()
void | setCondition (string expression)
bool | testCondition (const MathStructure &vargs)
int | args () const
int | minargs () const
int | maxargs () const
int | args (const string &str, MathStructure &vargs, const ParseOptions &po=default_parse_options)
size_t | lastArgumentDefinitionIndex () const
Argument * | getArgumentDefinition (size_t index)
void | clearArgumentDefinitions ()
void | setArgumentDefinition (size_t index, Argument *argdef)
int | stringArgs (const string &str, vector< string > &svargs)
void | setDefaultValue (size_t arg_, string value_)
const string & | getDefaultValue (size_t arg_) const
void | appendDefaultValues (MathStructure &vargs)
MathStructure | produceVector (const MathStructure &vargs, int begin=-1, int end=-1)
MathStructure | produceArgumentsVector (const MathStructure &vargs, int begin=-1, int end=-1)
virtual bool | representsPositive (const MathStructure &, bool=false) const
virtual bool | representsNegative (const MathStructure &, bool=false) const
virtual bool | representsNonNegative (const MathStructure &, bool=false) const
virtual bool | representsNonPositive (const MathStructure &, bool=false) const
virtual bool | representsInteger (const MathStructure &, bool=false) const
virtual bool | representsNumber (const MathStructure &, bool=false) const
virtual bool | representsRational (const MathStructure &, bool=false) const
virtual bool | representsReal (const MathStructure &, bool=false) const
virtual bool | representsComplex (const MathStructure &, bool=false) const
virtual bool | representsNonZero (const MathStructure &, bool=false) const
virtual bool | representsEven (const MathStructure &, bool=false) const
virtual bool | representsOdd (const MathStructure &, bool=false) const
virtual bool | representsUndefined (const MathStructure &) const
virtual bool | representsBoolean (const MathStructure &) const
virtual bool | representsNonMatrix (const MathStructure &) const
## Protected Member Functions
bool | testArguments (MathStructure &vargs)
virtual MathStructure | createFunctionMathStructureFromVArgs (const MathStructure &vargs)
virtual MathStructure | createFunctionMathStructureFromSVArgs (vector< string > &svargs)
## Protected Attributes
int | argc
int | max_argc
vector< string > | default_values
Sgi::hash_map< size_t, Argument * > | argdefs
size_t | last_argdef_index
string | scondition

## Detailed Description

Abstract base class for mathematical functions.

A mathemical function, subclassed from MathFunction, should at least reimplement calculate(MathStructure&, const MathStructure&, const EvaluationOptions&) and copy(), and preferably also the represents* functions. Argument definitions should be added in the constructor.

## Member Function Documentation

virtual int MathFunction::type | ( |  | ) | const`[virtual]`

Returns the type of the expression item, corresponding to which subclass the object belongs to.

Returns:
  ExpressionItemType.

Implements ExpressionItem.

virtual int MathFunction::subtype | ( |  | ) | const`[virtual]`

Returns the subtype of the mathematical function, corresponding to which subsubclass the object belongs to.

Returns:
  FunctionSubtype.

Implements ExpressionItem.

Reimplemented in DataSet, and UserFunction.

virtual int MathFunction::calculate | ( | MathStructure & | mstruct,
|  | const MathStructure & | vargs,
|  | const EvaluationOptions & | eo |
| ) |  |  | `[virtual]`

The main function for subclasses to reimplement. Calculates a value from arguments in vargs and puts it in mstruct.

This function expects the number of arguments to be equal to the maximum number of arguments, and checked by the argument definitions.

If the return value is negative, then argument -(return value) has been evaluated in mstruct. If -(return value) is greater than max arguments, then mstruct is a vector of evaluated argument values.

Parameters:

  `[out]` | mstruct | Structure that is set with the result of the calculation.
  | vargs | Arguments passed to the mathematical function.
  | eo | Evaluation options.

Returns:
  1 if the calculation was successful.

Reimplemented in DataSet, and UserFunction.

string MathFunction::condition | ( |  | ) | const

Returns the functions condition expression.

Returns:
  The function's condition expression

string MathFunction::printCondition | ( |  | ) |

Print the function's condition expression with argument names.

Returns:
  The printed condition

void MathFunction::setCondition | ( | string | expression | ) |

Sets the functions condition expression.

Parameters:

  | expression | The function's new condition expression

bool MathFunction::testCondition | ( | const MathStructure & | vargs | ) |

Test if arguments fulfil the function's condition expression.

Parameters:

  | vargs | Vector with arguments.

Returns:
  true if the arguments fulfil the function's condition expression

int MathFunction::args | ( |  | ) | const

Returns the maximum number of arguments that the function accepts or -1 if the number of arguments is unlimited.

int MathFunction::minargs | ( |  | ) | const

Returns the minimum number of arguments for the function.

int MathFunction::maxargs | ( |  | ) | const

Returns the maximum number of arguments that the function accepts or -1 if the number of arguments is unlimited.

int MathFunction::args | ( | const string & | str,
|  | MathStructure & | vargs,
|  | const ParseOptions & | po = `default_parse_options` |
| ) |  |  |

Parses arguments from a text string and places them in a vector. The text string should be a comma separated list of arguments.

Parameters:

  | str | The argument string to parse.
  | vargs | Vector to store parsed arguments in.
  | po | Parse options.

Returns:
  The number of parsed arguments.

size_t MathFunction::lastArgumentDefinitionIndex | ( |  | ) | const

Returns the index of the last argument definition.

Returns:
  The index of the last argument definition

Argument* MathFunction::getArgumentDefinition | ( | size_t | index | ) |

Returns the argument definition for an argument index.

Parameters:

  | index | Argument index.

Returns:
  The argument definition for the index or NULL if no the argument was not defined for the index

void MathFunction::clearArgumentDefinitions | ( |  | ) |

Removes all argument definitions for the function.

void MathFunction::setArgumentDefinition | ( | size_t | index,
|  | Argument * | argdef |
| ) |  |  |

Set the argument definition for an argument index.

Parameters:

  | index | Argument index.
  | argdef | A newly allocated argument definition

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

- libqalculate/Function.h