New version attribute in Techno object (it is parsed and drived)

Recently adds have been adjusted in PyDtr.py

    Examples have been updated (c++ is tested, python fails on my Mac due to a strange python2.6.6 behavior I have to check this)
This commit is contained in:
Damien Dupuis 2010-11-17 15:09:59 +00:00
parent 9e5b5226d9
commit 48407432c9
3 changed files with 24 additions and 38 deletions

View File

@ -46,6 +46,8 @@ BOOST_PYTHON_MODULE(DTR) {
// modifiers
.def("setType" , &Rule::setType )
.def("setValue" , &Rule::setValue )
.def("setRef" , &Rule::setRef )
;
// class DTR::ARule derived from DTR::Rule
@ -53,15 +55,19 @@ BOOST_PYTHON_MODULE(DTR) {
;
// class DTR::Techno
class_<Techno>("Techno", init<Name, Name>())
class_<Techno>("Techno", init<Name, Name, Name>())
// accessors
.def("getName" , &Techno::getName)
.def("getUnit" , &Techno::getUnit)
.def("getVersion" , &Techno::getVersion)
.def("getRule" , &Techno::getRule , getRule_overloads()[return_value_policy<reference_existing_object>()])
.def("getValue" , &Techno::getValue , getValue_overloads())
.def("getValueAsString", &Techno::getValueAsString, getValueAsString_overloads()[return_value_policy<copy_const_reference>()])
// modifiers
.def("setName" , &Techno::setName)
.def("setUnit" , &Techno::setUnit)
.def("setVersion" , &Techno::setVersion)
.def("addRule" , &Techno::addRule , addRule_overloads()[return_value_policy<reference_existing_object>()])
.def("addARule" , &Techno::addARule, return_value_policy<reference_existing_object>())

View File

@ -36,7 +36,7 @@ namespace {
}
namespace DTR {
Techno::Techno(Name name, Name unit) : _name(name), _unit(unit) {}
Techno::Techno(Name name, Name unit, Name version) : _name(name), _unit(unit), _version(version) {}
Rule* Techno::addRule (Name name, double value, Name ref, Name layer1, Name layer2) {
Rule* rule = new Rule(name, value, ref, layer1, layer2);
@ -51,37 +51,11 @@ ARule* Techno::addARule (Name name, double value, Name ref, Name layer1, Name la
}
Rule* Techno::getRule(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;
// }
// } else {
// return rule;
// }
// }
// } else {
// return rule;
// }
// }
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);
return NULL;
}
@ -111,19 +85,20 @@ Techno* Techno::readFromFile(const string filePath) {
string error ("[ERROR] Failed to parse: ");
error += filePath;
throw DTRException(error);
//return NULL;
}
xmlNode* rootElement = xmlDocGetRootElement(doc);
if (rootElement->type == XML_ELEMENT_NODE && xmlStrEqual(rootElement->name, (xmlChar*)"technology")) {
xmlChar* technoNameC = xmlGetProp(rootElement, (xmlChar*)"name");
xmlChar* technoUnitC = xmlGetProp(rootElement, (xmlChar*)"unit");
xmlChar* technoVersC = xmlGetProp(rootElement, (xmlChar*)"version");
if (technoNameC && technoUnitC) {
if (technoNameC && technoUnitC && technoVersC) {
Name name ((const char*)technoNameC);
Name unit ((const char*)technoUnitC);
techno = new Techno(name, unit);
Name vers ((const char*)technoVersC);
techno = new Techno(name, unit, vers);
} else {
throw DTRException("[ERROR] 'technology' node must have 'name' and 'unit' properties.");
throw DTRException("[ERROR] 'technology' node must have 'name', 'unit' and 'version' properties.");
return NULL;
}
@ -215,7 +190,7 @@ bool Techno::writeToFile(string filePath) {
throw DTRException("[ERROR] Cannot writeToFile since no rule is defined!");
}
file << "<technology name=\"" << _name.getString() << "\" unit=\"" << _unit.getString() << "\">" << endl
file << "<technology name=\"" << _name.getString() << "\" unit=\"" << _unit.getString() << "\" version=\"" << _version.getString() << "\">" << endl
<< " <physical_rules>" << endl;
file.setf(ios::left, ios::adjustfield);

View File

@ -22,14 +22,16 @@ class Rule;
class ARule;
class Techno {
public:
Techno(Name name, Name unit);
Techno(Name name, Name unit, Name version);
inline Name getName();
inline Name getUnit();
inline Name getVersion();
inline std::vector<Rule*>& getRules();
inline void setName(Name);
inline void setUnit(Name);
inline void setVersion(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);
@ -43,15 +45,18 @@ class Techno {
Name _name;
Name _unit;
Name _version;
std::vector<Rule*> _rules;
};
inline Name Techno::getName() { return _name; };
inline Name Techno::getUnit() { return _unit; };
inline Name Techno::getVersion() { return _version; };
inline std::vector<Rule*>& Techno::getRules() { return _rules; };
inline void Techno::setName(Name name) { _name = name; };
inline void Techno::setUnit(Name unit) { _unit = unit; };
inline void Techno::setName (Name name) { _name = name; };
inline void Techno::setUnit (Name unit) { _unit = unit; };
inline void Techno::setVersion(Name version) { _version = version; };
} // namespace DTR
#endif