From b0b3d50c3ef42bf08c8e928b17bb27ca2f627207 Mon Sep 17 00:00:00 2001 From: Damien Dupuis Date: Wed, 7 Jul 2010 11:13:00 +0000 Subject: [PATCH] Cleanly pass 'copy_const_reference' for getValueAsString methods (hooping it will solve a big bug in python binding. DO NOT SUPPRESS TARGET_LINK_LIBRARIES in CMakeLists.txt for ADD_LIBRARY since it is mandotory under man osx (at least under version 10.6.3) --- vlsisapd/src/dtr/src/CMakeLists.txt | 22 +++++++++++++--------- vlsisapd/src/dtr/src/PyDtr.cpp | 6 +++--- vlsisapd/src/dtr/src/Techno.cpp | 2 +- vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h | 4 ++-- vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h | 2 +- 5 files changed, 20 insertions(+), 16 deletions(-) diff --git a/vlsisapd/src/dtr/src/CMakeLists.txt b/vlsisapd/src/dtr/src/CMakeLists.txt index e7d81fa3..783e649b 100644 --- a/vlsisapd/src/dtr/src/CMakeLists.txt +++ b/vlsisapd/src/dtr/src/CMakeLists.txt @@ -3,24 +3,28 @@ INCLUDE_DIRECTORIES(${VLSISAPD_SOURCE_DIR}/src/dtr/src ${LIBXML2_INCLUDE_DIR} ${ SET ( hpps vlsisapd/dtr/Techno.h vlsisapd/dtr/Rules.h vlsisapd/dtr/Name.h - vlsisapd/dtr/DTRException.h ) + vlsisapd/dtr/DTRException.h + ) SET ( cpps Techno.cpp - Name.cpp ) + Name.cpp + ) -SET ( pycpps PyDtr.cpp ${cpps}) +SET ( pycpps PyDtr.cpp ${cpps} + ) ADD_LIBRARY(dtr ${cpps}) TARGET_LINK_LIBRARIES(dtr ${LIBXML2_LIBRARIES}) INSTALL(TARGETS dtr DESTINATION lib${LIB_SUFFIX}) IF (Boost_FOUND) - ADD_LIBRARY(pyDTR MODULE ${pycpps}) -SET_TARGET_PROPERTIES(pyDTR PROPERTIES - COMPILE_FLAGS "${COMPILE_FLAGS} -D__PYTHON_MODULE__=1" - PREFIX "" - ) -INSTALL(TARGETS pyDTR DESTINATION ${PYTHON_SITE_PACKAGES}) + ADD_LIBRARY(pyDTR MODULE ${pycpps}) + SET_TARGET_PROPERTIES(pyDTR PROPERTIES + COMPILE_FLAGS "${COMPILE_FLAGS} -D__PYTHON_MODULE__=1" + PREFIX "" + ) + TARGET_LINK_LIBRARIES(pyDTR dtr ${LIBXML2_LIBRARIES} ${Boost_LIBRARIES} ${PYTHON_LIBRARIES}) + INSTALL(TARGETS pyDTR DESTINATION ${PYTHON_SITE_PACKAGES}) ENDIF(Boost_FOUND) INSTALL(FILES ${hpps} DESTINATION include/vlsisapd/dtr) diff --git a/vlsisapd/src/dtr/src/PyDtr.cpp b/vlsisapd/src/dtr/src/PyDtr.cpp index 36019e0f..0e4e02ac 100644 --- a/vlsisapd/src/dtr/src/PyDtr.cpp +++ b/vlsisapd/src/dtr/src/PyDtr.cpp @@ -20,7 +20,7 @@ BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(getValueAsString_overloads, getValueAsStr // specify that Techno::addRule method has optional arguments BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(addRule_overloads, addRule, 3, 5); -BOOST_PYTHON_MODULE(pyDTR) { +BOOST_PYTHON_MODULE(DTR) { // class DTR::Name class_("Name", init()) .def("getString", &Name::getString, return_value_policy()) // return_value_policy because this method return a refenrce on string @@ -37,7 +37,7 @@ BOOST_PYTHON_MODULE(pyDTR) { .def("getName" , &Rule::getName ) .def("getType" , &Rule::getType ) .def("getValue" , &Rule::getValue ) - .def("getValueAsString", &Rule::getValueAsString) + .def("getValueAsString", &Rule::getValueAsString, return_value_policy()) .def("getRef" , &Rule::getRef ) .def("getLayer1" , &Rule::getLayer1 ) .def("getLayer2" , &Rule::getLayer2 ) @@ -57,7 +57,7 @@ BOOST_PYTHON_MODULE(pyDTR) { .def("getUnit" , &Techno::getUnit) .def("getRule" , &Techno::getRule , getRule_overloads()[return_value_policy()]) .def("getValue" , &Techno::getValue , getValue_overloads()) - .def("getValueAsString", &Techno::getValueAsString, getValueAsString_overloads()) + .def("getValueAsString", &Techno::getValueAsString, getValueAsString_overloads()[return_value_policy()]) // modifiers .def("addRule" , &Techno::addRule , addRule_overloads()[return_value_policy()]) diff --git a/vlsisapd/src/dtr/src/Techno.cpp b/vlsisapd/src/dtr/src/Techno.cpp index 73b8d9ca..a821db41 100644 --- a/vlsisapd/src/dtr/src/Techno.cpp +++ b/vlsisapd/src/dtr/src/Techno.cpp @@ -82,7 +82,7 @@ double Techno::getValue(Name name, Name layer1, Name layer2) { return getRule(name, layer1, layer2)->getValue(); } -string Techno::getValueAsString(Name name, Name layer1, Name layer2) { +const string& Techno::getValueAsString(Name name, Name layer1, Name layer2) { return getRule(name, layer1, layer2)->getValueAsString(); } diff --git a/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h b/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h index 659b8db1..0ad13c88 100644 --- a/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h +++ b/vlsisapd/src/dtr/src/vlsisapd/dtr/Rules.h @@ -32,7 +32,7 @@ class Rule { inline Name getName(); inline Name getType(); inline double getValue(); - inline std::string getValueAsString(); + inline const std::string& getValueAsString(); inline Name getRef(); inline Name getLayer1(); virtual inline Name getLayer2(); // add virtual so the Rule object is polymorphic @@ -63,7 +63,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 const 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 e5fd3ecd..a194d701 100644 --- a/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h +++ b/vlsisapd/src/dtr/src/vlsisapd/dtr/Techno.h @@ -33,7 +33,7 @@ class Techno { Rule* getRule(Name name, Name layer1=Name(""), Name layer2=Name("")); double getValue(Name name, Name layer1=Name(""), Name layer2=Name("")); - std::string getValueAsString(Name name, Name layer1=Name(""), Name layer2=Name("")); + const std::string& getValueAsString(Name name, Name layer1=Name(""), Name layer2=Name("")); bool writeToFile(std::string filePath); static Techno* readFromFile(const std::string filePath);