From ba80733d5ef924f732077adc22cb8e34da2c33d8 Mon Sep 17 00:00:00 2001 From: Damien Dupuis Date: Tue, 15 Jun 2010 11:29:15 +0000 Subject: [PATCH] Rule & ARule constructors do not need 'Name valueStr' anymore. It is automatically generated based on 'double value' argument Python binding is up to date --- vlsisapd/src/dtr/src/PyTechno.cpp | 33 +++++++++++++------- vlsisapd/src/dtr/src/Techno.cpp | 36 +++++----------------- vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h | 18 ++++++++--- vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h | 13 +++----- 4 files changed, 48 insertions(+), 52 deletions(-) diff --git a/vlsisapd/src/dtr/src/PyTechno.cpp b/vlsisapd/src/dtr/src/PyTechno.cpp index e5aeb0b2..32eb040c 100644 --- a/vlsisapd/src/dtr/src/PyTechno.cpp +++ b/vlsisapd/src/dtr/src/PyTechno.cpp @@ -12,6 +12,13 @@ void translator(DTRException const& e) { PyErr_SetString(PyExc_UserWarning, e.what()); } + +// specify that Techno::getValue & Techno::getValueAsString methods have optional arguments +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 +BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(addRule_overloads, addRule, 3, 5); + BOOST_PYTHON_MODULE(pyDTR) { // class DTR::Name class_("Name", init()) @@ -19,7 +26,7 @@ BOOST_PYTHON_MODULE(pyDTR) { ; // class DTR::Rule - class_("Rule", init()) + class_("Rule", init()) // accessors .def("getName" , &Rule::getName ) .def("getType" , &Rule::getType ) @@ -28,27 +35,31 @@ BOOST_PYTHON_MODULE(pyDTR) { .def("getRef" , &Rule::getRef ) .def("getLayer1" , &Rule::getLayer1 ) .def("getLayer2" , &Rule::getLayer2 ) + // modifiers .def("setType" , &Rule::setType ) ; // class DTR::ARule derived from DTR::Rule - class_ >("ARule", init()) + class_ >("ARule", init()) ; // class DTR::Techno class_("Techno", init()) + // accessors + .def("getName" , &Techno::getName) + .def("getUnit" , &Techno::getUnit) + .def("getValue" , &Techno::getValue, getValue_overloads()) + .def("getValueAsString", &Techno::getValueAsString, getValueAsString_overloads()) + + // modifiers + .def("addRule" , &Techno::addRule , addRule_overloads()[return_value_policy()]) + .def("addARule" , &Techno::addARule, return_value_policy()) + + // others .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("getValueAsString", static_cast(&Techno::getValueAsString)) - .def("getValueAsString", static_cast(&Techno::getValueAsString)) - .def("getValueAsString", static_cast(&Techno::getValueAsString)) + .def("writeToFile" , &Techno::writeToFile) ; // DTRException translator diff --git a/vlsisapd/src/dtr/src/Techno.cpp b/vlsisapd/src/dtr/src/Techno.cpp index 346de4e1..ffba92ce 100644 --- a/vlsisapd/src/dtr/src/Techno.cpp +++ b/vlsisapd/src/dtr/src/Techno.cpp @@ -34,26 +34,18 @@ namespace { namespace DTR { Techno::Techno(Name name, Name unit) : _name(name), _unit(unit) {} -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); +Rule* Techno::addRule (Name name, double value, Name ref, Name layer1, Name layer2) { + Rule* rule = new Rule(name, value, ref, layer1, layer2); _rules.push_back(rule); return rule; } -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); +ARule* Techno::addARule (Name name, double value, Name ref, Name layer1, Name layer2) { + ARule* arule = new ARule(name, value, ref, layer1, layer2); _rules.push_back(arule); return arule; } -double Techno::getValue(Name name) { - return getValue(name, Name(""), Name("")); -} - -double Techno::getValue(Name name, Name layer) { - return getValue(name, layer, Name("")); -} - double Techno::getValue(Name name, Name layer1, Name layer2) { bool testL1 = (layer1 == Name("")) ? false : true; bool testL2 = (layer2 == Name("")) ? false : true; @@ -86,14 +78,6 @@ 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; @@ -176,21 +160,18 @@ Techno* Techno::readFromFile(const string filePath) { Name layer1 ((const char*)layer1C); Name layer2 ((const char*)layer2C); double value = ::getValue(valueC); - Name valueStr ((const char*)valueC); - rule = techno->addRule(name, value, valueStr, ref, layer1, layer2); + rule = techno->addRule(name, value, 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); - Name valueStr ((const char*)valueC); - rule = techno->addRule(name, value, valueStr, ref, layer); + rule = techno->addRule(name, value, ref, layer); } else if (nameC && valueC && refC) { // rule without layer Name name ((const char*)nameC); Name ref ((const char*)refC); double value = ::getValue(valueC); - Name valueStr ((const char*)valueC); - rule = techno->addRule(name, value, valueStr, ref); + rule = techno->addRule(name, value, 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; @@ -211,8 +192,7 @@ Techno* Techno::readFromFile(const string filePath) { Name layer2 ((const char*)layer2C); Name ref ((const char*)refC); double value = ::getValue(valueC); - Name valueStr ((const char*)valueC); - techno->addARule(name, value, valueStr, ref, layer1, layer2); + techno->addARule(name, value, 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 cf1dedfc..659b8db1 100644 --- a/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h +++ b/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h @@ -10,13 +10,23 @@ #ifndef __DTR_RULES_H__ #define __DTR_RULES_H__ +#include +#include + #include "vlsisapd/dtr/Name.h" namespace DTR { +template +std::string to_string(T const& value) { + std::stringstream sstr; + sstr << value; + return sstr.str(); +} + class Rule { public: - 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) {}; + Rule(Name name, double value, Name ref, Name layer1, Name layer2) + : _name(name), _type(Name("")), _value(value), _valueStr(to_string(value)), _ref(ref), _layer1(layer1), _layer2(layer2) {}; // accessors inline Name getName(); @@ -43,8 +53,8 @@ class Rule { class ARule : public Rule { public: - ARule(Name name, double value, Name valueStr, Name ref, Name layer1, Name layer2) - : Rule(name, value, valueStr, ref, layer1, layer2) {}; + ARule(Name name, double value, Name ref, Name layer1, Name layer2) + : Rule(name, value, ref, layer1, layer2) {}; }; inline Name Rule::getName() { return _name; }; diff --git a/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h b/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h index 9808cd6a..e3edb351 100644 --- a/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h +++ b/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h @@ -28,16 +28,11 @@ class Techno { inline Name getUnit(); inline std::vector& getRules(); - 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); + 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); - 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); + double getValue(Name name, Name layer1=Name(""), Name layer2=Name("")); + std::string getValueAsString(Name name, Name layer1=Name(""), Name layer2=Name("")); bool writeToFile(std::string filePath); static Techno* readFromFile(const std::string filePath);