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

Calculator Class Reference

#include <Calculator.h>

List of all members.


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");

Definition at line 184 of file Calculator.h.


Public Member Functions

Functions for handling of threaded calculations


void abort ()
void abort_this ()
bool busy ()
void clearBuffers ()
void restoreState ()
void saveState ()
void terminateThreads ()
Functions for handling of builtin expression items


void addBuiltinFunctions ()
void addBuiltinUnits ()
void addBuiltinVariables ()
void reset ()
void resetFunctions ()
void resetUnits ()
void resetVariables ()
Functions for managing functions, variables, units, prefixes and data sets.


DataSetaddDataSet (DataSet *dc, bool force=true, bool check_names=true)
ExpressionItemaddExpressionItem (ExpressionItem *item, bool force=true)
MathFunctionaddFunction (MathFunction *f, bool force=true, bool check_names=true)
UnitaddUnit (Unit *u, bool force=true, bool check_names=true)
VariableaddVariable (Variable *v, bool force=true, bool check_names=true)
bool checkSaveFunctionCalled ()
void deleteName (string name_, ExpressionItem *object=NULL)
void deleteUnitName (string name_, Unit *object=NULL)
void delPrefixUFV (Prefix *object)
void delUFV (ExpressionItem *object)
void expressionItemActivated (ExpressionItem *item)
void expressionItemDeactivated (ExpressionItem *item)
void expressionItemDeleted (ExpressionItem *item)
void functionNameChanged (MathFunction *f, bool new_item=false)
ExpressionItemgetActiveExpressionItem (ExpressionItem *item)
ExpressionItemgetActiveExpressionItem (string name, ExpressionItem *item=NULL)
MathFunctiongetActiveFunction (string name_)
UnitgetActiveUnit (string name_)
VariablegetActiveVariable (string name_)
UnitgetCompositeUnit (string internal_name_)
DataSetgetDataSet (string name)
DataSetgetDataSet (size_t index)
ExpressionItemgetExpressionItem (string name, ExpressionItem *item=NULL)
MathFunctiongetFunction (size_t index) const
MathFunctiongetFunction (string name_)
ExpressionItemgetInactiveExpressionItem (string name, ExpressionItem *item=NULL)
PrefixgetPrefix (string name_) const
PrefixgetPrefix (size_t index) const
UnitgetUnit (size_t index) const
UnitgetUnit (string name_)
VariablegetVariable (size_t index) const
VariablegetVariable (string name_)
bool hasFunction (MathFunction *f)
bool hasUnit (Unit *u)
bool hasVariable (Variable *v)
void nameChanged (ExpressionItem *item, bool new_item=false)
void saveFunctionCalled ()
bool stillHasFunction (MathFunction *f)
bool stillHasUnit (Unit *u)
bool stillHasVariable (Variable *v)
bool unitIsUsedByOtherUnits (const Unit *u) const
void unitNameChanged (Unit *u, bool new_item=false)
void variableNameChanged (Variable *v, bool new_item=false)
Functions adding alternative symbols for operators and such


void addDefaultStringAlternative (string replacement, string standard)
void addStringAlternative (string replacement, string standard)
bool delDefaultStringAlternative (string replacement, string standard)
bool delStringAlternative (string replacement, string standard)
Functions for storing values with associated identifiers


size_t addId (MathStructure *mstruct, bool persistent=false)
void delId (size_t id)
MathStructuregetId (size_t id)
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)
Functions for finding a suitable prefix.


