Logo Search packages:      
Sourcecode: libqalculate version File versions  Download package

UserFunction Class Reference

#include <Function.h>

Inheritance diagram for UserFunction:

MathFunction ExpressionItem

List of all members.


Detailed Description

A user defined mathematical function.

User functions are functions defined using expression strings, representing mathematical formulas.

The expression/formula of a function is basically a normal expression with placeholders for arguments. These placeholders consists of a backslash and a letter — x, y, z for the 1st, 2nd and 3rd arguments and a to u for argument 4 to 24. They are replaced by entered arguments when a function is calculated. The placeholders naturally also decide the number of arguments that a function requires. For example the function for triangle area ("base * height / 2") has the name triangle and the formula "(\x*\y)/2", which gives that "triangle(2, 3)" equals "(2*3) / 2" and returns "3" as result. An argument can be used more than one time and all arguments must not necessarily be in order in the formula.

Additionally, optional arguments can be put in the formula with upper-case (X, Y, Z, ...) instead of lower-case letters (x, y, z, ...). The default value can be put in brackets after the letter (ex. "\X{2}"). The default value may be omitted and is then zero. All additional arguments after an optional argument must also be optional.

To simplify the formula and make it more efficient, subfunctions can be used. These works just like the main formula, using the arguments of it. Subfunctions are referenced in the formula using ('', '', '', ...). Even though it would be quite meaningless, the formula for triangle function could for example have a subfunction "\x*\y" and the formula "\1/2". Subfunctions must be added before the main formula is set.

Definition at line 222 of file Function.h.


Public Member Functions

