wxEcMath - Official documentation
0.6.4
|
Evaluates mathematical expressions. More...
#include <ec_engine.h>
Public Member Functions | |
wxArrayString | GetLog () |
wxEcEngine () | |
~wxEcEngine () | |
wxString | GetFormula () |
wxString | GetIndicator () |
int | GetLastError () |
double | GetLastResult () |
wxString | TranslateError (int code) |
int | GetTrigonometricMode () |
void | SetTrigonometricMode (int trigmode) |
void | Reset (bool formulaToo, bool constantsToo) |
bool | DeleteConstant (wxString name) |
bool | GetConstant (wxString expression, double *destination) |
bool | GetConstant (wxString expression, double *destination, double defaultval) |
bool | HasConstant (wxString expression) |
int | GetConstantCount () |
bool | ListAllConstants (wxControlWithItems *destination, bool full=true) |
bool | ListAllConstants (wxArrayString *destination, bool full=true) |
bool | SetConstant (wxString name, wxDouble value) |
void | ResetConstants (bool pDefault=true) |
bool | ApplyFunction (wxString *function, double *value) |
double | Compute () |
bool | Derivate (double where, double *result, double *storewhere=NULL) |
bool | IsValid (wxString *expression) |
bool | SetFormula (wxString expression) |
void | Simplify (wxString *expression) |
void | UseDebug (bool state) |
Evaluates mathematical expressions.
When the object is created, the radian mode is activated and you can compute directly. To do it, see the sample written on the main page of this documentation.
wxEcEngine::wxEcEngine | ( | ) |
The default constructor which takes no parameter.
wxEcEngine::~wxEcEngine | ( | ) |
The default destructor.
bool wxEcEngine::ApplyFunction | ( | wxString * | function, |
double * | value | ||
) |
Applies a function on the given value.
function | The pointer to the name of the function. |
value | The pointer to the value which will be read and overwritten. |
double wxEcEngine::Compute | ( | ) |
Evaluates the mathematical expression you have set with SetFormula(). To be sure of the result you must call GetLastError().
bool wxEcEngine::DeleteConstant | ( | wxString | name | ) |
Deletes a constant.
name | The name of the constant. |
bool wxEcEngine::Derivate | ( | double | where, |
double * | result, | ||
double * | storewhere = NULL |
||
) |
Performs an approximation of the derivative of the loaded expression at a given point.
where | The X-coordinate which must be evaluated. |
result | The pointer to the floating number which will contain df(x)/dx. It must be valid. |
storewhere | A pointer to store f(x) as a floating number. |
bool wxEcEngine::GetConstant | ( | wxString | expression, |
double * | destination | ||
) |
Converts a constant or a floating number encoded as a wxString, and stores it into the destination.
expression | Input to convert. |
destination | Pointer to a double where to store the value. |
bool wxEcEngine::GetConstant | ( | wxString | expression, |
double * | destination, | ||
double | defaultval | ||
) |
Variant method allowing to return a default value when the expression cannot be interpreted.
int wxEcEngine::GetConstantCount | ( | ) |
Gives the number of constants currently defined.
wxString wxEcEngine::GetFormula | ( | ) |
Reads the formula currently stored by the object.
wxString wxEcEngine::GetIndicator | ( | ) |
Returns the tip associated with the latest error. It helps you to track down a problem when GetLastError() does not return wxECE_NOERROR.
int wxEcEngine::GetLastError | ( | ) |
Returns the latest error obtained with Compute().
double wxEcEngine::GetLastResult | ( | ) |
Returns the latest result obtained with Compute().
wxArrayString wxEcEngine::GetLog | ( | ) |
Returns the log generated by the evaluation of the formula.
|
inline |
Returns the trigonometric mode used for cosine, sine and tangent.
bool wxEcEngine::HasConstant | ( | wxString | expression | ) |
Tells if the expression exists as a variable or a number.
expression | Input to look for. |
bool wxEcEngine::IsValid | ( | wxString * | expression | ) |
Checks the validity of an expression. The method is based on a set of criteria, such as the number of brackets. The symbols used in the expression will not be validated.
expression | A pointer to the expression to check. |
bool wxEcEngine::ListAllConstants | ( | wxControlWithItems * | destination, |
bool | full = true |
||
) |
Makes a dump of all the constants into a wxControlWithItems, it can be wxListBox, wxComboBox...
destination | A pointer to the control which will receive the data. |
full | Tells if the value should also be included. |
bool wxEcEngine::ListAllConstants | ( | wxArrayString * | destination, |
bool | full = true |
||
) |
Makes a dump of all the constants into a wxArrayString.
destination | A pointer to the array which will receive the data. |
full | Tells if the value should also be included. |
void wxEcEngine::Reset | ( | bool | formulaToo, |
bool | constantsToo | ||
) |
Resets the engine.
formulaToo | Will clear the formula set with SetFormula(). |
constantsToo | Will restore the default constants. |
void wxEcEngine::ResetConstants | ( | bool | pDefault = true | ) |
Deletes all the constants, and sets the default ones if requested.
bool wxEcEngine::SetConstant | ( | wxString | name, |
wxDouble | value | ||
) |
Defines a new constant. If the constant already exists, it will be overwritten.
name | The name of the new constant. |
value | The value of the new constant. |
bool wxEcEngine::SetFormula | ( | wxString | expression | ) |
Stores the internal formula which will be used for all the computations. If the formula is rejected, wxECE_SYNTAX will be returned by GetLastError().
expression | The formula you want to use. |
|
inline |
Sets the trigonometric mode to be used for cosine, sine and tangent.
trigmode | A mode defined in ec_defs.h (wxECA_*). |
void wxEcEngine::Simplify | ( | wxString * | expression | ) |
Performs the simplifications required to make the expression readable by the interpreter. You cannot expect all inputs to be valid after this operation. It depends on the quality of the input (in terms of wrong syntax).
expression | A pointer to a string which will be read and rewritten. |
wxString wxEcEngine::TranslateError | ( | int | code | ) |
Returns a string describing the meaning of an error code.
code | An error code defined in ec_defs.h (wxECE_*). |
|
inline |
Enables or disable the storage of debug information in LogAction(). This function is useless if wxECM_USEDEBUG is not defined.