Thread: [pygccxml-development] Iteration over py++ generated maps and vectors
Brought to you by:
mbaas,
roman_yakovenko
From: Vincent F. <vin...@gm...> - 2008-06-18 15:50:25
|
I've generated most of what I needed. I'm currently trying to recover all the informations stocked in my different objects. I'm initializing an object with childrens (nodes in this example). I've said myself the best way should be using iterators over such lists (vector, maps etc). I tried the following example : nodes = self.internalDb.getNodes() iterator = nodes.__iter__() for it in iterator: print it It prints me a list of lines like that : (52208839, <pyferespost.NastranNode object at 0xb7e01dec>) I'd like to access to the inner object (in this case a NastranNode) but don't really know how... Thanks in advance! Vincent FERRIES |
From: Roman Y. <rom...@gm...> - 2008-06-18 17:55:09
|
On Wed, Jun 18, 2008 at 6:50 PM, Vincent Ferries <vin...@gm...> wrote: > I've generated most of what I needed. > I'm currently trying to recover all the informations stocked in my > different objects. > > I'm initializing an object with childrens (nodes in this example). > > I've said myself the best way should be using iterators over such > lists (vector, maps etc). > I tried the following example : > > > nodes = self.internalDb.getNodes() > iterator = nodes.__iter__() > for it in iterator: > print it > > > > It prints me a list of lines like that : > > (52208839, <pyferespost.NastranNode object at 0xb7e01dec>) > > > > I'd like to access to the inner object (in this case a NastranNode) > but don't really know how... Sorry, but I don't understand you. Small and complete example is needed. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Vincent F. <vin...@gm...> - 2008-06-19 07:16:25
|
The method NastranDatabase.getNodes() has the following signature in the C++ code : std::map<int,node> & getNodes(void) ; In my python code, I'm able to call it and get the corresponding map_indexing_suite_map_less__int_comma__postLib_scope_nastran_scope_node__grate_ object. When I iterate over this instance, I get the example listed above. But don't know how to access corresponding int and NastranNode for every element in the list... Hope this is better explained. Thanks again. 2008/6/18, Roman Yakovenko <rom...@gm...>: > On Wed, Jun 18, 2008 at 6:50 PM, Vincent Ferries > <vin...@gm...> wrote: >> I've generated most of what I needed. >> I'm currently trying to recover all the informations stocked in my >> different objects. >> >> I'm initializing an object with childrens (nodes in this example). >> >> I've said myself the best way should be using iterators over such >> lists (vector, maps etc). >> I tried the following example : >> >> >> nodes = self.internalDb.getNodes() >> iterator = nodes.__iter__() >> for it in iterator: >> print it >> >> >> >> It prints me a list of lines like that : >> >> (52208839, <pyferespost.NastranNode object at 0xb7e01dec>) >> >> >> >> I'd like to access to the inner object (in this case a NastranNode) >> but don't really know how... > > Sorry, but I don't understand you. Small and complete example is needed. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > |
From: Roman Y. <rom...@gm...> - 2008-06-19 07:40:31
|
On Thu, Jun 19, 2008 at 10:16 AM, Vincent Ferries <vin...@gm...> wrote: > The method NastranDatabase.getNodes() has the following signature in > the C++ code : std::map<int,node> & getNodes(void) ; > > In my python code, I'm able to call it and get the corresponding > map_indexing_suite_map_less__int_comma__postLib_scope_nastran_scope_node__grate_ > object. > When I iterate over this instance, I get the example listed above. > But don't know how to access corresponding int and NastranNode for > every element in the list... > > Hope this is better explained. A little bit. Iterating over std::map class is same as iterating over dictionary: you get tuple of <key, value> if you are interested in values only, you can use "values" function. Take a look on Py++ unittests. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Vincent F. <vin...@gm...> - 2008-06-19 08:00:13
|
For dictionaries you can directly use structures like : for (key, values) in dict: and the key/values elements will be matching key and list of values. But I'm not able to access them in this way. Using reflection to list accessibles methods on the map I get : __call__ x.__call__(...) <==> x(...) __class__ instancemethod(function, instance, class) Create an instance method object. __cmp__ x.__cmp__(y) <==> cmp(x,y) __delattr__ x.__delattr__('name') <==> del x.name __get__ descr.__get__(obj[, type]) -> value __getattribute__ x.__getattribute__('name') <==> x.name __hash__ x.__hash__() <==> hash(x) __init__ x.__init__(...) initializes x; see x.__class__.__doc__ for signature __new__ T.__new__(S, ...) -> a new object with type S, a subtype of T __reduce__ helper for pickle __reduce_ex__ helper for pickle __repr__ x.__repr__() <==> repr(x) __setattr__ x.__setattr__('name', value) <==> x.name = value __str__ x.__str__() <==> str(x) im_class None im_func None "values" function don't appear... 2008/6/19, Roman Yakovenko <rom...@gm...>: > On Thu, Jun 19, 2008 at 10:16 AM, Vincent Ferries > <vin...@gm...> wrote: >> The method NastranDatabase.getNodes() has the following signature in >> the C++ code : std::map<int,node> & getNodes(void) ; >> >> In my python code, I'm able to call it and get the corresponding >> map_indexing_suite_map_less__int_comma__postLib_scope_nastran_scope_node__grate_ >> object. >> When I iterate over this instance, I get the example listed above. >> But don't know how to access corresponding int and NastranNode for >> every element in the list... >> >> Hope this is better explained. > > A little bit. > > Iterating over std::map class is same as iterating over dictionary: > you get tuple of <key, value> > if you are interested in values only, you can use "values" function. > > Take a look on Py++ unittests. > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > |
From: Roman Y. <rom...@gm...> - 2008-06-19 08:06:52
|
On Thu, Jun 19, 2008 at 11:00 AM, Vincent Ferries <vin...@gm...> wrote: > For dictionaries you can directly use structures like : > > for (key, values) in dict: > > and the key/values elements will be matching key and list of values. > > > But I'm not able to access them in this way. > > > Using reflection to list accessibles methods on the map I get : > > __call__ x.__call__(...) <==> x(...) > __class__ instancemethod(function, instance, class) Create an > instance method object. > __cmp__ x.__cmp__(y) <==> cmp(x,y) > __delattr__ x.__delattr__('name') <==> del x.name > __get__ descr.__get__(obj[, type]) -> value > __getattribute__ x.__getattribute__('name') <==> x.name > __hash__ x.__hash__() <==> hash(x) > __init__ x.__init__(...) initializes x; see x.__class__.__doc__ for signature > __new__ T.__new__(S, ...) -> a new object with type S, a subtype of T > __reduce__ helper for pickle > __reduce_ex__ helper for pickle > __repr__ x.__repr__() <==> repr(x) > __setattr__ x.__setattr__('name', value) <==> x.name = value > __str__ x.__str__() <==> str(x) > im_class None > im_func None > > > "values" function don't appear... Please create small test case that reproduce the problem. According to my unit tests * http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/indexing_suites_tester.py?revision=414&view=markup * http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/indexing_suites2_tester.py?revision=1081&view=markup the functionality works just fine. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Vincent F. <vin...@gm...> - 2008-06-19 08:28:21
|
I read this unit tests before, but don't seem to get the same type of vectors/maps. I don't really know what I am missing, maybe a wrong call policy? I set the call policy of getters on those maps to call_policies.reference_existing_object. The module creator generate me a list of vector and map wrappers with the methods I just listed above. I can't obviously access it like a list or a dictionary. I'm using base implementation of indexing_suite (not indexing_suite_v2, I have problems to compile while using it). If I can access different children elements it'll be fine for me, no real need of indexing_suite_v2. 2008/6/19, Roman Yakovenko <rom...@gm...>: > On Thu, Jun 19, 2008 at 11:00 AM, Vincent Ferries > <vin...@gm...> wrote: >> For dictionaries you can directly use structures like : >> >> for (key, values) in dict: >> >> and the key/values elements will be matching key and list of values. >> >> >> But I'm not able to access them in this way. >> >> >> Using reflection to list accessibles methods on the map I get : >> >> __call__ x.__call__(...) <==> x(...) >> __class__ instancemethod(function, instance, class) Create an >> instance method object. >> __cmp__ x.__cmp__(y) <==> cmp(x,y) >> __delattr__ x.__delattr__('name') <==> del x.name >> __get__ descr.__get__(obj[, type]) -> value >> __getattribute__ x.__getattribute__('name') <==> x.name >> __hash__ x.__hash__() <==> hash(x) >> __init__ x.__init__(...) initializes x; see x.__class__.__doc__ for >> signature >> __new__ T.__new__(S, ...) -> a new object with type S, a subtype of T >> __reduce__ helper for pickle >> __reduce_ex__ helper for pickle >> __repr__ x.__repr__() <==> repr(x) >> __setattr__ x.__setattr__('name', value) <==> x.name = value >> __str__ x.__str__() <==> str(x) >> im_class None >> im_func None >> >> >> "values" function don't appear... > > Please create small test case that reproduce the problem. > > According to my unit tests > * > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/indexing_suites_tester.py?revision=414&view=markup > * > http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/indexing_suites2_tester.py?revision=1081&view=markup > > the functionality works just fine. > > > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > |
From: Vincent F. <vin...@gm...> - 2008-06-19 09:33:10
|
In fact, it allways produce me classes like pyferespost.map_less__int_comma__postLib_scope_nastran_scope_property__grate_, I understand the reason but, is it a way to use python lists, sets and dictionnaries instead of generated ones which seams to lack some functionalities? Or is it a way to implement these functionalities? 2008/6/19, Vincent Ferries <vin...@gm...>: > I read this unit tests before, but don't seem to get the same type of > vectors/maps. > > I don't really know what I am missing, maybe a wrong call policy? > I set the call policy of getters on those maps to > call_policies.reference_existing_object. > The module creator generate me a list of vector and map wrappers with > the methods I just listed above. I can't obviously access it like a > list or a dictionary. > > I'm using base implementation of indexing_suite (not > indexing_suite_v2, I have problems to compile while using it). If I > can access different children elements it'll be fine for me, no real > need of indexing_suite_v2. > > 2008/6/19, Roman Yakovenko <rom...@gm...>: >> On Thu, Jun 19, 2008 at 11:00 AM, Vincent Ferries >> <vin...@gm...> wrote: >>> For dictionaries you can directly use structures like : >>> >>> for (key, values) in dict: >>> >>> and the key/values elements will be matching key and list of values. >>> >>> >>> But I'm not able to access them in this way. >>> >>> >>> Using reflection to list accessibles methods on the map I get : >>> >>> __call__ x.__call__(...) <==> x(...) >>> __class__ instancemethod(function, instance, class) Create an >>> instance method object. >>> __cmp__ x.__cmp__(y) <==> cmp(x,y) >>> __delattr__ x.__delattr__('name') <==> del x.name >>> __get__ descr.__get__(obj[, type]) -> value >>> __getattribute__ x.__getattribute__('name') <==> x.name >>> __hash__ x.__hash__() <==> hash(x) >>> __init__ x.__init__(...) initializes x; see x.__class__.__doc__ for >>> signature >>> __new__ T.__new__(S, ...) -> a new object with type S, a subtype of T >>> __reduce__ helper for pickle >>> __reduce_ex__ helper for pickle >>> __repr__ x.__repr__() <==> repr(x) >>> __setattr__ x.__setattr__('name', value) <==> x.name = value >>> __str__ x.__str__() <==> str(x) >>> im_class None >>> im_func None >>> >>> >>> "values" function don't appear... >> >> Please create small test case that reproduce the problem. >> >> According to my unit tests >> * >> http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/indexing_suites_tester.py?revision=414&view=markup >> * >> http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/indexing_suites2_tester.py?revision=1081&view=markup >> >> the functionality works just fine. >> >> >> >> -- >> Roman Yakovenko >> C++ Python language binding >> http://www.language-binding.net/ >> > |
From: Vincent F. <vin...@gm...> - 2008-06-20 07:16:08
|
More precisions again, I'm mapping the following function : std::map<int,node> & getNodes(void) ; I specify the call policy like that : nastranDb.member_function('getNodes').call_policies = call_policies.return_value_policy(call_policies.reference_existing_object) Is this the good way to do? Is there a possibility to directly get Python lists, or tuples etc? 2008/6/19, Vincent Ferries <vin...@gm...>: > In fact, it allways produce me classes like > pyferespost.map_less__int_comma__postLib_scope_nastran_scope_property__grate_, > I understand the reason but, is it a way to use python lists, sets and > dictionnaries instead of generated ones which seams to lack some > functionalities? > Or is it a way to implement these functionalities? > > 2008/6/19, Vincent Ferries <vin...@gm...>: >> I read this unit tests before, but don't seem to get the same type of >> vectors/maps. >> >> I don't really know what I am missing, maybe a wrong call policy? >> I set the call policy of getters on those maps to >> call_policies.reference_existing_object. >> The module creator generate me a list of vector and map wrappers with >> the methods I just listed above. I can't obviously access it like a >> list or a dictionary. >> >> I'm using base implementation of indexing_suite (not >> indexing_suite_v2, I have problems to compile while using it). If I >> can access different children elements it'll be fine for me, no real >> need of indexing_suite_v2. >> >> 2008/6/19, Roman Yakovenko <rom...@gm...>: >>> On Thu, Jun 19, 2008 at 11:00 AM, Vincent Ferries >>> <vin...@gm...> wrote: >>>> For dictionaries you can directly use structures like : >>>> >>>> for (key, values) in dict: >>>> >>>> and the key/values elements will be matching key and list of values. >>>> >>>> >>>> But I'm not able to access them in this way. >>>> >>>> >>>> Using reflection to list accessibles methods on the map I get : >>>> >>>> __call__ x.__call__(...) <==> x(...) >>>> __class__ instancemethod(function, instance, class) Create an >>>> instance method object. >>>> __cmp__ x.__cmp__(y) <==> cmp(x,y) >>>> __delattr__ x.__delattr__('name') <==> del x.name >>>> __get__ descr.__get__(obj[, type]) -> value >>>> __getattribute__ x.__getattribute__('name') <==> x.name >>>> __hash__ x.__hash__() <==> hash(x) >>>> __init__ x.__init__(...) initializes x; see x.__class__.__doc__ for >>>> signature >>>> __new__ T.__new__(S, ...) -> a new object with type S, a subtype of T >>>> __reduce__ helper for pickle >>>> __reduce_ex__ helper for pickle >>>> __repr__ x.__repr__() <==> repr(x) >>>> __setattr__ x.__setattr__('name', value) <==> x.name = value >>>> __str__ x.__str__() <==> str(x) >>>> im_class None >>>> im_func None >>>> >>>> >>>> "values" function don't appear... >>> >>> Please create small test case that reproduce the problem. >>> >>> According to my unit tests >>> * >>> http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/indexing_suites_tester.py?revision=414&view=markup >>> * >>> http://pygccxml.svn.sourceforge.net/viewvc/pygccxml/pyplusplus_dev/unittests/indexing_suites2_tester.py?revision=1081&view=markup >>> >>> the functionality works just fine. >>> >>> >>> >>> -- >>> Roman Yakovenko >>> C++ Python language binding >>> http://www.language-binding.net/ >>> >> > |
From: Roman Y. <rom...@gm...> - 2008-06-24 07:41:55
|
On Fri, Jun 20, 2008 at 10:16 AM, Vincent Ferries <vin...@gm...> wrote: > More precisions again, I'm mapping the following function : > > std::map<int,node> & getNodes(void) ; > > I specify the call policy like that : > > nastranDb.member_function('getNodes').call_policies = > call_policies.return_value_policy(call_policies.reference_existing_object) > > Is this the good way to do? I don't know. In order to answer this question I need to see code - I need to know what is the lifetime of the returned value. It is also important to know whether getNodes function is member function or not > Is there a possibility to directly get Python lists, or tuples etc? No, you will have to write wrappers. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Vincent F. <vin...@gm...> - 2008-06-24 07:14:32
|
Absolutely no idea? :S |
From: Roman Y. <rom...@gm...> - 2008-06-24 07:42:20
|
On Tue, Jun 24, 2008 at 10:14 AM, Vincent Ferries <vin...@gm...> wrote: > Absolutely no idea? :S Sorry, I was pretty busy. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Vincent F. <vin...@gm...> - 2008-06-24 08:06:11
|
Yes, the function getNodes is a member function. Here is a little portion of the source code : namespace postLib { namespace nastran { class dataBase : public generic::dataBase { private : std::map<int,node> nodes ; public : dataBase(void) ; ~dataBase(void) ; // Accessing "model" member data : std::map<int,node> & getNodes(void) ; } ; // class dataBase } // namespace nastran } // namespace postLib I cleaned all that wasn't necessary. After getting the node objects from the getNodes function, I need to recover them one by one in the map and use them in other functions, be able to call their methods too. According to me, these items are supposed to live as long as the dataBase is exploited. >Sorry, I was pretty busy. No problem, you are very reactive, that's a pleasure! 2008/6/24, Roman Yakovenko <rom...@gm...>: > On Tue, Jun 24, 2008 at 10:14 AM, Vincent Ferries > <vin...@gm...> wrote: >> Absolutely no idea? :S > > Sorry, I was pretty busy. > > > > -- > Roman Yakovenko > C++ Python language binding > http://www.language-binding.net/ > |
From: Roman Y. <rom...@gm...> - 2008-06-24 08:16:24
|
On Tue, Jun 24, 2008 at 11:06 AM, Vincent Ferries <vin...@gm...> wrote: > Yes, the function getNodes is a member function. > > Here is a little portion of the source code : > > namespace postLib { > namespace nastran { > class dataBase : public generic::dataBase { > > private : > std::map<int,node> nodes ; > > public : > dataBase(void) ; > ~dataBase(void) ; > > // Accessing "model" member data : > std::map<int,node> & getNodes(void) ; > > } ; // class dataBase > } // namespace nastran > } // namespace postLib > > I cleaned all that wasn't necessary. > After getting the node objects from the getNodes function, I need to > recover them one by one in the map and use them in other functions, be > able to call their methods too. > According to me, these items are supposed to live as long as the > dataBase is exploited. In this case you use the right call policy - return_internal_reference I suggest you to read this document http://www.boost.org/doc/libs/1_35_0/libs/python/doc/v2/indexing.html , which explains how to use "built-in" indexing suite HTH -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |