Hello everybody, I am actually writing an interface to python for an existing C++ library using Boost. This library has a C++ singleton class. This class has only one constructor (with arguments) which is "protected" because it's a singleton. I am not able to build a Boost interface to this class because the compiler complains that the constructor I have given to Boost in the class_xxx constructor argument is not public (which is true) ! Therefore, my question is simple : How is it possible to interface such a class with only one constructor which is protected and a static method to create/access the object ? Thank's very much for your answer. Sincerely Emmanuel Taurel (etaurel@cells.es) PS : By the way, is there a searchable archive of this mailing list ?
On 10/24/05, Emmanuel Taurel <etaurel@cells.es> wrote:
Therefore, my question is simple : How is it possible to interface such a class with only one constructor which is protected and a static method to create/access the object ? Look for no_init here http://boost.org/libs/python/doc/v2/class.html
Better solution is to try boost.python code generator Pyste ( an official one ) or pyplusplus http://pygccxml.sourceforge.net/pyplusplus/pyplusplus.html
Thank's very much for your answer. Sincerely
Emmanuel Taurel (etaurel@cells.es)
PS : By the way, is there a searchable archive of this mailing list ?
yes: http://aspn.activestate.com/ASPN/Mail/Browse/Threaded/cpp-sig Roman Yakovenko
Hi,
I am actually writing an interface to python for an existing C++ library using Boost. This library has a C++ singleton class. This class has only one
constructor (with arguments) which is “protected” because it’s a singleton.
I am not able to build a Boost interface to this class because the compiler complains that the constructor I have given to Boost
in the class_xxx constructor argument is not public (which is true) !
Therefore, my question is simple : How is it possible to interface such a class with only one constructor which is protected and a static method
to create/access the object ?
Don't export the constructor, use no_init. Declare the static method which returns the only instance as staticmethod. Example code, not tested: class_<MySingleton, boost::noncopyable>("MySingleton", no_init) .def("get", &MySingleton::get, return_internal_reference<>()) .staticmethod("get") ; For more information see tutorial an reference: http://www.boost.org/libs/python/doc/index.html For code examples look at the unit tests or other projects using boost:python. bye by Wolfgang
Yo may find usefull information about Singletin here: http://sourcemaking.com/design_patterns/singleton -- View this message in context: http://www.nabble.com/-C%2B%2B-sig--C%2B%2B-singleton-tf442256.html#a1350806... Sent from the Python - c++-sig mailing list archive at Nabble.com.
participants (4)
-
Emmanuel Taurel -
neoguru -
Roman Yakovenko -
Wolfgang Langner