PrefixaddPrefix (Prefix *p)
BinaryPrefixgetBestBinaryPrefix (const Number &exp2, const Number &exp) const
BinaryPrefixgetBestBinaryPrefix (int exp2, int exp=1) const
DecimalPrefixgetBestDecimalPrefix (const Number &exp10, const Number &exp, bool all_prefixes=true) const
DecimalPrefixgetBestDecimalPrefix (int exp10, int exp=1, bool all_prefixes=true) const
BinaryPrefixgetExactBinaryPrefix (int exp2, int exp=1) const
DecimalPrefixgetExactDecimalPrefix (int exp10, int exp=1) const
PrefixgetExactPrefix (const Number &o, int exp=1) const
BinaryPrefixgetNearestBinaryPrefix (int exp2, int exp=1) const
DecimalPrefixgetNearestDecimalPrefix (int exp10, int exp=1) const
void prefixNameChanged (Prefix *p, bool new_item=false)
Functions for message handling.


void beginTemporaryStopMessages ()
int endTemporaryStopMessages (int *message_count=NULL, int *warning_count=NULL)
void error (bool critical, const char *TEMPLATE,...)
CalculatorMessagemessage ()
void message (MessageType mtype, const char *TEMPLATE,...)
CalculatorMessagenextMessage ()
bool showArgumentErrors () const
Functions for calculating expressions.


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, string str, int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL, MathStructure *to_struct=NULL, bool make_to_division=true)
string printMathStructureTimeOut (const MathStructure &mstruct, int msecs=100000, const PrintOptions &op=default_print_options)
int testCondition (string expression)
Functions for manipulation of the RPN stack.


