I've come across two problems with some python exporting Im trying to do.
First problems is as follows. I have the following piece of python code:
            inv = ActiveGame.GetPlayerParty().GetInventory().GetItems()         
   print str(len(inv))            print type(inv)            inv["Thunder 
Core"] = 10            print str(len(inv))            for key in 
inv.iterkeys():                print key
The problem is that the code simply hangs at print key. That is. nothing gets 
printed, and my program stops responding. Everything up to that point works 
correctly.
inv is a boost::unordered_map<std::string, int> and it's exposed like follows:
class_<boost::unordered_map<std::string, int> >("ItemCountMapUnordered")        
                        
.def(map_indexing_suite<boost::unordered_map<std::string, int> >())             
                ;
Inventory is wrapped like this:
class InventoryComponent : public Components::Component         {               
public:                        //additional methods omitted for example         
        boost::unordered_map<std::string, int>& GetItems();                 
private:                    boost::unordered_map<std::string, int> ItemCount;   
              }
class_<Items::InventoryComponent, bases<Components::Component> 
>("InventoryComponent", init<Entity*>())                         
.def("GetItems", &Items::InventoryComponent::GetItems, 
return_value_policy<reference_existing_object>())
When I run the python code I get the output8<class 
'ItemModule.ItemCountMapUnordered'>9
and then it hangs. Nothing is printed even though the map is definitely not 
empty and I was able to add an item to it. Is there something obvious I'm 
missing? I've tried switching it to an std::map from boost::unordered_map but 
the result was the same.
The second problem I'm having seems directly related to trying to use a 
boost::unordered_map with map_indexing_suite.
I wrap a map like follows:
class_<boost::unordered_map<std::string, 
boost::shared_ptr<Character::BaseCharacter> > >("BasePartyMemberMap")
                .def(map_indexing_suite<boost::unordered_map<std::string, 
boost::shared_ptr<Character::BaseCharacter> > >())
                ;
however, when I attempt to access objects of this type I get the following error
Error   26  error C2039: 'key_comp' : is not a member of 
'boost::unordered::unordered_map<K,T>' 
c:\programming_libraries\cpp_libraries\boost_1_49_0\boost\python\suite\indexing\map_indexing_suite.hpp
  155
in this case, switching boost::unordered_map to std::map solved the issue, but 
I'd prefer to keep boost::unordered_map if possible.
I'd appreciate any help in fixing these issues and can provide more code if you 
need it. Thanks in advance

                                          
_______________________________________________
Cplusplus-sig mailing list
Cplusplus-sig@python.org
http://mail.python.org/mailman/listinfo/cplusplus-sig

Reply via email to