Bug 786 - Make Ipv4Address hashable from Python
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Thu, 14 Jan 2010 11:45:04 +0000
changeset 5911 993998a62a6a
parent 5910 681058254595
child 5912 679c04aa43e7
Bug 786 - Make Ipv4Address hashable from Python
bindings/python/ns3modulegen.py
bindings/python/ns3modulegen_core_customizations.py
--- a/bindings/python/ns3modulegen.py	Wed Jan 13 09:58:37 2010 -0500
+++ b/bindings/python/ns3modulegen.py	Thu Jan 14 11:45:04 2010 +0000
@@ -95,6 +95,7 @@
     ns3modulegen_core_customizations.CommandLine_customizations(root_module)
     ns3modulegen_core_customizations.TypeId_customizations(root_module)
     ns3modulegen_core_customizations.add_std_ofstream(root_module)
+    ns3modulegen_core_customizations.add_ipv4_address_tp_hash(root_module)
 
 
     for local_module in LOCAL_MODULES:
--- a/bindings/python/ns3modulegen_core_customizations.py	Wed Jan 13 09:58:37 2010 -0500
+++ b/bindings/python/ns3modulegen_core_customizations.py	Thu Jan 14 11:45:04 2010 +0000
@@ -572,3 +572,14 @@
                               Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")])
     ofstream.add_method('close', None, [])
 
+def add_ipv4_address_tp_hash(module):
+    module.body.writeln('''
+long
+_ns3_Ipv4Address_tp_hash (PyObject *obj)
+{
+   PyNs3Ipv4Address *addr = reinterpret_cast<PyNs3Ipv4Address *> (obj);
+   return static_cast<long> (ns3::Ipv4AddressHash () (*addr->obj));
+}
+''')
+    module.header.writeln('long _ns3_Ipv4Address_tp_hash (PyObject *obj);')
+    module['Ipv4Address'].pytype.slots['tp_hash'] = "_ns3_Ipv4Address_tp_hash"