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

The almighty calculator class. More...

#include <Calculator.h>

Public Member Functions

UnitfindMatchingUnit (const MathStructure &mstruct)
 
Constructor
 Calculator ()
 
virtual ~Calculator ()
 
Functions for calculating expressions.
bool calculate (MathStructure *mstruct, string str, int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL, MathStructure *to_struct=NULL, bool make_to_division=true)
 
MathStructure calculate (string str, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL, MathStructure *to_struct=NULL, bool make_to_division=true)
 
bool calculate (MathStructure *mstruct, int msecs, const EvaluationOptions &eo=default_evaluation_options, string to_str="")
 
MathStructure calculate (const MathStructure &mstruct, const EvaluationOptions &eo=default_evaluation_options, string to_str="")
 
int testCondition (string expression)
 
Functions for printing expressions with the option to set maximum time or abort.
string print (const MathStructure &mstruct, int milliseconds=100000, const PrintOptions &op=default_print_options)
 
string printMathStructureTimeOut (const MathStructure &mstruct, int milliseconds=100000, const PrintOptions &op=default_print_options)
 Deprecated: use print() instead.
 
void startControl (int milliseconds=0)
 
void stopControl (void)
 
bool abort ()
 
bool aborted (void)
 
bool isControlled (void) const
 
string abortedMessage (void) const
 
string timedOutString (void) const
 
void startPrintControl (int milliseconds=0)
 Deprecated: use startControl()
 
void abortPrint (void)
 Deprecated: use abort()
 
void stopPrintControl (void)
 Deprecated: use stopControl()
 
bool printingAborted (void)
 Deprecated: use aborted()
 
bool printingControlled (void) const
 Deprecated: use isControlled()
 
string printingAbortedMessage (void) const
 Deprecated: use abortedMessage()
 
Functions for handling of threaded calculations
bool busy ()
 
void saveState ()
 Deprecated: does nothing.
 
void restoreState ()
 Deprecated: does nothing.
 
void clearBuffers ()
 
void terminateThreads ()
 
Functions for manipulation of the RPN stack.
bool calculateRPNRegister (size_t index, int msecs, const EvaluationOptions &eo=default_evaluation_options)
 
