2006-11-05 00:31:17 +01:00
|
|
|
#include <iostream>
|
2007-05-08 21:16:35 +02:00
|
|
|
|
2006-11-05 00:31:17 +01:00
|
|
|
#include "NumericalConstants.hh"
|
2006-11-23 20:10:41 +01:00
|
|
|
|
2006-11-05 00:31:17 +01:00
|
|
|
NumericalConstants::NumericalConstants()
|
|
|
|
{
|
2007-05-08 21:16:35 +02:00
|
|
|
AddConstant("0");
|
|
|
|
AddConstant("1");
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
|
2007-05-08 21:16:35 +02:00
|
|
|
int
|
|
|
|
NumericalConstants::AddConstant(const string &iConst)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2007-05-08 21:16:35 +02:00
|
|
|
map<string, int>::iterator iter = numConstantsIndex.find(iConst);
|
2007-06-04 00:35:30 +02:00
|
|
|
//cout << "iConst=" << iConst << "\n" ;
|
2006-11-23 20:10:41 +01:00
|
|
|
if (iter != numConstantsIndex.end())
|
|
|
|
return iter->second;
|
|
|
|
|
2007-05-08 21:16:35 +02:00
|
|
|
if (atof(iConst.c_str()) < 0)
|
|
|
|
{
|
|
|
|
cerr << "Can't handle a negative constant..!" << endl;
|
|
|
|
exit(-1);
|
|
|
|
}
|
|
|
|
|
2006-11-23 20:10:41 +01:00
|
|
|
int id = (int) mNumericalConstants.size();
|
2006-11-05 00:31:17 +01:00
|
|
|
mNumericalConstants.push_back(iConst);
|
2006-11-23 20:10:41 +01:00
|
|
|
numConstantsIndex[iConst] = id;
|
|
|
|
return id;
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
|
2007-05-08 21:16:35 +02:00
|
|
|
string
|
|
|
|
NumericalConstants::get(int ID) const
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2007-05-08 21:16:35 +02:00
|
|
|
if (ID < (int) mNumericalConstants.size())
|
|
|
|
return mNumericalConstants[ID];
|
2006-11-05 00:31:17 +01:00
|
|
|
else
|
|
|
|
{
|
2007-05-08 21:16:35 +02:00
|
|
|
cerr << "Unknown constant" << endl;
|
|
|
|
exit(-1);
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-05-08 21:16:35 +02:00
|
|
|
double
|
|
|
|
NumericalConstants::getDouble(int iID) const
|
|
|
|
{
|
|
|
|
return(atof(get(iID).c_str()));
|
|
|
|
}
|