[C++-sig] How to use functionality of list.
Actually I am able create wrapper code for list . All the functions of list are exposed. But when I try to compile it (try to create shared library) it showing below error --- testModule.cpp:11: error: _Alloc was not declared in this scope testModule.cpp:18: error: _Tp was not declared in this scope testModule.cpp:18: error: _Alloc was not declared in this scope testModule.cpp: In function void init_module_testModule(): testModule.cpp:110: error: _Alloc was not declared in this scope testModule.cpp:113: error: _Tp was not declared in this scope /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/list.tcc: In member function âvoid std::list<_Tp, _Alloc>::merge(std::list<_Tp, _Alloc>&) [with _Tp = A, _Alloc = std::allocator ]â: testModule.cpp:368: instantiated from here /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/list.tcc:222: error: no match for âoperator<â in â__first2.std::_List_iterator<_Tp>::operator* [with _Tp = A]() < __first1.std::_List_iterator<_Tp>::operator* [with _Tp = A]()â /usr/lib/gcc/x86_64-redhat-linux/4.1.2/../../../../include/c++/4.1.2/bits/list.tcc: In member function âvoid std::list<_Tp, _Alloc>::remove(const _Tp&) [with _Tp = A, _Alloc = std::allocator ]â: --- I think if I can somewhere declare _Alloc and _Tp I will be able to use it (list) correctly. Please let me know the possible solution Below are the code (and one file is attahced) that is used. cpp code : listP.cpp === #include #include class A { public: A(int num):num(num) { } private: int num; }; class Alist : public std::list { public: static void a() { std::cout << "check" << std::endl; } }; Alist getDummyAlist() { Alist aList; A a1(5); A a2(6); aList.push_back(a1); aList.push_back(a2); return aList; }; python file for generating wrapper code : afile.py import os from pyplusplus import module_builder from pyplusplus.module_builder import call_policies from pyplusplus import code_creators mb=module_builder.module_builder_t(["./listP.cpp"], ) classA = mb.class_('list') classA.include() for className in mb.classes(): print "className : %s"%className http://old.nabble.com/file/p28459066/testModule.cpp testModule.cpp mb.build_code_creator( module_name = 'testModule') mb.write_module('./testModule.cpp') Generated wrapper code : testModule.cpp === file testModule.cpp is uploaded (attached) on this page only. -- View this message in context: http://old.nabble.com/How-to-use-functionality-of-list.-tp28459066p28459066.html Sent from the Python - c++-sig mailing list archive at Nabble.com. ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] How to use functionality of list.
On Wed, May 5, 2010 at 1:19 PM, vishal bayskar wrote: > > Actually I am able create wrapper code for list . All the functions of list > are exposed. > But when I try to compile it (try to create shared library) it showing below > error > ... > mb=module_builder.module_builder_t(["./listP.cpp"], > ) > > classA = mb.class_('list') > classA.include() There is no need to expose std containers directly. Instead, expose declarations that are using them and Py++ will do the rest. mb.free_function( 'getDummyAlist' ).include() This topic is covered in the following document: http://language-binding.net/pyplusplus/documentation/containers.html HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] How to use functionality of list.
>There is no need to expose std containers directly. Instead, expose >declarations that are using them and Py++ will do the rest. >mb.free_function( 'getDummyAlist' ).include() >This topic is covered in the following document: >http://language-binding.net/pyplusplus/documentation/containers.html Yes I tried like as you suggested. but I am not able to use the functionality of list from python. Like suppose I need to use push_back etc from python. >>> import testModule >>> alistobj = testModule.Alist() >>> aobj=testModule.A(5) >>> alistobj.push_back(aobj) Traceback (most recent call last): File "", line 1, in ? AttributeError: 'Alist' object has no attribute 'push_back' >>> >>> dummyList =testModule.getDummyAlist() >>> dummyList.push_back(aobj) Traceback (most recent call last): File "", line 1, in ? AttributeError: 'Alist' object has no attribute 'push_back' Generated wrapper code : testModule.cpp === // This file has been generated by Py++. #include "boost/python.hpp" #include "listP.cpp" namespace bp = boost::python; BOOST_PYTHON_MODULE(testModule){ { //::A typedef bp::class_< A > A_exposer_t; A_exposer_t A_exposer = A_exposer_t( "A", bp::init< int >(( bp::arg("num") )) ); bp::scope A_scope( A_exposer ); bp::implicitly_convertible< int, A >(); } bp::class_< Alist >( "Alist" ) .def( "a" , (void (*)( ))( &::Alist::a ) ) .staticmethod( "a" ); { //::getDummyAlist typedef ::Alist ( *getDummyAlist_function_type )( ); bp::def( "getDummyAlist" , getDummyAlist_function_type( &::getDummyAlist ) ); } { //::main typedef int ( *main_function_type )( ); bp::def( "main" , main_function_type( &::main ) ); } } -- View this message in context: http://old.nabble.com/How-to-use-functionality-of-list.-tp28459066p28459555.html Sent from the Python - c++-sig mailing list archive at Nabble.com. ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] How to use functionality of list.
On Wed, May 5, 2010 at 2:20 PM, vishal bayskar wrote: > >>There is no need to expose std containers directly. Instead, expose >>declarations that are using them and Py++ will do the rest. > >>mb.free_function( 'getDummyAlist' ).include() > >>This topic is covered in the following document: >>http://language-binding.net/pyplusplus/documentation/containers.html > > > Yes I tried like as you suggested. > but I am not able to use the functionality of list from python. > Like suppose I need to use push_back etc from python. Both indexing suites provides interface very similar to Python containers. So the user will not have to learn new API, but if you insists, you can rename/introduce new method from Python AList.push_back = AList.append -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig
Re: [C++-sig] How to use functionality of list.
>Both indexing suites provides interface very similar to Python >containers. So the user will not have to learn new API, but if you >insists, you can rename/introduce new method from Python >AList.push_back = AList.append But object Alist is not treated as a list and giving the below error. >>> dummyList =testModule.getDummyAlist() >>> >>> print dummyList >>> >>> aobj=testModule.A(5) >>> >>> print aobj >>> >>> dummyList.append(aobj) Traceback (most recent call last): File "", line 1, in ? AttributeError: 'Alist' object has no attribute 'append' -- View this message in context: http://old.nabble.com/How-to-use-functionality-of-list.-tp28459066p28460323.html Sent from the Python - c++-sig mailing list archive at Nabble.com. ___ Cplusplus-sig mailing list Cplusplus-sig@python.org http://mail.python.org/mailman/listinfo/cplusplus-sig