libqalculate-2.1.0
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Argument Class Reference

A mathematical function argument definition with free value and base class for all argument definitions. More...

#include <Function.h>

Inheritance diagram for Argument:
AngleArgument ArgumentSet BooleanArgument DataObjectArgument DataPropertyArgument DateArgument ExpressionItemArgument FileArgument FunctionArgument IntegerArgument MatrixArgument NumberArgument SymbolicArgument TextArgument UnitArgument VariableArgument VectorArgument

Public Member Functions

 Argument (string name_="", bool does_test=true, bool does_error=true)
 
 Argument (const Argument *arg)
 
virtual ~Argument ()
 
virtual void set (const Argument *arg)
 
virtual Argumentcopy () const
 
virtual string print () const
 
string printlong () const
 
bool test (MathStructure &value, int index, MathFunction *f, const EvaluationOptions &eo=default_evaluation_options) const
 
virtual MathStructure parse (const string &str, const ParseOptions &po=default_parse_options) const
 
virtual void parse (MathStructure *mstruct, const string &str, const ParseOptions &po=default_parse_options) const
 
string name () const
 
void setName (string name_)
 
void setCustomCondition (string condition)
 
string getCustomCondition () const
 
bool tests () const
 
void setTests (bool does_error)
 
bool alerts () const
 
void setAlerts (bool does_error)
 
bool zeroForbidden () const
 
void setZeroForbidden (bool forbid_zero)
 
bool matrixAllowed () const
 
void setMatrixAllowed (bool allow_matrix)
 
bool isLastArgument () const
 
void setIsLastArgument (bool is_last)
 
bool rationalPolynomial () const
 
void setRationalPolynomial (bool rational_polynomial)
 
virtual bool suggestsQuotes () const
 
virtual int type () const
 

Protected Member Functions

virtual bool subtest (MathStructure &value, const EvaluationOptions &eo) const
 
virtual string subprintlong () const
 

Protected Attributes

string sname
 
string scondition
 
bool b_zero
 
bool b_test
 
bool b_matrix
 
bool b_text
 
bool b_error
 
bool b_rational
 
bool b_last
 

Detailed Description

A mathematical function argument definition with free value and base class for all argument definitions.

Free arguments accepts any value.

Constructor & Destructor Documentation

◆ Argument() [1/2]

Argument::Argument ( string  name_ = "",
bool  does_test = true,
bool  does_error = true 
)

Creates a new argument definition.

Parameters
nameName/title of the argument definition.
does_testIf argument values will be tested.
does_errorIf an error will issued if the value tests false.

◆ Argument() [2/2]

Argument::Argument ( const Argument arg)

Creates a copy of an argument definition.

Parameters
argArgument to copy.

◆ ~Argument()

virtual Argument::~Argument ( )
virtual

Destructor

Member Function Documentation

◆ alerts()

bool Argument::alerts ( ) const

If an error message will be presented to the user if the value for the argument is not allowed.

Returns
true if error messages will be shown.

◆ copy()

virtual Argument* Argument::copy ( ) const
virtual

◆ getCustomCondition()

string Argument::getCustomCondition ( ) const

Returns the custom condition expression set for argument values.

Returns
Custom condition for argument values.

◆ name()

string Argument::name ( ) const

Returns the name/title of the argument definition.

Returns
Name/title.

◆ parse() [1/2]

virtual MathStructure Argument::parse ( const string &  str,
const ParseOptions po = default_parse_options 
) const
virtual

Parses an expression for an argument value. The default behavior is to use Calculator::parse() directly.

Parameters
strExpression.
poParse options.
Returns
A new mathematical structure with the parsed expression.

◆ parse() [2/2]

virtual void Argument::parse ( MathStructure mstruct,
const string &  str,
const ParseOptions po = default_parse_options 
) const
virtual

Parses an expression for an argument value. The default behavior is to use Calculator::parse() directly.

Parameters
mstructMathematical structure to set with the parsed expression.
strExpression.
poParse options.

Reimplemented in AngleArgument, and DateArgument.

◆ print()

virtual string Argument::print ( ) const
virtual

◆ printlong()

string Argument::printlong ( ) const

Resturns a long description of the argument definition. Ex. "A real number > 2".

Returns
Long description.

◆ rationalPolynomial()

bool Argument::rationalPolynomial ( ) const

If only rational polynomials are allowed as argument value.

See also
MathStructure::isRationalPolynomial()
Returns
true if only rational polynomials is allowed.

◆ set()

virtual void Argument::set ( const Argument arg)
virtual

Sets the argument to a copy of an argument definition.

Parameters
argArgument to copy.

Reimplemented in IntegerArgument, and NumberArgument.

◆ setCustomCondition()

void Argument::setCustomCondition ( string  condition)

Sets a custom condition for argument values. '' is replaced by the argument value in the expression.

Parameters
conditionCondition expression.

◆ setName()

void Argument::setName ( string  name_)

Sets the name/title of the argument definition.

Parameters
name_New name/title.

◆ setZeroForbidden()

void Argument::setZeroForbidden ( bool  forbid_zero)

Sets if a value of zero is forbidden for the argument value.

Parameters
forbid_zeroIf zero shall be forbidden.

◆ subprintlong()

virtual string Argument::subprintlong ( ) const
protectedvirtual

This function is called from Argument::printlong() and returns description specific the argument definition type. Should be reimplemented by all subclasses. For example IntegerArgument::subprintlong() might return "an integer" and Argument::printlong() might append " that fulfills the condition: even(\x)".

Returns
Long description.

Reimplemented in ArgumentSet, FileArgument, VariableArgument, AngleArgument, UnitArgument, BooleanArgument, FunctionArgument, ExpressionItemArgument, MatrixArgument, VectorArgument, DateArgument, TextArgument, SymbolicArgument, IntegerArgument, NumberArgument, DataObjectArgument, and DataPropertyArgument.

◆ subtest()

virtual bool Argument::subtest ( MathStructure value,
const EvaluationOptions eo 
) const
protectedvirtual

This function is called from Argument::test() and performs validation specific to the argument definition type. Should be reimplemented by all subclasses.

Parameters
valueValue to test.
eoEvaluation options to use if the value needs to be evaluated.
Returns
true if the value is valid for the argument definition.

Reimplemented in ArgumentSet, FileArgument, VariableArgument, AngleArgument, UnitArgument, BooleanArgument, FunctionArgument, ExpressionItemArgument, MatrixArgument, VectorArgument, DateArgument, TextArgument, SymbolicArgument, IntegerArgument, NumberArgument, DataObjectArgument, and DataPropertyArgument.

◆ test()

bool Argument::test ( MathStructure value,
int  index,
MathFunction f,
const EvaluationOptions eo = default_evaluation_options 
) const

Tests if a value fulfils the requirements of the argument definition. The value might change if it has not been fully evaluated.

Parameters
valueValue to test.
fMathematical function that the value is an argument for.
eoEvaluation options to use if the value needs to be evaluated.
Returns
true if the value is valid for the argument definition.

◆ tests()

bool Argument::tests ( ) const

If the value for the argument will be tested. If not, the argument only works as an suggestion and any value is allowed.

Returns
true if the argument value will be tested.

◆ type()

virtual int Argument::type ( ) const
virtual

◆ zeroForbidden()

bool Argument::zeroForbidden ( ) const

If an argument value of zero is forbidden.

Returns
true if zero argument value is forbidden.

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