Adding setName & setUnit methods on Techno object.
getRule method of Techno does not throw exception anymore if rule is not found : a NULL Rule* is returned instead. but getValue methods throw exception if rule is not found
This commit is contained in:
parent
cefe8dc6a7
commit
9e5b5226d9
|
@ -74,22 +74,33 @@ Rule* Techno::getRule(Name name, Name layer1, Name layer2) {
|
|||
if ((rule->getName() == name) && (rule->getLayer1() == layer1) && (rule->getLayer2() == layer2))
|
||||
return rule;
|
||||
}
|
||||
string error ("[ERROR] Could not find rule: ");
|
||||
error += name.getString();
|
||||
error += ".";
|
||||
error += layer1.getString();
|
||||
error += ".";
|
||||
error += layer2.getString();
|
||||
error += ".";
|
||||
throw DTRException(error);
|
||||
//string error ("[ERROR] Could not find rule: ");
|
||||
//error += name.getString();
|
||||
//error += ".";
|
||||
//error += layer1.getString();
|
||||
//error += ".";
|
||||
//error += layer2.getString();
|
||||
//error += ".";
|
||||
//throw DTRException(error);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
double Techno::getValue(Name name, Name layer1, Name layer2) {
|
||||
return getRule(name, layer1, layer2)->getValue();
|
||||
Rule* r = getRule(name, layer1, layer2);
|
||||
if(!r) {
|
||||
string error = "[ERROR] Could not find rule: " + name.getString() + "." + layer1.getString() + "." + layer2.getString() + ".";
|
||||
throw DTRException(error);
|
||||
}
|
||||
return r->getValue();
|
||||
}
|
||||
|
||||
const string& Techno::getValueAsString(Name name, Name layer1, Name layer2) {
|
||||
return getRule(name, layer1, layer2)->getValueAsString();
|
||||
Rule* r = getRule(name, layer1, layer2);
|
||||
if(!r) {
|
||||
string error = "[ERROR] Could not find rule: " + name.getString() + "." + layer1.getString() + "." + layer2.getString() + ".";
|
||||
throw DTRException(error);
|
||||
}
|
||||
return r->getValueAsString();
|
||||
}
|
||||
|
||||
Techno* Techno::readFromFile(const string filePath) {
|
||||
|
|
|
@ -28,6 +28,9 @@ class Techno {
|
|||
inline Name getUnit();
|
||||
inline std::vector<Rule*>& getRules();
|
||||
|
||||
inline void setName(Name);
|
||||
inline void setUnit(Name);
|
||||
|
||||
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);
|
||||
|
||||
|
@ -47,6 +50,9 @@ inline Name Techno::getName() { return _name; };
|
|||
inline Name Techno::getUnit() { return _unit; };
|
||||
inline std::vector<Rule*>& Techno::getRules() { return _rules; };
|
||||
|
||||
inline void Techno::setName(Name name) { _name = name; };
|
||||
inline void Techno::setUnit(Name unit) { _unit = unit; };
|
||||
|
||||
} // namespace DTR
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Reference in New Issue