bool calculateRPN (MathOperation op, int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
 
bool calculateRPN (MathFunction *f, int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
 
bool calculateRPNBitwiseNot (int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
 
bool calculateRPNLogicalNot (int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
 
MathStructurecalculateRPN (MathOperation op, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
 
MathStructurecalculateRPN (MathFunction *f, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
 
MathStructurecalculateRPNBitwiseNot (const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
 
MathStructurecalculateRPNLogicalNot (const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
 
bool RPNStackEnter (MathStructure *mstruct, int msecs, const EvaluationOptions &eo=default_evaluation_options)
 
bool RPNStackEnter (string str, int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL, MathStructure *to_struct=NULL, bool make_to_division=true)
 
void RPNStackEnter (MathStructure *mstruct, bool eval=false, const EvaluationOptions &eo=default_evaluation_options)
 
void RPNStackEnter (string str, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL, MathStructure *to_struct=NULL, bool make_to_division=true)
 
bool setRPNRegister (size_t index, MathStructure *mstruct, int msecs, const EvaluationOptions &eo=default_evaluation_options)
 
bool setRPNRegister (size_t index, string str, int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL, MathStructure *to_struct=NULL, bool make_to_division=true)
 
void setRPNRegister (size_t index, MathStructure *mstruct, bool eval=false, const EvaluationOptions &eo=default_evaluation_options)
 
void setRPNRegister (size_t index, string str, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL, MathStructure *to_struct=NULL, bool make_to_division=true)
 
void deleteRPNRegister (size_t index)
 
MathStructuregetRPNRegister (size_t index=1) const
 
size_t RPNStackSize () const
 
void clearRPNStack ()
 
void moveRPNRegister (size_t old_index, size_t new_index)
 
void moveRPNRegisterUp (size_t index)
 
void moveRPNRegisterDown (size_t index)
 
Functions for expression parsing.
string localizeExpression (string str) const
 
string unlocalizeExpression (string str, const ParseOptions &po=default_parse_options) const
 
bool separateToExpression (string &str, string &to_str, const EvaluationOptions &eo, bool keep_modifiers=false) const
 
bool hasToExpression (const string &str) const
 
void parseSigns (string &str) const
 
MathStructure parse (string str, const ParseOptions &po=default_parse_options)
 
void parse (MathStructure *mstruct, string str, const ParseOptions &po=default_parse_options)
 
bool parseNumber (MathStructure *mstruct, string str, const ParseOptions &po=default_parse_options)
 
bool parseOperators (MathStructure *mstruct, string str, const ParseOptions &po=default_parse_options)
 
bool parseAdd (string &str, MathStructure *mstruct, const ParseOptions &po, MathOperation s, bool append=true)
 
bool parseAdd (string &str, MathStructure *mstruct, const ParseOptions &po)
 
Functions converting epxressions between units.
MathStructure convert (const MathStructure &mstruct, string composite_, const EvaluationOptions &eo=default_evaluation_options, MathStructure *units=NULL)
 
MathStructure convert (const MathStructure &mstruct, Unit *to_unit, const EvaluationOptions &eo=default_evaluation_options, bool always_convert=true, bool convert_to_mixed_units=true)
 
MathStructure convert (double value, Unit *from_unit, Unit *to_unit, const EvaluationOptions &eo=default_evaluation_options)
 
MathStructure convert (string str, Unit *from_unit, Unit *to_unit, int milliseconds, const EvaluationOptions &eo=default_evaluation_options)
 
MathStructure convertTimeOut (string str, Unit *from_unit, Unit *to_unit, int milliseconds, const EvaluationOptions &eo=default_evaluation_options)
 
MathStructure convert (string str, Unit *from_unit, Unit *to_unit, const EvaluationOptions &eo=default_evaluation_options)
 
MathStructure convertToBaseUnits (const MathStructure &mstruct, const EvaluationOptions &eo=default_evaluation_options)
 
UnitgetBestUnit (Unit *u, bool allow_only_div=false)
 
MathStructure convertToBestUnit (const MathStructure &mstruct, const EvaluationOptions &eo=default_evaluation_options, bool convert_to_si_units=true)
 
MathStructure convertToCompositeUnit (const MathStructure &mstruct, CompositeUnit *cu, const EvaluationOptions &eo=default_evaluation_options, bool always_convert=true)
 
MathStructure convertToMixedUnits (const MathStructure &mstruct, const EvaluationOptions &eo=default_evaluation_options)
 
Functions for default assumptions for unknown variables and symbols
void setDefaultAssumptions (Assumptions *ass)
 
AssumptionsdefaultAssumptions ()
 
Functions for retrieval of angle units
UnitgetGraUnit ()
 
UnitgetRadUnit ()
 
UnitgetDegUnit ()
 
Functions for finding a suitable prefix.
DecimalPrefixgetExactDecimalPrefix (int exp10, int exp=1) const
 
BinaryPrefixgetExactBinaryPrefix (int exp2, int exp=1) const
 
PrefixgetExactPrefix (const Number &o, int exp=1) const
 
DecimalPrefixgetNearestDecimalPrefix (int exp10, int exp=1) const
 
DecimalPrefixgetBestDecimalPrefix (int exp10, int exp=1, bool all_prefixes=true) const
 
DecimalPrefixgetBestDecimalPrefix (const Number &exp10, const Number &exp, bool all_prefixes=true) const
 
BinaryPrefixgetNearestBinaryPrefix (int exp2, int exp=1) const
 
BinaryPrefixgetBestBinaryPrefix (int exp2, int exp=1) const
 
BinaryPrefixgetBestBinaryPrefix (const Number &exp2, const Number &exp) const
 
PrefixaddPrefix (Prefix *p)
 
void prefixNameChanged (Prefix *p, bool new_item=false)
 
Functions for managing functions, variables, units, prefixes and data sets.
void expressionItemActivated (ExpressionItem *item)
 
void expressionItemDeactivated (ExpressionItem *item)
 
void expressionItemDeleted (ExpressionItem *item)
 
void nameChanged (ExpressionItem *item, bool new_item=false)
 
void deleteName (string name_, ExpressionItem *object=NULL)
 
void deleteUnitName (string name_, Unit *object=NULL)
 
UnitaddUnit (Unit *u, bool force=true, bool check_names=true)
 
void delPrefixUFV (Prefix *object)
 
void delUFV (ExpressionItem *object)
 
bool hasVariable (Variable *v)
 
bool hasUnit (Unit *u)
 
bool hasFunction (MathFunction *f)
 
bool stillHasVariable (Variable *v)
 
bool stillHasUnit (Unit *u)
 
bool stillHasFunction (MathFunction *f)
 
void saveFunctionCalled ()
 
bool checkSaveFunctionCalled ()
 
ExpressionItemgetActiveExpressionItem (string name, ExpressionItem *item=NULL)
 
ExpressionItemgetInactiveExpressionItem (string name, ExpressionItem *item=NULL)
 
ExpressionItemgetActiveExpressionItem (ExpressionItem *item)
 
ExpressionItemgetExpressionItem (string name, ExpressionItem *item=NULL)
 
UnitgetUnit (string name_)
 
UnitgetActiveUnit (string name_)
 
UnitgetCompositeUnit (string internal_name_)
 
PrefixgetPrefix (size_t index) const
 
PrefixgetPrefix (string name_) const
 
VariableaddVariable (Variable *v, bool force=true, bool check_names=true)
 
void variableNameChanged (Variable *v, bool new_item=false)
 
void functionNameChanged (MathFunction *f, bool new_item=false)
 
void unitNameChanged (Unit *u, bool new_item=false)
 
VariablegetVariable (string name_)
 
VariablegetActiveVariable (string name_)
 
ExpressionItemaddExpressionItem (ExpressionItem *item, bool force=true)
 
MathFunctionaddFunction (MathFunction *f, bool force=true, bool check_names=true)
 
DataSetaddDataSet (DataSet *dc, bool force=true, bool check_names=true)
 
DataSetgetDataSet (size_t index)
 
DataSetgetDataSet (string name)
 
MathFunctiongetFunction (string name_)
 
MathFunctiongetActiveFunction (string name_)
 
VariablegetVariable (size_t index) const
 
UnitgetUnit (size_t index) const
 
MathFunctiongetFunction (size_t index) const
 
bool unitIsUsedByOtherUnits (const Unit *u) const
 
Functions for handling of builtin expression items
void resetVariables ()
 
void resetFunctions ()
 
void resetUnits ()
 
void reset ()
 
void addBuiltinVariables ()
 
void addBuiltinFunctions ()
 
void addBuiltinUnits ()
 
Functions for testing validity of functions, variable and unit names.
bool variableNameIsValid (const string &name_)
 
bool variableNameIsValid (const char *name_)
 
bool variableNameIsValid (const char *name_, int version_numbers[3], bool is_user_defs)
 
bool variableNameIsValid (const string &name_, int version_numbers[3], bool is_user_defs)
 
string convertToValidVariableName (string name_)
 
bool functionNameIsValid (const string &name_)
 
bool functionNameIsValid (const char *name_)
 
bool functionNameIsValid (const char *name_, int version_numbers[3], bool is_user_defs)
 
bool functionNameIsValid (const string &name_, int version_numbers[3], bool is_user_defs)
 
string convertToValidFunctionName (string name_)
 
bool unitNameIsValid (const string &name_)
 
bool unitNameIsValid (const char *name_)
 
bool unitNameIsValid (const char *name_, int version_numbers[3], bool is_user_defs)
 
bool unitNameIsValid (const string &name_, int version_numbers[3], bool is_user_defs)
 
bool utf8_pos_is_valid_in_name (char *pos)
 
string convertToValidUnitName (string name_)
 
bool nameTaken (string name, ExpressionItem *object=NULL)
 
bool variableNameTaken (string name, Variable *object=NULL)
 
bool unitNameTaken (string name, Unit *object=NULL)
 
bool functionNameTaken (string name, MathFunction *object=NULL)
 
string getName (string name="", ExpressionItem *object=NULL, bool force=false, bool always_append=false)
 
Functions for message handling.
void error (bool critical, int message_category, const char *TEMPLATE,...)
 
void error (bool critical, const char *TEMPLATE,...)
 
void message (MessageType mtype, int message_category, const char *TEMPLATE,...)
 
void message (MessageType mtype, const char *TEMPLATE,...)
 
void message (MessageType mtype, int message_category, const char *TEMPLATE, va_list ap)
 
CalculatorMessagemessage ()
 
CalculatorMessagenextMessage ()
 
bool showArgumentErrors () const
 
void beginTemporaryStopMessages ()
 
int endTemporaryStopMessages (int *message_count=NULL, int *warning_count=NULL)
 
Functions for loading and saving definitions (variables, functions, units, etc.).
bool loadGlobalDefinitions ()
 
bool loadGlobalDefinitions (string filename)
 
bool loadGlobalPrefixes ()
 
bool loadGlobalCurrencies ()
 
bool loadGlobalUnits ()
 
bool loadGlobalVariables ()
 
bool loadGlobalFunctions ()
 
bool loadGlobalDataSets ()
 
bool loadLocalDefinitions ()
 
int loadDefinitions (const char *file_name, bool is_user_defs=true)
 
bool saveDefinitions ()
 
int saveDataObjects ()
 
int savePrefixes (const char *file_name, bool save_global=false)
 
string temporaryCategory (void) const
 
int saveVariables (const char *file_name, bool save_global=false)
 
int saveUnits (const char *file_name, bool save_global=false)
 
int saveFunctions (const char *file_name, bool save_global=false)
 
int saveDataSets (const char *file_name, bool save_global=false)
 
Functions for CSV file import/export.
bool importCSV (MathStructure &mstruct, const char *file_name, int first_row=1, string delimiter=",", vector< string > *headers=NULL)
 
bool importCSV (const char *file_name, int first_row=1, bool headers=true, string delimiter=",", bool to_matrix=false, string name="", string title="", string category="")
 
bool exportCSV (const MathStructure &mstruct, const char *file_name, string delimiter=",")
 
Functions for exchange rates.
bool canFetch ()
 
bool hasGVFS ()
 Deprecated: gvfs is not needed anymore.
 
bool hasGnomeVFS ()
 Deprecated: gvfs is not needed anymore.
 
bool loadExchangeRates ()
 
string getExchangeRatesFileName ()
 
string getExchangeRatesFileName2 ()
 
string getExchangeRatesUrl ()
 
string getExchangeRatesUrl2 ()
 
time_t getExchangeRatesTime ()
 
bool fetchExchangeRates (int seconds, string wget_args)
 Deprecated: wget arguments are not used.
 
bool fetchExchangeRates (int seconds=15)
 
bool checkExchangeRatesDate (unsigned int n_days=7, bool force_check=false, bool send_warning=false)
 
void setExchangeRatesWarningEnabled (bool enable)
 Enable or disable old exchange rates warning (initial state is true).
 
bool exchangeRatesWarningEnabled () const
 
bool exchangeRatesUsed () const
 Check if exchange rates has been used since resetExchangeRatesUsed() was last called.
 
void resetExchangeRatesUsed ()
 
void setExchangeRatesUsed ()
 For internal use, called by currency units.
 
Functions for plotting
bool canPlot ()
 
MathStructure expressionToPlotVector (string expression, const MathStructure &min, const MathStructure &max, int steps, MathStructure *x_vector=NULL, string x_var="\", const ParseOptions &po=default_parse_options, int msecs=5000)
 
MathStructure expressionToPlotVector (string expression, float min, float max, int steps, MathStructure *x_vector=NULL, string x_var="\", const ParseOptions &po=default_parse_options, int msecs=5000)
 
MathStructure expressionToPlotVector (string expression, const MathStructure &min, const MathStructure &max, const MathStructure &step, MathStructure *x_vector=NULL, string x_var="\", const ParseOptions &po=default_parse_options, int msecs=5000)
 
MathStructure expressionToPlotVector (string expression, float min, float max, float step, MathStructure *x_vector=NULL, string x_var="\", const ParseOptions &po=default_parse_options, int msecs=5000)
 
MathStructure expressionToPlotVector (string expression, const MathStructure &x_vector, string x_var="\", const ParseOptions &po=default_parse_options, int msecs=5000)
 
bool plotVectors (PlotParameters *param, const vector< MathStructure > &y_vectors, const vector< MathStructure > &x_vectors, vector< PlotDataParameters *> &pdps, bool persistent=false, int msecs=5000)
 
bool invokeGnuplot (string commands, string commandline_extra="", bool persistent=false)
 
bool closeGnuplot ()
 
bool gnuplotOpen ()
 
Functions for global precision
void setPrecision (int precision=DEFAULT_PRECISION)
 
int getPrecision () const
 
Functions for localization
const string & getDecimalPoint () const
 
const string & getComma () const
 
void setLocale ()
 
void useDecimalComma ()
 
void useDecimalPoint (bool comma_as_separator=false)
 
void unsetLocale ()
 
string localToString () const
 
Functions adding alternative symbols for operators and such
void addStringAlternative (string replacement, string standard)
 
bool delStringAlternative (string replacement, string standard)
 
void addDefaultStringAlternative (string replacement, string standard)
 
bool delDefaultStringAlternative (string replacement, string standard)
 
Functions for storing values with associated identifiers
size_t addId (MathStructure *mstruct, bool persistent=false)
 
size_t parseAddId (MathFunction *f, const string &str, const ParseOptions &po, bool persistent=false)
 
size_t parseAddIdAppend (MathFunction *f, const MathStructure &append_mstruct, const string &str, const ParseOptions &po, bool persistent=false)
 
size_t parseAddVectorId (const string &str, const ParseOptions &po, bool persistent=false)
 
MathStructuregetId (size_t id)
 
void delId (size_t id)
 

Public Attributes

KnownVariablev_pi
 
KnownVariablev_e
 
KnownVariablev_euler
 
KnownVariablev_catalan
 
KnownVariablev_i
 
KnownVariablev_inf
 
KnownVariablev_pinf
 
KnownVariablev_minf
 
KnownVariablev_undef
 
KnownVariablev_precision
 
UnknownVariablev_x
 
UnknownVariablev_y
 
UnknownVariablev_z
 
MathFunctionf_vector
 
MathFunctionf_sort
 
MathFunctionf_rank
 
MathFunctionf_limits
 
MathFunctionf_component
 
MathFunctionf_dimension
 
MathFunctionf_merge_vectors
 
MathFunctionf_matrix
 
MathFunctionf_matrix_to_vector
 
MathFunctionf_area
 
MathFunctionf_rows
 
MathFunctionf_columns
 
MathFunctionf_row
 
MathFunctionf_column
 
MathFunctionf_elements
 
MathFunctionf_element
 
MathFunctionf_transpose
 
MathFunctionf_identity
 
MathFunctionf_determinant
 
MathFunctionf_permanent
 
MathFunctionf_adjoint
 
MathFunctionf_cofactor
 
MathFunctionf_inverse
 
MathFunctionf_factorial
 
MathFunctionf_factorial2
 
MathFunctionf_multifactorial
 
MathFunctionf_binomial
 
MathFunctionf_xor
 
MathFunctionf_bitxor
 
MathFunctionf_even
 
MathFunctionf_odd
 
MathFunctionf_shift
 
MathFunctionf_abs
 
MathFunctionf_gcd
 
MathFunctionf_lcm
 
MathFunctionf_signum
 
MathFunctionf_round
 
MathFunctionf_floor
 
MathFunctionf_ceil
 
MathFunctionf_trunc
 
MathFunctionf_int
 
MathFunctionf_frac
 
MathFunctionf_rem
 
MathFunctionf_mod
 
MathFunctionf_polynomial_unit
 
MathFunctionf_polynomial_primpart
 
MathFunctionf_polynomial_content
 
MathFunctionf_coeff
 
MathFunctionf_lcoeff
 
MathFunctionf_tcoeff
 
MathFunctionf_degree
 
MathFunctionf_ldegree
 
MathFunctionf_re
 
MathFunctionf_im
 
MathFunctionf_arg
 
MathFunctionf_numerator
 
MathFunctionf_denominator
 
MathFunctionf_sqrt
 
MathFunctionf_cbrt
 
MathFunctionf_root
 
MathFunctionf_sq
 
MathFunctionf_exp
 
MathFunctionf_ln
 
MathFunctionf_logn
 
MathFunctionf_lambert_w
 
MathFunctionf_sin
 
MathFunctionf_cos
 
MathFunctionf_tan
 
MathFunctionf_asin
 
MathFunctionf_acos
 
MathFunctionf_atan
 
MathFunctionf_sinh
 
MathFunctionf_cosh
 
MathFunctionf_tanh
 
MathFunctionf_asinh
 
MathFunctionf_acosh
 
MathFunctionf_atanh
 
MathFunctionf_atan2
 
MathFunctionf_radians_to_default_angle_unit
 
MathFunctionf_zeta
 
MathFunctionf_gamma
 
MathFunctionf_digamma
 
MathFunctionf_beta
 
MathFunctionf_airy
 
MathFunctionf_besselj
 
MathFunctionf_bessely
 
MathFunctionf_erf
 
MathFunctionf_erfc
 
MathFunctionf_total
 
MathFunctionf_percentile
 
MathFunctionf_min
 
MathFunctionf_max
 
MathFunctionf_mode
 
MathFunctionf_rand
 
MathFunctionf_isodate
 
MathFunctionf_localdate
 
MathFunctionf_timestamp
 
MathFunctionf_stamptodate
 
MathFunctionf_days
 
MathFunctionf_yearfrac
 
MathFunctionf_week
 
MathFunctionf_weekday
 
MathFunctionf_month
 
MathFunctionf_day
 
MathFunctionf_year
 
MathFunctionf_yearday
 
MathFunctionf_time
 
MathFunctionf_add_days
 
MathFunctionf_add_months
 
MathFunctionf_add_years
 
MathFunctionf_bin
 
MathFunctionf_oct
 
MathFunctionf_hex
 
MathFunctionf_base
 
MathFunctionf_roman
 
MathFunctionf_ascii
 
MathFunctionf_char
 
MathFunctionf_length
 
MathFunctionf_concatenate
 
MathFunctionf_replace
 
MathFunctionf_stripunits
 
MathFunctionf_genvector
 
MathFunctionf_for
 
MathFunctionf_sum
 
MathFunctionf_product
 
MathFunctionf_process
 
MathFunctionf_process_matrix
 
MathFunctionf_csum
 
MathFunctionf_if
 
MathFunctionf_is_number
 
MathFunctionf_is_real
 
MathFunctionf_is_rational
 
MathFunctionf_is_integer
 
MathFunctionf_represents_number
 
MathFunctionf_represents_real
 
MathFunctionf_represents_rational
 
MathFunctionf_represents_integer
 
MathFunctionf_function
 
MathFunctionf_select
 
MathFunctionf_diff
 
MathFunctionf_integrate
 
MathFunctionf_solve
 
MathFunctionf_multisolve
 
MathFunctionf_error
 
MathFunctionf_warning
 
MathFunctionf_message
 
MathFunctionf_save
 
MathFunctionf_load
 
MathFunctionf_export
 
MathFunctionf_title
 
MathFunctionf_register
 
MathFunctionf_stack
 
MathFunctionf_plot
 
MathFunctionf_uncertainty
 
Unitu_rad
 
Unitu_gra
 
Unitu_deg
 
Unitu_euro
 
DecimalPrefixdecimal_null_prefix
 
BinaryPrefixbinary_null_prefix
 
bool place_currency_code_before
 
bool place_currency_sign_before
 
bool place_currency_code_before_negative
 
bool place_currency_sign_before_negative
 
bool default_dot_as_separator
 
bool b_busy
 
string expression_to_calculate
 
EvaluationOptions tmp_evaluationoptions
 
MathStructuretmp_parsedstruct
 
MathStructuretmp_tostruct
 
MathStructuretmp_rpn_mstruct
 
bool tmp_maketodivision
 
int tmp_proc_command
 
int tmp_proc_registers
 
size_t tmp_rpnindex
 
PrintOptions save_printoptions
 
vector< Variable * > variables
 
vector< MathFunction * > functions
 
vector< Unit * > units
 
vector< Prefix * > prefixes
 
vector< DecimalPrefix * > decimal_prefixes
 
vector< BinaryPrefix * > binary_prefixes
 

Protected Member Functions

bool calculateRPN (MathStructure *mstruct, int command, size_t index, int msecs, const EvaluationOptions &eo, int function_arguments=0)
 
bool calculateRPN (string str, int command, size_t index, int msecs, const EvaluationOptions &eo, MathStructure *parsed_struct, MathStructure *to_struct, bool make_to_division, int function_arguments=0)
 

Protected Attributes

vector< CalculatorMessagemessages
 
int ianglemode
 
int i_precision
 
char vbuffer [200]
 
vector< void * > ufvl
 
vector< char > ufvl_t
 
vector< size_t > ufvl_i
 
vector< void * > ufv [4][UFV_LENGTHS]
 
vector< size_t > ufv_i [4][UFV_LENGTHS]
 
vector< DataSet * > data_sets
 
class Calculator_p * priv
 
vector< string > signs
 
vector< string > real_signs
 
vector< string > default_signs
 
vector< string > default_real_signs
 
char * saved_locale
 
int disable_errors_ref
 
vector< int > stopped_errors_count
 
vector< int > stopped_warnings_count
 
vector< int > stopped_messages_count
 
Threadcalculate_thread
 
string NAME_NUMBER_PRE_S
 
string NAME_NUMBER_PRE_STR
 
string DOT_STR
 
string DOT_S
 
string COMMA_S
 
string COMMA_STR
 
string ILLEGAL_IN_NAMES
 
string ILLEGAL_IN_UNITNAMES
 
string ILLEGAL_IN_NAMES_MINUS_SPACE_STR
 
bool b_argument_errors
 
int current_stage
 
time_t exchange_rates_time
 
time_t exchange_rates_check_time
 
bool b_exchange_rates_used
 
bool b_exchange_rates_warning_enabled
 
bool b_gnuplot_open
 
string gnuplot_cmdline
 
FILE * gnuplot_pipe
 
bool local_to
 
Assumptionsdefault_assumptions
 
vector< Variable * > deleted_variables
 
vector< MathFunction * > deleted_functions
 
vector< Unit * > deleted_units
 
bool b_save_called
 
int i_timeout
 
struct timeval t_end
 
int i_aborted
 
bool b_controlled
 
string per_str
 
string times_str
 
string plus_str
 
string minus_str
 
string and_str
 
string AND_str
 
string or_str
 
string OR_str
 
string XOR_str
 
size_t per_str_len
 
size_t times_str_len
 
size_t plus_str_len
 
size_t minus_str_len
 
size_t and_str_len
 
size_t AND_str_len
 
size_t or_str_len
 
size_t OR_str_len
 
size_t XOR_str_len
 
vector< MathStructure * > rpn_stack
 

Detailed Description

The almighty calculator class.

The calculator class is responsible for loading functions, variables and units, and keeping track of them, as well as parsing expressions and much more. A calculator object must be created before any other Qalculate! class is used. There should never be more than one calculator object, accessed with CALCULATOR.

A simple application using libqalculate need only create a calculator object, perhaps load definitions (functions, variables, units, etc.) and use the calculate function as follows:

new Calculator();
CALCULATOR->loadGlobalDefinitions();
CALCULATOR->loadLocalDefinitions();
MathStructure result = CALCULATOR->calculate("1 + 1");

Member Function Documentation

◆ abort()

bool Calculator::abort ( )

Abort formatting, printing or evaluation (after startControl() has been called). This function will normally be called from a thread that checks for user input or other conditions.

Returns
false if the calculation thread was forcibly stopped

◆ addBuiltinFunctions()

void Calculator::addBuiltinFunctions ( )

Adds builtin functions. Called automatically when the calculator is created.

◆ addBuiltinUnits()

void Calculator::addBuiltinUnits ( )

Adds builtin units. Called automatically when the calculator is created.

◆ addBuiltinVariables()

void Calculator::addBuiltinVariables ( )

Adds builtin variables. Called automatically when the calculator is created.

◆ addId()

size_t Calculator::addId ( MathStructure mstruct,
bool  persistent = false 
)

Stores a value with an associated id. Mainly for internal use.

Parameters
mstructThe value to store.
persistentIf false the values will be removed from storage when retrieved with getId().
Returns
Storage id.

◆ addPrefix()

Prefix* Calculator::addPrefix ( Prefix p)

Add a new prefix to the calculator.

◆ busy()

bool Calculator::busy ( )

Returns true if the calculate or print thread is busy.

◆ calculate() [1/4]

bool Calculator::calculate ( MathStructure mstruct,
string  str,
int  msecs,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL,
MathStructure to_struct = NULL,
bool  make_to_division = true 
)

Calculates an expression. The expression should be unlocalized first with unlocalizeExpression(). This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters
[out]mstructMath structure to fill with the result.
strExpression.
msecsThe maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the result of the parsing of the expression.
[out]to_structNULL or a math structure to fill with unit expression parsed after "to". If expression does not contain a "to" string, and to_struct is a unit or a symbol (a unit expression string), to_struct will be used instead.
make_to_divisionIf true, the expression after "to" will be interpreted as a unit epxression to convert the result to.
Returns
true if the calculation was successfully started (and finished if msecs > 0).

◆ calculate() [2/4]

MathStructure Calculator::calculate ( string  str,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL,
MathStructure to_struct = NULL,
bool  make_to_division = true 
)

Calculates an expression. The expression should be unlocalized first with unlocalizeExpression().

Parameters
strExpression.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the result of the parsing of the expression.
[out]to_structNULL or a math structure to fill with unit expression parsed after "to". If expression does not contain a "to" string, and to_struct is a unit or a symbol (a unit expression string), to_struct will be used instead.
make_to_divisionIf true, the expression after "to" will be interpreted as a unit epxression to convert the result to.
Returns
The result of the calculation.

◆ calculate() [3/4]

bool Calculator::calculate ( MathStructure mstruct,
int  msecs,
const EvaluationOptions eo = default_evaluation_options,
string  to_str = "" 
)

Calculates a parsed value. This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters
[out]mstructParsed value to evaluate and fill with the result.
msecsThe maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
eoOptions for the evaluation of the expression.
to_str"to" expression for conversion.
Returns
The result of the calculation.

◆ calculate() [4/4]

MathStructure Calculator::calculate ( const MathStructure mstruct,
const EvaluationOptions eo = default_evaluation_options,
string  to_str = "" 
)

Calculates a parsed value.

Parameters
mstructParsed value to evaluate.
eoOptions for the evaluation of the expression.
to_str"to" expression for conversion.
Returns
The result of the calculation.

◆ calculateRPN() [1/4]

bool Calculator::calculateRPN ( MathOperation  op,
int  msecs,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies a mathematical operation to the first and second value on the RPN stack. The the second value is changed with input from the first value. For example, with OPERATION_SUBTRACT the first value is subtracted from the second. The first value on the stack is removed. If not enough registers is available, then zeros are added. This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters
opOperation.
msecsThe maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the unevaluated result.
Returns
true if the calculation was successfully started (and finished if msecs > 0).

◆ calculateRPN() [2/4]

bool Calculator::calculateRPN ( MathFunction f,
int  msecs,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies a mathematical operation to the first value on the RPN stack. The value is set as the first argument of the function. If no register is available, then zero is added. This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters
fMathematical function.
msecsThe maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the unevaluated result.
Returns
true if the calculation was successfully started (and finished if msecs > 0).

◆ calculateRPN() [3/4]

MathStructure* Calculator::calculateRPN ( MathOperation  op,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies a mathematical operation to the first and second value on the RPN stack. The the second value is changed with input from the first value. For example, with OPERATION_SUBTRACT the first value is subtracted from the second. The first value on the stack is removed. If not enough registers is available, then zeros are added.

Parameters
opOperation.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the unevaluated result.
Returns
The first value on the stack.

◆ calculateRPN() [4/4]

MathStructure* Calculator::calculateRPN ( MathFunction f,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies a mathematical operation to the first value on the RPN stack. The value is set as the first argument of the function. If no register is available, then zero is added.

Parameters
fMathematical function.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the unevaluated result.
Returns
The first value on the stack.

◆ calculateRPNBitwiseNot() [1/2]

bool Calculator::calculateRPNBitwiseNot ( int  msecs,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies bitwise not to the first value on the RPN stack. If no register is available, then zero is added. This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters
msecsThe maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the unevaluated result.
Returns
true if the calculation was successfully started (and finished if msecs > 0).

◆ calculateRPNBitwiseNot() [2/2]

MathStructure* Calculator::calculateRPNBitwiseNot ( const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies bitwise not to the first value on the RPN stack. If no register is available, then zero is added.

Parameters
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the unevaluated result.
Returns
The first value on the stack.

◆ calculateRPNLogicalNot() [1/2]

bool Calculator::calculateRPNLogicalNot ( int  msecs,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies logical not to the first value on the RPN stack. If no register is available, then zero is added. This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters
msecsThe maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the unevaluated result.
Returns
true if the calculation was successfully started (and finished if msecs > 0).

◆ calculateRPNLogicalNot() [2/2]

MathStructure* Calculator::calculateRPNLogicalNot ( const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL 
)

Applies logical not to the first value on the RPN stack. If no register is available, then zero is added.

Parameters
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the unevaluated result.
Returns
The first value on the stack.

◆ calculateRPNRegister()

bool Calculator::calculateRPNRegister ( size_t  index,
int  msecs,
const EvaluationOptions eo = default_evaluation_options 
)

Evaluates a value on the RPN stack. This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters
indexIndex, starting at 1, on the RPN stack.
msecsThe maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
eoOptions for the evaluation and parsing of the expression.
Returns
true if the calculation was successfully started (and finished if msecs > 0).

◆ canFetch()

bool Calculator::canFetch ( )

Checks if able to downloading exchange rates from the Internet (using libcurl).

Returns
true if exchange rates can downloaded (if libcurl is available).

◆ canPlot()

bool Calculator::canPlot ( )

Checks if gnuplot is available.

Returns
true if gnuplot was found.

◆ checkExchangeRatesDate()

bool Calculator::checkExchangeRatesDate ( unsigned int  n_days = 7,
bool  force_check = false,
bool  send_warning = false 
)

Check age of exchange rates on local disc.

Parameters
n_daysHow old in days exchange rates may be before exchange rates need updating
force_checkIf exchange rates date should be checked again even if found outdated within n_days before
send_warningIf the standard exchange rates warning should be sent.
Returns
false if exchange.rates need updating

◆ clearBuffers()

void Calculator::clearBuffers ( )

Clears all stored values. Used internally after aborted calculation.

◆ convert() [1/2]

MathStructure Calculator::convert ( const MathStructure mstruct,
string  composite_,
const EvaluationOptions eo = default_evaluation_options,
MathStructure units = NULL 
)

Converts to a unit expression. The converted value is evaluated.

Parameters
mstructThe value to convert.
composite_Unit expression.
eoEvaluation options.
[out]unitsNULL or a math structure to fill with the parsed unit expression(or set to undefined if no units were found).
Returns
Converted value.

◆ convert() [2/2]

MathStructure Calculator::convert ( const MathStructure mstruct,
Unit to_unit,
const EvaluationOptions eo = default_evaluation_options,
bool  always_convert = true,
bool  convert_to_mixed_units = true 
)

Converts to a unit. The converted value is evaluated.

Parameters
mstructThe value to convert.
composite_Unit to convert to.
eoEvaluation options.
always_convert...
Returns
Converted value.

◆ convertTimeOut()

MathStructure Calculator::convertTimeOut ( string  str,
Unit from_unit,
Unit to_unit,
int  milliseconds,
const EvaluationOptions eo = default_evaluation_options 
)

Depecated: use convert()

◆ defaultAssumptions()

Assumptions* Calculator::defaultAssumptions ( )

Returns the default assumptions for objects without own assumptions (unknown variables and symbols).

◆ delId()

void Calculator::delId ( size_t  id)

Removes and unreferences (value->unref() will be called) a value from storage. Mainly for internal use.

Parameters
idStorage id.

◆ fetchExchangeRates()

bool Calculator::fetchExchangeRates ( int  seconds = 15)

Download current exchange rates from the Internet to local disc with default wget arguments.

Parameters
secondsMaximum time for donwload try
Returns
true if operation was successful.

◆ findMatchingUnit()

Unit* Calculator::findMatchingUnit ( const MathStructure mstruct)

Used by the UI to find unit category for a mathematical expression.

◆ getBestBinaryPrefix() [1/2]

BinaryPrefix* Calculator::getBestBinaryPrefix ( int  exp2,
int  exp = 1 
) const

Returns the best suited binary prefix for a value.

Parameters
exp10Base-2 exponent of the value.
expThe exponent of the unit.
Returns
A prefix or NULL if the unit should be left without prefix.

◆ getBestBinaryPrefix() [2/2]

BinaryPrefix* Calculator::getBestBinaryPrefix ( const Number exp2,
const Number exp 
) const

Returns the best suited binary prefix for a value.

Parameters
exp10Base-2 exponent of the value.
expThe exponent of the unit.
Returns
A prefix or NULL if the unit should be left without prefix.

◆ getBestDecimalPrefix() [1/2]

DecimalPrefix* Calculator::getBestDecimalPrefix ( int  exp10,
int  exp = 1,
bool  all_prefixes = true 
) const

Returns the best suited decimal prefix for a value.

Parameters
exp10Base-10 exponent of the value.
expThe exponent of the unit.
all_prefixesIf false, prefixes which is not a multiple of thousand (centi, deci, deka, hekto) will be skipped.
Returns
A prefix or NULL if the unit should be left without prefix.

◆ getBestDecimalPrefix() [2/2]

DecimalPrefix* Calculator::getBestDecimalPrefix ( const Number exp10,
const Number exp,
bool  all_prefixes = true 
) const

Returns the best suited decimal prefix for a value.

Parameters
exp10Base-10 exponent of the value.
expThe exponent of the unit.
all_prefixesIf false, prefixes which is not a multiple of thousand (centi, deci, deka, hekto) will be skipped.
Returns
A prefix or NULL if the unit should be left without prefix.

◆ getComma()

const string& Calculator::getComma ( ) const

Returns the preferred comma character for separating arguments.

◆ getDecimalPoint()

const string& Calculator::getDecimalPoint ( ) const

Returns the preferred decimal point character.

◆ getDegUnit()

Unit* Calculator::getDegUnit ( )

Returns the degrees unit.

◆ getExactBinaryPrefix()

BinaryPrefix* Calculator::getExactBinaryPrefix ( int  exp2,
int  exp = 1 
) const

Returns a binary prefix with exactly the provided value, that fulfils the condition prefix->exponent(exp) == exp2.

Parameters
exp2Base-2 exponent of the requested prefix.
expThe exponent of the unit.
Returns
A prefix or NULL if not found.

◆ getExactDecimalPrefix()

DecimalPrefix* Calculator::getExactDecimalPrefix ( int  exp10,
int  exp = 1 
) const

Returns a decimal prefix with exactly the provided value, that fulfils the condition prefix->exponent(exp) == exp10.

Parameters
exp10Base-10 exponent of the requested prefix.
expThe exponent of the unit.
Returns
A prefix or NULL if not found.

◆ getExactPrefix()

Prefix* Calculator::getExactPrefix ( const Number o,
int  exp = 1 
) const

Returns a prefix with exactly the provided value, that fulfils the condition prefix->value(exp) == o.

Parameters
oValue of the requested prefix.
expThe exponent of the unit.
Returns
A prefix or NULL if not found.

◆ getExchangeRatesFileName()

string Calculator::getExchangeRatesFileName ( )

Name of the exchange rates file on local disc.

Returns
name of local exchange rates file.

◆ getExchangeRatesTime()

time_t Calculator::getExchangeRatesTime ( )

Modification time of the exchange rates file.

Returns
Returns exchange rates modification time.

◆ getExchangeRatesUrl()

string Calculator::getExchangeRatesUrl ( )

Url of the exchange rates file on the Internet.

Returns
Url of exchange rates file.

◆ getFunction()

MathFunction* Calculator::getFunction ( size_t  index) const

Returns function for an index (starting at zero). All functions can be traversed by starting at index zero and increasing the index until NULL is returned.

Parameters
indexIndex of function.
Returns
Function for index or NULL if not found.

◆ getGraUnit()

Unit* Calculator::getGraUnit ( )

Returns the gradians unit.

◆ getId()

MathStructure* Calculator::getId ( size_t  id)

Returns a stored value. Mainly for internal use.

Parameters
idStorage id.
Returns
A stored value.

◆ getNearestBinaryPrefix()

BinaryPrefix* Calculator::getNearestBinaryPrefix ( int  exp2,
int  exp = 1 
) const

Returns the nearest binary prefix for a value.

Parameters
exp10Base-2 exponent of the value.
expThe exponent of the unit.
Returns
A prefix or NULL if no binary prefix is available.

◆ getNearestDecimalPrefix()

DecimalPrefix* Calculator::getNearestDecimalPrefix ( int  exp10,
int  exp = 1 
) const

Returns the nearest decimal prefix for a value.

Parameters
exp10Base-10 exponent of the value.
expThe exponent of the unit.
Returns
A prefix or NULL if no decimal prefix is available.

◆ getPrecision()

int Calculator::getPrecision ( ) const

Returns default precision for approximate calculations.

◆ getPrefix() [1/2]

Prefix* Calculator::getPrefix ( size_t  index) const

Returns prefix for an index (starting at zero). All prefixes can be traversed by starting at index zero and increasing the index until NULL is returned.

Parameters
indexIndex of prefix.
Returns
Prefix for index or NULL if not found.

◆ getPrefix() [2/2]

Prefix* Calculator::getPrefix ( string  name_) const

Returns prefix with provided name.

Parameters
name_Name of prefix to retrieve.
Returns
Prefix with provided name or NULL if not found.

◆ getRadUnit()

Unit* Calculator::getRadUnit ( )

Returns the radians unit.

◆ getUnit()

Unit* Calculator::getUnit ( size_t  index) const

Returns unit for an index (starting at zero). All units can be traversed by starting at index zero and increasing the index until NULL is returned.

Parameters
indexIndex of unit.
Returns
Unit for index or NULL if not found.

◆ getVariable()

Variable* Calculator::getVariable ( size_t  index) const

Returns variable for an index (starting at zero). All variables can be traversed by starting at index zero and increasing the index until NULL is returned.

Parameters
indexIndex of variable.
Returns
Variable for index or NULL if not found.

◆ hasFunction()

bool Calculator::hasFunction ( MathFunction f)

Checks if a function exists/is registered in the calculator.

◆ hasUnit()

bool Calculator::hasUnit ( Unit u)

Checks if a unit exists/is registered in the calculator.

◆ hasVariable()

bool Calculator::hasVariable ( Variable v)

Checks if a variable exists/is registered in the calculator.

◆ loadDefinitions()

int Calculator::loadDefinitions ( const char *  file_name,
bool  is_user_defs = true 
)

Load definitions from a file.

Parameters
file_nameThe path to the file to load.
is_user_defstrue if the definitions are local, false if they are global.
Returns
true if the definitions were successfully loaded.

◆ loadExchangeRates()

bool Calculator::loadExchangeRates ( )

Load saved (local) currency units and exchange rates.

Returns
true if operation successful.

◆ loadGlobalCurrencies()

bool Calculator::loadGlobalCurrencies ( )

Load currencies.

Returns
true if the definitions were successfully loaded.

◆ loadGlobalDataSets()

bool Calculator::loadGlobalDataSets ( )

Load data sets.

Returns
true if the definitions were successfully loaded.

◆ loadGlobalDefinitions() [1/2]

bool Calculator::loadGlobalDefinitions ( )

Load all standard global (system wide) definitions from the global data directory ($PREFIX/share/qalculate).

Returns
true if the definitions were successfully loaded.

◆ loadGlobalDefinitions() [2/2]

bool Calculator::loadGlobalDefinitions ( string  filename)

Load global (system wide) definitions from a file in the global data directory ($PREFIX/share/qalculate).

Parameters
filenameName of the file in the global data directory.
Returns
true if the definitions were successfully loaded.

◆ loadGlobalFunctions()

bool Calculator::loadGlobalFunctions ( )

Load functions.

Returns
true if the definitions were successfully loaded.

◆ loadGlobalPrefixes()

bool Calculator::loadGlobalPrefixes ( )

Load prefixes.

Returns
true if the definitions were successfully loaded.

◆ loadGlobalUnits()

bool Calculator::loadGlobalUnits ( )

Load units.

Returns
true if the definitions were successfully loaded.

◆ loadGlobalVariables()

bool Calculator::loadGlobalVariables ( )

Load variables.

Returns
true if the definitions were successfully loaded.

◆ loadLocalDefinitions()

bool Calculator::loadLocalDefinitions ( )

Load local, user specific, definitions from the local definitions directory (~/.qalculate/definitions). All files in the directory and in the datasets subdirectory are loaded.

Returns
true if the definitions were successfully loaded.

◆ localizeExpression()

string Calculator::localizeExpression ( string  str) const

Returns a localized expressions. Affects decimal signs and argument separators.

Parameters
strThe expression to localize.
Returns
A localized expression.

◆ localToString()

string Calculator::localToString ( ) const

Returns the translated text string used in expressions for converting to a specific unit expression (ex "5 meters to feet.

◆ message() [1/2]

void Calculator::message ( MessageType  mtype,
int  message_category,
const char *  TEMPLATE,
  ... 
)

Put a message in the message queue.

◆ message() [2/2]

CalculatorMessage* Calculator::message ( )

Returns the first message in queue.

◆ nameTaken()

bool Calculator::nameTaken ( string  name,
ExpressionItem object = NULL 
)

Checks if a name is used by another object which is not allowed to have the same name.

Parameters
nameName.
objectObject to exclude from check.
Returns
true if the name is used.

◆ nextMessage()

CalculatorMessage* Calculator::nextMessage ( )

Removes the first message in queue and returns the next.

◆ parse()

MathStructure Calculator::parse ( string  str,
const ParseOptions po = default_parse_options 
)

Parse an expression and place in a MathStructure object.

Parameters
strExpression
poParse options.
Returns
MathStructure with result of parse.

◆ parseAddId()

size_t Calculator::parseAddId ( MathFunction f,
const string &  str,
const ParseOptions po,
bool  persistent = false 
)

Stores a function value with arguments parsed from a text string using Function::parse(), with an associated id. Mainly for internal use.

Parameters
fMathematical function.
strArguments.
poParse options.
persistentIf false the values will be removed from storage when retrieved with getId().
Returns
Storage id.

◆ prefixNameChanged()

void Calculator::prefixNameChanged ( Prefix p,
bool  new_item = false 
)

Used internally.

◆ print()

string Calculator::print ( const MathStructure mstruct,
int  milliseconds = 100000,
const PrintOptions op = default_print_options 
)

Calls MathStructure::format(po) and MathStructure::print(po). The process is aborted after msecs milliseconds.

◆ reset()

void Calculator::reset ( )

Unloads all non-builtin variables, functions and units.

◆ resetFunctions()

void Calculator::resetFunctions ( )

Unloads all non-builtin functions.

◆ resetUnits()

void Calculator::resetUnits ( )

Unloads all non-builtin units.

◆ resetVariables()

void Calculator::resetVariables ( )

Unloads all non-builtin variables.

◆ RPNStackEnter() [1/4]

bool Calculator::RPNStackEnter ( MathStructure mstruct,
int  msecs,
const EvaluationOptions eo = default_evaluation_options 
)

Evaluates a value and adds the result first on the RPN stack. This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters
mstructValue.
msecsThe maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
eoOptions for the evaluation of the expression.
Returns
true if the calculation was successfully started (and finished if msecs > 0).

◆ RPNStackEnter() [2/4]

bool Calculator::RPNStackEnter ( string  str,
int  msecs,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL,
MathStructure to_struct = NULL,
bool  make_to_division = true 
)

Calculates an expression and adds the result first on the RPN stack. The expression should be unlocalized first with unlocalizeExpression(). This function starts the calculation in a separate thread and will return when the calculation has started unless a maximum time has been specified. The calculation can then be stopped with abort().

Parameters
strExpression.
msecsThe maximum time for the calculation in milliseconds. If msecs <= 0 the time will be unlimited.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the result of the parsing of the expression.
[out]to_structNULL or a math structure to fill with unit expression parsed after "to".
make_to_divisionIf true, the expression after "to" will be interpreted as a unit epxression to convert the result to.
Returns
true if the calculation was successfully started (and finished if msecs > 0).

◆ RPNStackEnter() [3/4]

void Calculator::RPNStackEnter ( MathStructure mstruct,
bool  eval = false,
const EvaluationOptions eo = default_evaluation_options 
)

Adds a value first on the RPN stack.

Parameters
mstructValue.
evalIf true, the the mathematical structure will be evaluated first.

◆ RPNStackEnter() [4/4]

void Calculator::RPNStackEnter ( string  str,
const EvaluationOptions eo = default_evaluation_options,
MathStructure parsed_struct = NULL,
MathStructure to_struct = NULL,
bool  make_to_division = true 
)

Calculates an expression adds the result first on the RPN stack. The expression should be unlocalized first with unlocalizeExpression().

Parameters
strExpression.
eoOptions for the evaluation and parsing of the expression.
[out]parsed_structNULL or a math structure to fill with the result of the parsing of the expression.
[out]to_structNULL or a math structure to fill with unit expression parsed after "to".
make_to_divisionIf true, the expression after "to" will be interpreted as a unit epxression to convert the result to.

◆ saveDefinitions()

bool Calculator::saveDefinitions ( )

Save local definitions to ~/.qalculate/definitions/

Returns
true if definitions was successfully saved.

◆ separateToExpression()

bool Calculator::separateToExpression ( string &  str,
string &  to_str,
const EvaluationOptions eo,
bool  keep_modifiers = false 
) const

Split an expression string after and before " to ".

Parameters
[out]strThe expression. Will be set to the string before " to ".
[out]to_strWill be set to the string after " to ".
eoOptions for the evaluation and parsing of the expression (nothing will be done if units are not enabled).
Returns
true if " to " was found and the expression split.

◆ setDefaultAssumptions()

void Calculator::setDefaultAssumptions ( Assumptions ass)

Set assumptions for objects without own assumptions (unknown variables and symbols).

◆ setLocale()

void Calculator::setLocale ( )

Sets argument separator and decimal sign from the current locale. Mainly for internal use.

◆ setPrecision()

void Calculator::setPrecision ( int  precision = DEFAULT_PRECISION)

Set default precision for approximate calculations.

Parameters
precisionPrecision.

◆ startControl()

void Calculator::startControl ( int  milliseconds = 0)

Called before calculation, formatting or printing of a MathStructure (Calculator::calculate(), without maximum time, MathStructure::eval(), MathStructure::format() and MathStructure::print(), etc.) or printing of a Number (using Number::print) to be able to abort the process. Always use Calculator::stopControl() after finishing.

Parameters
millisecondsThe maximum time for the process in milliseconds. If msecs <= 0 the time will be unlimited (stop with abort()).

◆ stillHasFunction()

bool Calculator::stillHasFunction ( MathFunction f)

Checks if a pointer points to a mathematical function that still exists in the calculator. As opposed to hasFunction(), this function only checks if the mathematical function has been deleted.

◆ stillHasUnit()

bool Calculator::stillHasUnit ( Unit u)

Checks if a pointer points to a unit that still exists in the calculator. As opposed to hasUnit(), this function only checks if the unit has been deleted.

◆ stillHasVariable()

bool Calculator::stillHasVariable ( Variable v)

Checks if a pointer points to a variable that still exists in the calculator. As opposed to hasFunction(), this function only checks if the mathematical function has been deleted.

◆ stopControl()

void Calculator::stopControl ( void  )

Always call this function after Calculator::startControl() after formatting, printing or calculation has finished.

◆ terminateThreads()

void Calculator::terminateThreads ( )

Terminate calculation and print threads if started. Do not use to terminate calculation.

◆ unlocalizeExpression()

string Calculator::unlocalizeExpression ( string  str,
const ParseOptions po = default_parse_options 
) const

Returns an unlocalized expressions. Affects decimal signs and argument separators.

Parameters
strThe expression to unlocalize.
Returns
An unlocalized expression.

◆ unsetLocale()

void Calculator::unsetLocale ( )

Resets argument separator and decimal sign. Mainly for internal use.

◆ useDecimalPoint()

void Calculator::useDecimalPoint ( bool  comma_as_separator = false)

Use point as decimal separator. To use comma as an ignored separator in numbers, must be invoked with comma_as_separator = true, before using ParseOptions::comma_as_separator.

◆ variableNameIsValid() [1/2]

bool Calculator::variableNameIsValid ( const string &  name_)

Tests if a name is valid for a variable.

Parameters
name_Variable name.
Returns
true if the name is valid for a variable.

◆ variableNameIsValid() [2/2]

bool Calculator::variableNameIsValid ( const char *  name_)

Tests if a name is valid for a variable.

Parameters
name_Variable name.
Returns
true if the name is valid for a variable.

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