[C++-sig] accessing nontrivial types

Matthew Scouten (TT) Matthew.Scouten at tradingtechnologies.com
Thu Feb 4 21:25:44 CET 2010

class_< std::list<Thingy> >("ListOfThingys")
            .def(vector_indexing_suite< std::list<Thingy> >() )
This is really too complex to show quickly. Just read the c++ header and do the same thing to list that you did to myclass. 

bp::list getter (const MyClass& self) 
	bp::list L
	//move the values in self.ilist to L
	return L
void setter (const MyClass& self, bp::list L) 
	//move the values in L to self.ilist

        .def_readwrite("i", &Myclass::i)
        .def_readwrite("f", &Myclass::f)
        .add_property ("ilist", &getter, &setter)

That's the gist of it. I am not sure if 1 works and 2 will be difficult, so I recommend 3

-----Original Message-----
From: cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org [mailto:cplusplus-sig-bounces+matthew.scouten=tradingtechnologies.com at python.org] On Behalf Of Anders Wallin
Sent: Thursday, February 04, 2010 2:12 PM
To: Development of Python/C++ integration
Subject: Re: [C++-sig] accessing nontrivial types

are there examples of how to do this somewhere?
for something like list<int>, MyClass   and list<MyClass>


>        1) the vector_indexing_suite might work for a std::list. Give it
> a try.
>        2) Manually expose the function the you care about.
>        3) have a couple of get/set functions as a property that copies
> your std::list to and from a bp::list.
Cplusplus-sig mailing list
Cplusplus-sig at python.org

More information about the Cplusplus-sig mailing list