MathStructurecalculateRPN (MathFunction *f, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
MathStructurecalculateRPN (MathOperation op, 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 calculateRPN (MathOperation op, int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
MathStructurecalculateRPNBitwiseNot (const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
bool calculateRPNBitwiseNot (int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
MathStructurecalculateRPNLogicalNot (const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
bool calculateRPNLogicalNot (int msecs, const EvaluationOptions &eo=default_evaluation_options, MathStructure *parsed_struct=NULL)
bool calculateRPNRegister (size_t index, int msecs, const EvaluationOptions &eo=default_evaluation_options)
void clearRPNStack ()
void deleteRPNRegister (size_t index)
MathStructuregetRPNRegister (size_t index=1) const
void moveRPNRegister (size_t old_index, size_t new_index)
void moveRPNRegisterDown (size_t index)
void moveRPNRegisterUp (size_t index)
void RPNStackEnter (string str, 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)
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)
bool RPNStackEnter (MathStructure *mstruct, int msecs, const EvaluationOptions &eo=default_evaluation_options)
size_t RPNStackSize () const
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 setRPNRegister (size_t index, MathStructure *mstruct, bool eval=false, 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)
bool setRPNRegister (size_t index, MathStructure *mstruct, int msecs, const EvaluationOptions &eo=default_evaluation_options)
Constructor


 Calculator ()
virtual ~Calculator ()
Functions for exchange rates.


bool canFetch ()
bool checkExchangeRatesDate ()
bool fetchExchangeRates (int timeout=15)
bool fetchExchangeRates (int timeout, string wget_args)
string getExchangeRatesFileName ()
string getExchangeRatesUrl ()
bool hasGnomeVFS ()
bool loadExchangeRates ()
Functions for plotting


bool canPlot ()
bool closeGnuplot ()
MathStructure expressionToPlotVector (string expression, const MathStructure &x_vector, string x_var="\\x", const ParseOptions &po=default_parse_options)
MathStructure expressionToPlotVector (string expression, float min, float max, float step, MathStructure *x_vector=NULL, string x_var="\\x", const ParseOptions &po=default_parse_options)
MathStructure expressionToPlotVector (string expression, const MathStructure &min, const MathStructure &max, const MathStructure &step, MathStructure *x_vector=NULL, string x_var="\\x", const ParseOptions &po=default_parse_options)
MathStructure expressionToPlotVector (string expression, float min, float max, int steps, MathStructure *x_vector=NULL, string x_var="\\x", const ParseOptions &po=default_parse_options)
MathStructure expressionToPlotVector (string expression, const MathStructure &min, const MathStructure &max, int steps, MathStructure *x_vector=NULL, string x_var="\\x", const ParseOptions &po=default_parse_options)
bool gnuplotOpen ()
bool invokeGnuplot (string commands, string commandline_extra="", bool persistent=false)
bool plotVectors (PlotParameters *param, const vector< MathStructure > &y_vectors, const vector< MathStructure > &x_vectors, vector< PlotDataParameters * > &pdps, bool persistent=false)
Functions converting epxressions between units.


MathStructure convert (string str, Unit *from_unit, Unit *to_unit, const EvaluationOptions &eo=default_evaluation_options)
MathStructure convert (double value, Unit *from_unit, Unit *to_unit, const EvaluationOptions &eo=default_evaluation_options)
MathStructure convert (const MathStructure &mstruct, Unit *to_unit, const EvaluationOptions &eo=default_evaluation_options, bool always_convert=true)
MathStructure convert (const MathStructure &mstruct, string composite_, const EvaluationOptions &eo=default_evaluation_options)
MathStructure convertToBaseUnits (const MathStructure &mstruct, const EvaluationOptions &eo=default_evaluation_options)
MathStructure convertToBestUnit (const MathStructure &mstruct, const EvaluationOptions &eo=default_evaluation_options)
MathStructure convertToCompositeUnit (const MathStructure &mstruct, CompositeUnit *cu, const EvaluationOptions &eo=default_evaluation_options, bool always_convert=true)
UnitgetBestUnit (Unit *u, bool allow_only_div=false)
Functions for testing validity of functions, variable and unit names.


string convertToValidFunctionName (string name_)
string convertToValidUnitName (string name_)
string convertToValidVariableName (string name_)
bool functionNameIsValid (const string &name_, int version_numbers[3], bool is_user_defs)
bool functionNameIsValid (const char *name_, int version_numbers[3], bool is_user_defs)
bool functionNameIsValid (const char *name_)
bool functionNameIsValid (const string &name_)
bool functionNameTaken (string name, MathFunction *object=NULL)
string getName (string name="", ExpressionItem *object=NULL, bool force=false, bool always_append=false)
bool nameTaken (string name, ExpressionItem *object=NULL)
bool unitNameIsValid (const string &name_, int version_numbers[3], bool is_user_defs)
bool unitNameIsValid (const char *name_, int version_numbers[3], bool is_user_defs)
bool unitNameIsValid (const char *name_)
bool unitNameIsValid (const string &name_)
bool unitNameTaken (string name, Unit *object=NULL)
bool utf8_pos_is_valid_in_name (char *pos)
bool variableNameIsValid (const string &name_, int version_numbers[3], bool is_user_defs)
bool variableNameIsValid (const char *name_, int version_numbers[3], bool is_user_defs)
bool variableNameIsValid (const char *name_)
bool variableNameIsValid (const string &name_)
bool variableNameTaken (string name, Variable *object=NULL)
Functions for default assumptions for unknown variables and symbols


AssumptionsdefaultAssumptions ()
void setDefaultAssumptions (Assumptions *ass)
Functions for CSV file import/export.


bool exportCSV (const MathStructure &mstruct, const char *file_name, string delimiter=",")
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 importCSV (MathStructure &mstruct, const char *file_name, int first_row=1, string delimiter=",", vector< string > *headers=NULL)
Functions for localization


const string & getComma () const
const string & getDecimalPoint () const
string localToString () const
void setLocale ()
void unsetLocale ()
void useDecimalComma ()
void useDecimalPoint ()
Functions for retrieval of angle units


UnitgetDegUnit ()
UnitgetGraUnit ()
UnitgetRadUnit ()
Functions for global precision


int getPrecision () const
void setPrecision (int precision=DEFAULT_PRECISION)
Functions for loading and saving definitions (variables, functions, units, etc.).


int loadDefinitions (const char *file_name, bool is_user_defs=true)
bool loadGlobalCurrencies ()
bool loadGlobalDataSets ()
bool loadGlobalDefinitions (string filename)
bool loadGlobalDefinitions ()
bool loadGlobalFunctions ()
bool loadGlobalPrefixes ()
bool loadGlobalUnits ()
bool loadGlobalVariables ()
bool loadLocalDefinitions ()
int saveDataObjects ()
int saveDataSets (const char *file_name, bool save_global=false)
bool saveDefinitions ()
int saveFunctions (const char *file_name, bool save_global=false)
int savePrefixes (const char *file_name, bool save_global=false)
int saveUnits (const char *file_name, bool save_global=false)
int saveVariables (const char *file_name, bool save_global=false)
Functions for expression parsing.


string localizeExpression (string str) const
void parse (MathStructure *mstruct, string str, const ParseOptions &po=default_parse_options)
MathStructure parse (string str, const ParseOptions &po=default_parse_options)
bool parseAdd (string &str, MathStructure *mstruct, const ParseOptions &po)
bool parseAdd (string &str, MathStructure *mstruct, const ParseOptions &po, MathOperation s)
bool parseNumber (MathStructure *mstruct, string str, const ParseOptions &po=default_parse_options)
bool parseOperators (MathStructure *mstruct, string str, const ParseOptions &po=default_parse_options)
void parseSigns (string &str) const
bool separateToExpression (string &str, string &to_str, const EvaluationOptions &eo) const
string unlocalizeExpression (string str, const ParseOptions &po=default_parse_options) const

Public Attributes

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

Protected Member Functions

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

Protected Attributes

string AND_str
string and_str
size_t AND_str_len
size_t and_str_len
bool b_argument_errors
bool b_calcvars_was
bool b_functions_was
bool b_gnuplot_open
bool b_rpn_was
bool b_save_called
bool b_units_was
bool b_unknown_was
bool b_variables_was
FILE * calculate_pipe_r
FILE * calculate_pipe_w
pthread_t calculate_thread
pthread_attr_t calculate_thread_attr
string COMMA_S
string COMMA_STR
vector< DataSet * > data_sets
Assumptionsdefault_assumptions
vector< string > default_real_signs
vector< string > default_signs
vector< MathFunction * > deleted_functions
vector< Unit * > deleted_units
vector< Variable * > deleted_variables
int disable_errors_ref
string DOT_S
string DOT_STR
bool exchange_rates_warning_issued
vector< size_t > freed_ids
string gnuplot_cmdline
FILE * gnuplot_pipe
int has_gnomevfs
int i_precision
int ianglemode
Sgi::hash_map< size_t,
MathStructure * > 
id_structs
size_t ids_i
Sgi::hash_map< size_t, bool > ids_p
string ILLEGAL_IN_NAMES
string ILLEGAL_IN_NAMES_MINUS_SPACE_STR
string ILLEGAL_IN_UNITNAMES
bool local_to
vector< CalculatorMessagemessages
string minus_str
size_t minus_str_len
string NAME_NUMBER_PRE_S
string NAME_NUMBER_PRE_STR
string OR_str
string or_str
size_t OR_str_len
size_t or_str_len
string per_str
size_t per_str_len
string plus_str
size_t plus_str_len
FILE * print_pipe_r
FILE * print_pipe_w
pthread_t print_thread
pthread_attr_t print_thread_attr
vector< string > real_signs
vector< MathStructure * > rpn_stack
char * saved_locale
vector< string > signs
vector< int > stopped_errors_count
vector< int > stopped_messages_count
vector< int > stopped_warnings_count
string times_str
size_t times_str_len
vector< void * > ufv [4][UFV_LENGTHS]
vector< size_t > ufv_i [4][UFV_LENGTHS]
vector< void * > ufvl
vector< size_t > ufvl_i
vector< char > ufvl_t
char vbuffer [200]
string XOR_str
size_t XOR_str_len

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

Generated by  Doxygen 1.6.0   Back to index