diff --git a/vlsisapd/src/dtr/src/PyTechno.cpp b/vlsisapd/src/dtr/src/PyTechno.cpp index c6fe5d78..e5aeb0b2 100644 --- a/vlsisapd/src/dtr/src/PyTechno.cpp +++ b/vlsisapd/src/dtr/src/PyTechno.cpp @@ -1,3 +1,5 @@ +using namespace std; + #include using namespace boost::python; @@ -17,20 +19,21 @@ BOOST_PYTHON_MODULE(pyDTR) { ; // class DTR::Rule - class_("Rule", init()) + class_("Rule", init()) // accessors - .def("getName" , &Rule::getName ) - .def("getType" , &Rule::getType ) - .def("getValue" , &Rule::getValue ) - .def("getRef" , &Rule::getRef ) - .def("getLayer1", &Rule::getLayer1) - .def("getLayer2", &Rule::getLayer2) + .def("getName" , &Rule::getName ) + .def("getType" , &Rule::getType ) + .def("getValue" , &Rule::getValue ) + .def("getValueAsString", &Rule::getValueAsString) + .def("getRef" , &Rule::getRef ) + .def("getLayer1" , &Rule::getLayer1 ) + .def("getLayer2" , &Rule::getLayer2 ) // modifiers - .def("setType" , &Rule::setType ) + .def("setType" , &Rule::setType ) ; // class DTR::ARule derived from DTR::Rule - class_ >("ARule", init()) + class_ >("ARule", init()) ; // class DTR::Techno @@ -38,11 +41,14 @@ BOOST_PYTHON_MODULE(pyDTR) { .def("readFromFile", &Techno::readFromFile, return_value_policy()) .staticmethod("readFromFile") - .def("getName" , &Techno::getName ) - .def("getUnit" , &Techno::getUnit ) - .def("getValue" , static_cast(&Techno::getValue)) - .def("getValue" , static_cast(&Techno::getValue)) - .def("getValue" , static_cast(&Techno::getValue)) + .def("getName" , &Techno::getName ) + .def("getUnit" , &Techno::getUnit ) + .def("getValue" , static_cast(&Techno::getValue)) + .def("getValue" , static_cast(&Techno::getValue)) + .def("getValue" , static_cast(&Techno::getValue)) + .def("getValueAsString", static_cast(&Techno::getValueAsString)) + .def("getValueAsString", static_cast(&Techno::getValueAsString)) + .def("getValueAsString", static_cast(&Techno::getValueAsString)) ; // DTRException translator diff --git a/vlsisapd/src/dtr/src/Techno.cpp b/vlsisapd/src/dtr/src/Techno.cpp index 5f80d5e7..346de4e1 100644 --- a/vlsisapd/src/dtr/src/Techno.cpp +++ b/vlsisapd/src/dtr/src/Techno.cpp @@ -34,14 +34,14 @@ namespace { namespace DTR { Techno::Techno(Name name, Name unit) : _name(name), _unit(unit) {} -Rule* Techno::addRule (Name name, double value, Name ref, Name layer1, Name layer2) { - Rule* rule = new Rule(name, value, ref, layer1, layer2); +Rule* Techno::addRule (Name name, double value, Name valueStr, Name ref, Name layer1, Name layer2) { + Rule* rule = new Rule(name, value, valueStr, ref, layer1, layer2); _rules.push_back(rule); return rule; } -ARule* Techno::addARule (Name name, double value, Name ref, Name layer1, Name layer2) { - ARule* arule = new ARule(name, value, ref, layer1, layer2); +ARule* Techno::addARule (Name name, double value, Name valueStr, Name ref, Name layer1, Name layer2) { + ARule* arule = new ARule(name, value, valueStr, ref, layer1, layer2); _rules.push_back(arule); return arule; } @@ -86,6 +86,46 @@ double Techno::getValue(Name name, Name layer1, Name layer2) { throw DTRException(error); } +string Techno::getValueAsString(Name name) { + return getValueAsString(name, Name(""), Name("")); +} + +string Techno::getValueAsString(Name name, Name layer) { + return getValueAsString(name, layer, Name("")); +} + +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); +} + Techno* Techno::readFromFile(const string filePath) { LIBXML_TEST_VERSION; Techno* techno = NULL; @@ -136,18 +176,21 @@ Techno* Techno::readFromFile(const string filePath) { Name layer1 ((const char*)layer1C); Name layer2 ((const char*)layer2C); double value = ::getValue(valueC); - rule = techno->addRule(name, value, ref, layer1, layer2); + Name valueStr ((const char*)valueC); + rule = techno->addRule(name, value, valueStr, ref, layer1, layer2); } else if (nameC && layerC && valueC && refC) {// rule with only one layer Name name ((const char*)nameC); Name ref ((const char*)refC); Name layer ((const char*)layerC); double value = ::getValue(valueC); - rule = techno->addRule(name, value, ref, layer); + Name valueStr ((const char*)valueC); + rule = techno->addRule(name, value, valueStr, ref, layer); } else if (nameC && valueC && refC) { // rule without layer Name name ((const char*)nameC); Name ref ((const char*)refC); double value = ::getValue(valueC); - rule = techno->addRule(name, value, ref); + Name valueStr ((const char*)valueC); + rule = techno->addRule(name, value, valueStr, ref); } else { // invalid case throw DTRException("[ERROR] properties of 'rule' node must be ('name', 'value', 'ref') or ('name', 'layer', 'value', 'ref') or ('name', 'layer1', 'layer2', 'value', 'ref')."); return NULL; @@ -168,7 +211,8 @@ Techno* Techno::readFromFile(const string filePath) { Name layer2 ((const char*)layer2C); Name ref ((const char*)refC); double value = ::getValue(valueC); - techno->addARule(name, value, ref, layer1, layer2); + Name valueStr ((const char*)valueC); + techno->addARule(name, value, valueStr, ref, layer1, layer2); } else { throw DTRException("[ERROR] 'arule' node must have 'name', 'layer1', 'layer2', 'value' and 'ref' properties."); return NULL; diff --git a/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h b/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h index 6e365cb8..cf1dedfc 100644 --- a/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h +++ b/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h @@ -10,16 +10,19 @@ #ifndef __DTR_RULES_H__ #define __DTR_RULES_H__ +#include "vlsisapd/dtr/Name.h" + namespace DTR { class Rule { public: - Rule(Name name, double value, Name ref, Name layer1, Name layer2) - : _name(name), _type(Name("")), _value(value), _ref(ref), _layer1(layer1), _layer2(layer2) {}; + Rule(Name name, double value, Name valueStr, Name ref, Name layer1, Name layer2) + : _name(name), _type(Name("")), _value(value), _valueStr(valueStr), _ref(ref), _layer1(layer1), _layer2(layer2) {}; // accessors inline Name getName(); inline Name getType(); inline double getValue(); + inline std::string getValueAsString(); inline Name getRef(); inline Name getLayer1(); virtual inline Name getLayer2(); // add virtual so the Rule object is polymorphic @@ -32,6 +35,7 @@ class Rule { Name _name; Name _type; double _value; + Name _valueStr; Name _ref; Name _layer1; Name _layer2; @@ -39,8 +43,8 @@ class Rule { class ARule : public Rule { public: - ARule(Name name, double value, Name ref, Name layer1, Name layer2) - : Rule(name, value, ref, layer1, layer2) {}; + ARule(Name name, double value, Name valueStr, Name ref, Name layer1, Name layer2) + : Rule(name, value, valueStr, ref, layer1, layer2) {}; }; inline Name Rule::getName() { return _name; }; @@ -49,6 +53,7 @@ inline double Rule::getValue() { return _value; }; inline Name Rule::getRef() { return _ref; }; inline Name Rule::getLayer1() { return _layer1; }; inline Name Rule::getLayer2() { return _layer2; }; +inline std::string Rule::getValueAsString() { return _valueStr.getString(); }; inline void Rule::setType(Name type) { _type = type; }; } // namespace DTR diff --git a/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h b/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h index 8c676807..9808cd6a 100644 --- a/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h +++ b/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h @@ -28,13 +28,17 @@ class Techno { inline Name getUnit(); inline std::vector& getRules(); - 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* addRule (Name name, double value, Name valueStr, Name ref, Name layer1=Name(""), Name layer2=Name("")); + ARule* addARule(Name name, double value, Name valueStr, Name ref, Name layer1 , Name layer2); double getValue(Name name); double getValue(Name name, Name layer); double getValue(Name name, Name layer1, Name layer2); + std::string getValueAsString(Name name); + std::string getValueAsString(Name name, Name layer); + std::string getValueAsString(Name name, Name layer1, Name layer2); + bool writeToFile(std::string filePath); static Techno* readFromFile(const std::string filePath);