ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> cpp-sig
cpp-sig
[C++-sig] Re: a pointer question
by Nikolay Mladenov other posts by this author
Jun 27 2003 2:13PM messages near this date
[C++-sig] a pointer question | Re: [C++-sig] Re: Interest in luabind
You have to write
   class_<A>  ("A",init<int>())
     .add_property("d",&A::getd)
     .add_property("pb",make_getter(&A::pb,
return_internal_reference<1> ()));

check the docs for make_getter. 

Jaleco wrote:
>  
>  Dear all
>  
>          I am trying use boost.python to export freetype library to python.
>  But I encounter pointer problem.boost  don't know pointer.
>  How do I export class pointer to python ?
>  
>  / Includes
>  ====================================================================
>  #include ?boost/python.hpp?
>  
>  class  B
>  {
>    public :
>     int d ;
>  
>  };
>  class A
>  {
>    public :
>      A(int d) { pb = new(B);pb-?d = d ;} ;
>      int getd(void) { return pb-?d;} ;
>      B *pb ;
>  };
>  
>  // Using
>  =======================================================================
>  using namespace boost::python;
>  
>  // Module
>  ======================================================================
>  BOOST_PYTHON_MODULE(ft2)
>  {
>    class_?A? ("A",init?int?())
>      .add_property("d",?A::getd)
>      .def_readonly("pb",?A::pb);
>    class_?B? ("B")
>      .def_readwrite("d",?B::d)  ;
>  
>  }
>  
>  C:\source\boost_1_30_0\libs\python\ft2?python
>  Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32
>  Type "help", "copyright", "credits" or "license" for more information.
>  ??? import ft2
>  ??? a = ft2.A(1)
>  ??? pb = a.pb
>  Traceback (most recent call last):
>    File "?stdin?", line 1, in ?
>  TypeError: No to_python (by-value) converter found for C++ type: class B *
>  ???
>  
>  another question is , I try to add
>  BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(B) ;  to
>  my source source code, This problem is gone.
>  But the answer is wrong .................
>  
>  // Includes
>  ====================================================================
>  #include ?boost/python.hpp?
>  
>  class  B
>  {
>    public :
>     int d ;
>  
>  };
>  class A
>  {
>    public :
>      A(int d) { pb = new(B);pb-?d = d ;} ;
>      int getd(void) { return pb-?d;} ;
>      B *pb ;
>  };
>  BOOST_PYTHON_OPAQUE_SPECIALIZED_TYPE_ID(B) ;
>  // Using
>  =======================================================================
>  using namespace boost::python;
>  
>  // Module
>  ======================================================================
>  BOOST_PYTHON_MODULE(ft2)
>  {
>    class_?A? ("A",init?int?())
>      .add_property("d",?A::getd)
>      .def_readonly("pb",?A::pb);
>    class_?B? ("B")
>      .def_readwrite("d",?B::d)  ;
>  
>  }
>  
>  Python 2.2.3 (#42, May 30 2003, 18:12:08) [MSC 32 bit (Intel)] on win32
>  Type "help", "copyright", "credits" or "license" for more information.
>  ??? import ft2
>  ??? a = ft2.A(1)
>  ??? pb=a.pb
>  ??? pb
>  ?ft2.B object at 0x009082C8?
>  ??? pb.d
>  10445536
>  ??? a.d
>  1
>  ???


_______________________________________________
C++-sig mailing list
C++-sig@[...].org
http://mail.python.org/mailman/listinfo/c++-sig
Thread:
Jaleco
Nikolay Mladenov

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved