150 lines
2.9 KiB
C++
150 lines
2.9 KiB
C++
#include "compileconfig.h"
|
|
#include "parsermanager.h"
|
|
|
|
|
|
|
|
|
|
ParserManager::ParserManager() : buffer_len(300)
|
|
{
|
|
buffer = 0;
|
|
base_input = base_output = 10;
|
|
always_scientific = 0;
|
|
when_scientific = 15;
|
|
rounding = -2;
|
|
}
|
|
|
|
|
|
ParserManager::ParserManager(const ParserManager & p) : buffer_len(p.buffer_len)
|
|
{
|
|
buffer = 0;
|
|
base_input = p.base_input;
|
|
base_output = p.base_output;
|
|
always_scientific = p.always_scientific;
|
|
when_scientific = p.when_scientific;
|
|
rounding = p.rounding;
|
|
}
|
|
|
|
|
|
ParserManager & ParserManager::operator=(const ParserManager & p)
|
|
{
|
|
buffer = 0;
|
|
|
|
return *this;
|
|
}
|
|
|
|
|
|
ParserManager::~ParserManager()
|
|
{
|
|
delete [] buffer;
|
|
}
|
|
|
|
|
|
ttmath::ErrorCode ParserManager::Parse()
|
|
{
|
|
try
|
|
{
|
|
switch( precision )
|
|
{
|
|
case 0:
|
|
parser1.SetBase(base_input);
|
|
code = parser1.Parse(buffer);
|
|
break;
|
|
|
|
case 1:
|
|
parser2.SetBase(base_input);
|
|
code = parser2.Parse(buffer);
|
|
break;
|
|
|
|
default:
|
|
parser3.SetBase(base_input);
|
|
code = parser3.Parse(buffer);
|
|
break;
|
|
}
|
|
}
|
|
catch(...)
|
|
{
|
|
// we are in a thread, we shouldn't go up
|
|
code = ttmath::err_internal_error;
|
|
}
|
|
|
|
return code;
|
|
}
|
|
|
|
|
|
void ParserManager::MakeCopyOfVariables()
|
|
{
|
|
unsigned int i;
|
|
|
|
char * pchar = (char*)GetPrgRes()->GetBuffer();
|
|
for(i = 0 ; i<buffer_len-1 && pchar[i]!=0 ; ++i)
|
|
buffer[i] = pchar[i];
|
|
|
|
buffer[i] = 0;
|
|
|
|
//
|
|
|
|
variables = *GetPrgRes()->GetVariables();
|
|
functions = *GetPrgRes()->GetFunctions();
|
|
|
|
//
|
|
base_input = GetPrgRes()->GetBaseInput();
|
|
base_output = GetPrgRes()->GetBaseOutput();
|
|
|
|
always_scientific = GetPrgRes()->GetDisplayAlwaysScientific();
|
|
when_scientific = GetPrgRes()->GetDisplayWhenScientific();
|
|
rounding = GetPrgRes()->GetDisplayRounding();
|
|
precision = GetPrgRes()->GetPrecision();
|
|
|
|
country = GetPrgRes()->GetLanguages()->GetCurrentLanguage();
|
|
}
|
|
|
|
|
|
void ParserManager::Init()
|
|
{
|
|
buffer = new char[buffer_len];
|
|
buffer[0] = 0;
|
|
|
|
parser1.SetStopObject( GetPrgRes()->GetThreadController()->GetStopObject() );
|
|
parser1.SetVariables( &variables );
|
|
parser1.SetFunctions( &functions );
|
|
|
|
parser2.SetStopObject( GetPrgRes()->GetThreadController()->GetStopObject() );
|
|
parser2.SetVariables( &variables );
|
|
parser2.SetFunctions( &functions );
|
|
|
|
parser3.SetStopObject( GetPrgRes()->GetThreadController()->GetStopObject() );
|
|
parser3.SetVariables( &variables );
|
|
parser3.SetFunctions( &functions );
|
|
}
|
|
|
|
|
|
void ParserManager::PrintResult()
|
|
{
|
|
if( code == ttmath::err_ok )
|
|
{
|
|
switch( precision )
|
|
{
|
|
case 0:
|
|
return PrintResult(parser1);
|
|
|
|
case 1:
|
|
return PrintResult(parser2);
|
|
|
|
default:
|
|
return PrintResult(parser3);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
// we can call GetPrgRes() here because we're reading
|
|
// static value like GetMainWindow() which are set only once
|
|
// at the beginning of the program and will never be changed later
|
|
// by the first thread
|
|
|
|
SetDlgItemText(
|
|
GetPrgRes()->GetMainWindow(),
|
|
IDC_OUTPUT_EDIT,
|
|
GetPrgRes()->GetLanguages()->ErrorMessage(country, code) );
|
|
}
|
|
}
|