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:
Damien Dupuis 2010-11-16 15:33:42 +00:00
parent cefe8dc6a7
commit 9e5b5226d9
2 changed files with 27 additions and 10 deletions

View File

@ -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) {

View File

@ -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);
@ -46,6 +49,9 @@ class Techno {
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