144 lines
3.3 KiB
C++
144 lines
3.3 KiB
C++
#ifndef headerfilecalculation
|
|
#define headerfilecalculation
|
|
|
|
/*!
|
|
\file parsermanager.h
|
|
\brief object of type ParserManager we're using during calculating
|
|
*/
|
|
|
|
#include "resource.h"
|
|
#include <ttmath/ttmathparser.h>
|
|
#include "programresources.h"
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
/*!
|
|
\brief object of type ParserManager we're using during calculating
|
|
|
|
In our program we're using three kind of precisions. First is the smallest
|
|
, and the third is the biggest. Because precision is established during
|
|
compilation (templates) we need three different objects. ParserManager
|
|
helps us to maintain these objects.
|
|
*/
|
|
class ParserManager
|
|
{
|
|
public:
|
|
|
|
ParserManager();
|
|
ParserManager(const ParserManager & p);
|
|
ParserManager & operator=(const ParserManager & p);
|
|
~ParserManager();
|
|
|
|
|
|
/*!
|
|
the main method which call parserX.Parse(...)
|
|
*/
|
|
ttmath::ErrorCode Parse();
|
|
|
|
|
|
/*!
|
|
we call this method directly after when we have left
|
|
WaitForCalculatingAndBlockForStop() method from the ThreadController
|
|
|
|
only in this method we can read variables which can be changed
|
|
by the first thread
|
|
*/
|
|
void MakeCopyOfVariables();
|
|
|
|
|
|
/*!
|
|
it prepares our three parsers to work, it should be called only once
|
|
*/
|
|
void Init();
|
|
|
|
|
|
/*!
|
|
this method prints result
|
|
(a correct value if was or an error instead)
|
|
*/
|
|
void PrintResult();
|
|
|
|
|
|
private:
|
|
|
|
ttmath::Parser<ttmath::Big<1,3> > parser1;
|
|
ttmath::Parser<ttmath::Big<2,6> > parser2;
|
|
ttmath::Parser<ttmath::Big<3,9> > parser3;
|
|
|
|
ttmath::Objects variables, functions;
|
|
|
|
const unsigned int buffer_len;
|
|
char * buffer;
|
|
|
|
int base_input, base_output;
|
|
|
|
bool always_scientific;
|
|
int when_scientific;
|
|
int rounding;
|
|
int precision;
|
|
Languages::Country country;
|
|
ttmath::ErrorCode code;
|
|
|
|
|
|
template<class ValueType>
|
|
void PrintResult(ttmath::Parser<ValueType> & matparser)
|
|
{
|
|
std::string result, part;
|
|
unsigned int i = 0;
|
|
|
|
|
|
for(i=0 ; i<matparser.stack.size() ; ++i)
|
|
{
|
|
|
|
if( matparser.stack[i].value.ToString(part,base_output, always_scientific, when_scientific, rounding) )
|
|
{
|
|
// we shouldn't have this error in the new version of ToStrign(...)
|
|
// (it could be if were using very big mantissa and exponent
|
|
// in the Big type)
|
|
|
|
//
|
|
// look at this: part.erase()
|
|
//
|
|
// we're using it because it's something wrong on gcc
|
|
// when we're compiling with -O3 optimization flag
|
|
//
|
|
// gcc version 3.4.2 (mingw-special) with -O3
|
|
// program tell us if there was an error here (from ToString())
|
|
// but in fact it shouldn't have been here
|
|
// I don't know where is the problem (I think in optimization,
|
|
// with -O1 and -O2 program works well and visual express works perfectly
|
|
// as well)
|
|
|
|
part.erase();
|
|
|
|
// we can omit this part.erase() and use operator+= instead of
|
|
// operator= below, for example:
|
|
// part += GetPrgRes()->GetLanguages()->GuiMessage(country, Languages::overflow_during_printing);
|
|
// will be working correctly on gcc with -O3
|
|
|
|
// this error doesn't appear always, it can be seen, for example,
|
|
// if we use Big<1,3> type and we give '2^32' for calculating
|
|
|
|
// I didn't check this error on a new version of gcc
|
|
|
|
part = GetPrgRes()->GetLanguages()->GuiMessage(country, Languages::overflow_during_printing);
|
|
}
|
|
|
|
result += part;
|
|
|
|
if( i < matparser.stack.size()-1 )
|
|
result += " ";
|
|
}
|
|
|
|
SetDlgItemText(GetPrgRes()->GetMainWindow(),IDC_OUTPUT_EDIT,result.c_str());
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|