virtual void addName (string sname, size_t index=0, bool force=true)
virtual void addName (const ExpressionName &ename, size_t index=0, bool force=true)
void addSubfunction (string subfunction, bool precalculate=true)
void appendDefaultValues (MathStructure &vargs)
int args (const string &str, MathStructure &vargs, const ParseOptions &po=default_parse_options)
int args () const
virtual MathStructure calculate (MathStructure &vargs, const EvaluationOptions &eo=default_evaluation_options)
virtual MathStructure calculate (const string &eq, const EvaluationOptions &eo=default_evaluation_options)
int calculate (MathStructure &mstruct, const MathStructure &vargs, const EvaluationOptions &eo)
virtual const string & category () const
virtual bool changeReference (ExpressionItem *o_from, ExpressionItem *o_to)
void clearArgumentDefinitions ()
virtual void clearNames ()
virtual void clearNonReferenceNames ()
void clearSubfunctions ()
string condition () const
ExpressionItemcopy () const
virtual size_t countNames () const
size_t countSubfunctions () const
void delSubfunction (size_t index)
virtual const string & description () const
virtual bool destroy ()
virtual const ExpressionNamefindName (int abbreviation=-1, int use_unicode=-1, int plural=-1, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
string formula () const
ArgumentgetArgumentDefinition (size_t index)
const string & getDefaultValue (size_t arg_) const
virtual const ExpressionNamegetName (size_t index) const
virtual ExpressionItemgetReferencer (size_t index=1) const
const string & getSubfunction (size_t index) const
virtual bool hasChanged () const
virtual size_t hasName (const string &sname, bool case_sensitive=true) const
virtual size_t hasNameCaseSensitive (const string &sname) const
string internalFormula () const
virtual bool isActive () const
virtual bool isApproximate () const
virtual bool isBuiltin () const
virtual bool isHidden () const
virtual bool isLocal () const
bool isRegistered () const
size_t lastArgumentDefinitionIndex () const
int maxargs () const
int minargs () const
virtual const string & name (bool use_unicode=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
virtual int parse (MathStructure &mstruct, const string &eq, const ParseOptions &po=default_parse_options)
virtual MathStructure parse (const string &eq, const ParseOptions &po=default_parse_options)
virtual int precision () const
virtual const ExpressionNamepreferredDisplayName (bool abbreviation=false, bool use_unicode=false, bool plural=false, bool reference=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
virtual const ExpressionNamepreferredInputName (bool abbreviation=false, bool use_unicode=false, bool plural=false, bool reference=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
virtual const ExpressionNamepreferredName (bool abbreviation=false, bool use_unicode=false, bool plural=false, bool reference=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
string printCondition ()
MathStructure produceArgumentsVector (const MathStructure &vargs, int begin=-1, int end=-1)
MathStructure produceVector (const MathStructure &vargs, int begin=-1, int end=-1)
virtual void ref (ExpressionItem *o)
virtual void ref ()
virtual int refcount () const
virtual const string & referenceName () const
virtual void removeName (size_t index)
virtual bool representsBoolean (const MathStructure &) const
virtual bool representsComplex (const MathStructure &, bool=false) const
virtual bool representsEven (const MathStructure &, bool=false) const
virtual bool representsInteger (const MathStructure &, bool=false) const
virtual bool representsNegative (const MathStructure &, bool=false) const
virtual bool representsNonMatrix (const MathStructure &) const
virtual bool representsNonNegative (const MathStructure &, bool=false) const
virtual bool representsNonPositive (const MathStructure &, bool=false) const
virtual bool representsNonZero (const MathStructure &, bool=false) const
virtual bool representsNumber (const MathStructure &, bool=false) const
virtual bool representsOdd (const MathStructure &, bool=false) const
virtual bool representsPositive (const MathStructure &, bool=false) const
virtual bool representsRational (const MathStructure &, bool=false) const
virtual bool representsReal (const MathStructure &, bool=false) const
virtual bool representsUndefined (const MathStructure &) const
void set (const ExpressionItem *item)
virtual void setActive (bool is_active)
virtual void setApproximate (bool is_approx=true)
void setArgumentDefinition (size_t index, Argument *argdef)
virtual void setCategory (string cat_)
virtual void setChanged (bool has_changed)
void setCondition (string expression)
void setDefaultValue (size_t arg_, string value_)
virtual void setDescription (string descr_)
void setFormula (string new_formula, int argc_=-1, int max_argc_=0)
virtual void setHidden (bool is_hidden)
virtual bool setLocal (bool is_local=true, int will_be_active=-1)
virtual void setName (string sname, size_t index, bool force=true)
virtual void setName (const ExpressionName &ename, size_t index=1, bool force=true)
virtual void setPrecision (int prec)
void setRegistered (bool is_registered)
 For internal use.
void setSubfunction (size_t index, string subfunction)
void setSubfunctionPrecalculated (size_t index, bool precalculate)
virtual void setTitle (string title_)
int stringArgs (const string &str, vector< string > &svargs)
bool subfunctionPrecalculated (size_t index) const
int subtype () const
bool testArgumentCount (int itmp)
bool testCondition (const MathStructure &vargs)
virtual const string & title (bool return_name_if_no_title=true, bool use_unicode=false, bool(*can_display_unicode_string_function)(const char *, void *)=NULL, void *can_display_unicode_string_arg=NULL) const
virtual int type () const
virtual void unref (ExpressionItem *o)
virtual void unref ()
 UserFunction (const UserFunction *function)
 UserFunction (string cat_, string name_, string formula_, bool is_local=true, int argc_=-1, string title_="", string descr_="", int max_argc_=0, bool is_active=true)

Protected Member Functions

virtual MathStructure createFunctionMathStructureFromSVArgs (vector< string > &svargs)
virtual MathStructure createFunctionMathStructureFromVArgs (const MathStructure &vargs)
bool testArguments (MathStructure &vargs)

Protected Attributes

int argc
Sgi::hash_map< size_t, Argument * > argdefs
bool b_active
bool b_approx
bool b_builtin
bool b_changed
bool b_destroyed
bool b_hidden
bool b_local
bool b_registered
vector< string > default_values
int i_precision
int i_ref
size_t last_argdef_index
int max_argc
vector< ExpressionNamenames
string scat
string scondition
string sdescr
string sformula
string sformula_calc
string stitle
vector< bool > v_precalculate
vector< ExpressionItem * > v_refs
vector< string > v_subs

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

Generated by  Doxygen 1.6.0   Back to index