Skip to content
Snippets Groups Projects
Commit 67c3f2d1 authored by Giovanni Bussi's avatar Giovanni Bussi
Browse files

Changed opMap construction

opMap is now constructed in a single statement. This avoids
problems possibly arising with multiple threads accessing for the first time
to this method simultaneously.

opMap is then made const for clarity.

(cherry picked from commit 10cbe7e8)
parent ccac28fb
No related branches found
No related tags found
No related merge requests found
......@@ -332,37 +332,36 @@ Operation* Parser::getOperatorOperation(const std::string& name) {
Operation* Parser::getFunctionOperation(const std::string& name, const map<string, CustomFunction*>& customFunctions) {
static map<string, Operation::Id> opMap;
if (opMap.size() == 0) {
opMap["sqrt"] = Operation::SQRT;
opMap["exp"] = Operation::EXP;
opMap["log"] = Operation::LOG;
opMap["sin"] = Operation::SIN;
opMap["cos"] = Operation::COS;
opMap["sec"] = Operation::SEC;
opMap["csc"] = Operation::CSC;
opMap["tan"] = Operation::TAN;
opMap["cot"] = Operation::COT;
opMap["asin"] = Operation::ASIN;
opMap["acos"] = Operation::ACOS;
opMap["atan"] = Operation::ATAN;
opMap["sinh"] = Operation::SINH;
opMap["cosh"] = Operation::COSH;
opMap["tanh"] = Operation::TANH;
opMap["erf"] = Operation::ERF;
opMap["erfc"] = Operation::ERFC;
opMap["step"] = Operation::STEP;
opMap["delta"] = Operation::DELTA;
opMap["square"] = Operation::SQUARE;
opMap["cube"] = Operation::CUBE;
opMap["recip"] = Operation::RECIPROCAL;
opMap["min"] = Operation::MIN;
opMap["max"] = Operation::MAX;
opMap["abs"] = Operation::ABS;
opMap["floor"] = Operation::FLOOR;
opMap["ceil"] = Operation::CEIL;
opMap["select"] = Operation::SELECT;
}
const static map<string, Operation::Id> opMap ={
{ "sqrt" , Operation::SQRT },
{ "exp" , Operation::EXP },
{ "log" , Operation::LOG },
{ "sin" , Operation::SIN },
{ "cos" , Operation::COS },
{ "sec" , Operation::SEC },
{ "csc" , Operation::CSC },
{ "tan" , Operation::TAN },
{ "cot" , Operation::COT },
{ "asin" , Operation::ASIN },
{ "acos" , Operation::ACOS },
{ "atan" , Operation::ATAN },
{ "sinh" , Operation::SINH },
{ "cosh" , Operation::COSH },
{ "tanh" , Operation::TANH },
{ "erf" , Operation::ERF },
{ "erfc" , Operation::ERFC },
{ "step" , Operation::STEP },
{ "delta" , Operation::DELTA },
{ "square" , Operation::SQUARE },
{ "cube", Operation::CUBE },
{ "recip" , Operation::RECIPROCAL },
{ "min" , Operation::MIN },
{ "max" , Operation::MAX },
{ "abs" , Operation::ABS },
{ "floor" , Operation::FLOOR },
{ "ceil" , Operation::CEIL },
{ "select" , Operation::SELECT },
};
string trimmed = name.substr(0, name.size()-1);
// First check custom functions.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment