Add a Techno::getRule() method and simply Techno::getValue() & Techno::getValueAsString() methods
This commit is contained in:
parent
d0b2c0c6eb
commit
e3bdbfb7f0
|
@ -13,7 +13,8 @@ void translator(DTRException const& e) {
|
|||
}
|
||||
|
||||
|
||||
// specify that Techno::getValue & Techno::getValueAsString methods have optional arguments
|
||||
// specify that Techno::getRule & Techno::getValue & Techno::getValueAsString methods have optional arguments
|
||||
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getRule_overloads , getRule , 1, 3);
|
||||
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getValue_overloads , getValue , 1, 3);
|
||||
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getValueAsString_overloads, getValueAsString, 1, 3);
|
||||
// specify that Techno::addRule method has optional arguments
|
||||
|
@ -49,6 +50,7 @@ BOOST_PYTHON_MODULE(pyDTR) {
|
|||
// accessors
|
||||
.def("getName" , &Techno::getName)
|
||||
.def("getUnit" , &Techno::getUnit)
|
||||
.def("getRule" , &Techno::getRule , getRule_overloads()[return_value_policy<reference_existing_object>()])
|
||||
.def("getValue" , &Techno::getValue , getValue_overloads())
|
||||
.def("getValueAsString", &Techno::getValueAsString, getValueAsString_overloads())
|
||||
|
||||
|
|
|
@ -46,7 +46,7 @@ ARule* Techno::addARule (Name name, double value, Name ref, Name layer1, Name la
|
|||
return arule;
|
||||
}
|
||||
|
||||
double Techno::getValue(Name name, Name layer1, Name layer2) {
|
||||
Rule* Techno::getRule(Name name, Name layer1, Name layer2) {
|
||||
bool testL1 = (layer1 == Name("")) ? false : true;
|
||||
bool testL2 = (layer2 == Name("")) ? false : true;
|
||||
|
||||
|
@ -57,18 +57,18 @@ double Techno::getValue(Name name, Name layer1, Name layer2) {
|
|||
if (rule->getLayer1() == layer1) {
|
||||
if (testL2) {
|
||||
if (rule->getLayer2() == layer2) {
|
||||
return rule->getValue();
|
||||
return rule;
|
||||
}
|
||||
} else {
|
||||
return rule->getValue();
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return rule->getValue();
|
||||
return rule;
|
||||
}
|
||||
}
|
||||
}
|
||||
string error ("[ERROR] Could not found rule: ");
|
||||
string error ("[ERROR] Could not find rule: ");
|
||||
error += name.getString();
|
||||
error += ".";
|
||||
error += layer1.getString();
|
||||
|
@ -78,36 +78,12 @@ double Techno::getValue(Name name, Name layer1, Name layer2) {
|
|||
throw DTRException(error);
|
||||
}
|
||||
|
||||
double Techno::getValue(Name name, Name layer1, Name layer2) {
|
||||
return getRule(name, layer1, layer2)->getValue();
|
||||
}
|
||||
|
||||
string Techno::getValueAsString(Name name, Name layer1, Name layer2) {
|
||||
bool testL1 = (layer1 == Name("")) ? false : true;
|
||||
bool testL2 = (layer2 == Name("")) ? false : true;
|
||||
|
||||
for (size_t i = 0 ; i < _rules.size() ; i++) {
|
||||
Rule* rule = _rules[i];
|
||||
if (rule->getName() == name) {
|
||||
if (testL1) {
|
||||
if (rule->getLayer1() == layer1) {
|
||||
if (testL2) {
|
||||
if (rule->getLayer2() == layer2) {
|
||||
return rule->getValueAsString();
|
||||
}
|
||||
} else {
|
||||
return rule->getValueAsString();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return rule->getValueAsString();
|
||||
}
|
||||
}
|
||||
}
|
||||
string error ("[ERROR] Could not found rule: ");
|
||||
error += name.getString();
|
||||
error += ".";
|
||||
error += layer1.getString();
|
||||
error += ".";
|
||||
error += layer2.getString();
|
||||
error += ".";
|
||||
throw DTRException(error);
|
||||
return getRule(name, layer1, layer2)->getValueAsString();
|
||||
}
|
||||
|
||||
Techno* Techno::readFromFile(const string filePath) {
|
||||
|
|
|
@ -31,6 +31,7 @@ class Techno {
|
|||
Rule* addRule (Name name, double value, Name ref, Name layer1=Name(""), Name layer2=Name(""));
|
||||
ARule* addARule(Name name, double value, Name ref, Name layer1 , Name layer2);
|
||||
|
||||
Rule* getRule(Name name, Name layer1=Name(""), Name layer2=Name(""));
|
||||
double getValue(Name name, Name layer1=Name(""), Name layer2=Name(""));
|
||||
std::string getValueAsString(Name name, Name layer1=Name(""), Name layer2=Name(""));
|
||||
|
||||
|
|
Loading…
Reference in New Issue