wxEcMath - Official documentation  0.6.4
Public Member Functions | List of all members
wxEcEngine Class Reference

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)
 

Detailed Description

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.

Constructor & Destructor Documentation

wxEcEngine::wxEcEngine ( )

The default constructor which takes no parameter.

wxEcEngine::~wxEcEngine ( )

The default destructor.

Member Function Documentation

bool wxEcEngine::ApplyFunction ( wxString *  function,
double *  value 
)

Applies a function on the given value.

Parameters
functionThe pointer to the name of the function.
valueThe pointer to the value which will be read and overwritten.
Returns
true on success, false if the function is unknown or not defined for the given value.
double wxEcEngine::Compute ( )

Evaluates the mathematical expression you have set with SetFormula(). To be sure of the result you must call GetLastError().

Returns
The result of the computation. Zero is the default value if it failed.
See also
GetLastResult()
bool wxEcEngine::DeleteConstant ( wxString  name)

Deletes a constant.

Parameters
nameThe name of the constant.
Returns
true on success, false on failure.
bool wxEcEngine::Derivate ( double  where,
double *  result,
double *  storewhere = NULL 
)

Performs an approximation of the derivative of the loaded expression at a given point.

Parameters
whereThe X-coordinate which must be evaluated.
resultThe pointer to the floating number which will contain df(x)/dx. It must be valid.
storewhereA pointer to store f(x) as a floating number.
Returns
true on success, false on failure (see GetLastError() to know more about).
See also
wxEcEngine::SetFormula()
wxECD_DXSTEP
bool wxEcEngine::GetConstant ( wxString  expression,
double *  destination 
)

Converts a constant or a floating number encoded as a wxString, and stores it into the destination.

Parameters
expressionInput to convert.
destinationPointer to a double where to store the value.
Returns
true if the constant is found and converted, false if it is neither a valid constant nor a floating number.
Remarks
This function can be seen as a "wxString to Double converter". If wxString is the name of a constant, it will look for its value. Else it tries to convert into double in the destination.
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.

See also
SetFormula()
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().

Returns
wxECE_NOERROR if no error occured.
See also
ec_defs.h
GetIndicator()
TranslateError()
double wxEcEngine::GetLastResult ( )

Returns the latest result obtained with Compute().

See also
GetLastError()
wxArrayString wxEcEngine::GetLog ( )

Returns the log generated by the evaluation of the formula.

Remarks
This function is only available if wxECM_USEDEBUG is defined. To use it, code like this :
#ifdef wxECM_USEDEBUG
wxArrayString myLog = myEngine->GetLog();
#endif
See also
wxECM_USEDEBUG
int wxEcEngine::GetTrigonometricMode ( )
inline

Returns the trigonometric mode used for cosine, sine and tangent.

Returns
The current mode. wxECA_RADIAN should be the default value.
See also
ec_defs.h
bool wxEcEngine::HasConstant ( wxString  expression)

Tells if the expression exists as a variable or a number.

Parameters
expressionInput to look for.
Returns
true if the constant is found and converted, false if it is neither a valid constant nor a floating number.
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.

Parameters
expressionA pointer to the expression to check.
Returns
true if the expression appears logically correct, false in the other cases.
bool wxEcEngine::ListAllConstants ( wxControlWithItems *  destination,
bool  full = true 
)

Makes a dump of all the constants into a wxControlWithItems, it can be wxListBox, wxComboBox...

Parameters
destinationA pointer to the control which will receive the data.
fullTells if the value should also be included.
Returns
true on success, false on failure.
Remarks
If the result is true, it does not presume that at least 1 item has been added. You have to make sure on your own.
bool wxEcEngine::ListAllConstants ( wxArrayString *  destination,
bool  full = true 
)

Makes a dump of all the constants into a wxArrayString.

Parameters
destinationA pointer to the array which will receive the data.
fullTells if the value should also be included.
Returns
true on success, false on failure.
Remarks
This function has to be used for non-GUI applications.
void wxEcEngine::Reset ( bool  formulaToo,
bool  constantsToo 
)

Resets the engine.

Parameters
formulaTooWill clear the formula set with SetFormula().
constantsTooWill 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.

Warning
The name of the constant cannot begin with a figure
Parameters
nameThe name of the new constant.
valueThe value of the new constant.
Returns
true if the constant has been (re)defined, false on failure.
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().

Remarks
The expression will be simplified and checked before being stored.
Parameters
expressionThe formula you want to use.
Returns
true if the formula is accepted, false if it is rejected.
void wxEcEngine::SetTrigonometricMode ( int  trigmode)
inline

Sets the trigonometric mode to be used for cosine, sine and tangent.

Parameters
trigmodeA 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).

Parameters
expressionA 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.

Parameters
codeAn error code defined in ec_defs.h (wxECE_*).
void wxEcEngine::UseDebug ( bool  state)
inline

Enables or disable the storage of debug information in LogAction(). This function is useless if wxECM_USEDEBUG is not defined.

See also
wxECM_USEDEBUG
wxEcEngine::LogAction()

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



Documentation generated with Doxygen 1.8.10
Hosted on :
Get wxEcMath at SourceForge.net