Python: make helper class methods using attribute optional parameters work.
authorGustavo J. A. M. Carneiro <gjc@inescporto.pt>
Sun, 13 Jul 2008 17:55:48 +0100
changeset 3421 b9424c43753d
parent 3420 390db659644b
child 3422 ad0c05e68792
Python: make helper class methods using attribute optional parameters work.
bindings/python/ns3modulegen.py
bindings/python/ns3modulegen_core_customizations.py
bindings/python/wscript
--- a/bindings/python/ns3modulegen.py	Sat Jul 12 22:06:15 2008 +0100
+++ b/bindings/python/ns3modulegen.py	Sun Jul 13 17:55:48 2008 +0100
@@ -100,6 +100,7 @@
         mod.register_methods(root_module)
 
     ns3modulegen_core_customizations.Object_customizations(root_module)
+    ns3modulegen_core_customizations.Attribute_customizations(root_module)
 
     register_functions(root_module)
 
--- a/bindings/python/ns3modulegen_core_customizations.py	Sat Jul 12 22:06:15 2008 +0100
+++ b/bindings/python/ns3modulegen_core_customizations.py	Sun Jul 13 17:55:48 2008 +0100
@@ -5,6 +5,7 @@
 from pybindgen.cppmethod import CustomCppMethodWrapper, CustomCppConstructorWrapper
 from pybindgen.typehandlers.codesink import MemoryCodeSink
 from pybindgen.typehandlers import ctypeparser
+from pybindgen import cppclass
 import warnings
 
 from pybindgen.typehandlers.base import CodeGenerationError
@@ -493,3 +494,27 @@
     return 0;
 }
 ''')
+
+
+def Attribute_customizations(module):
+    # Fix up for the "const AttributeValue &v = EmptyAttribute()"
+    # case, as used extensively by helper classes.
+
+    # Here's why we need to do this: pybindgen.gccxmlscanner, when
+    # scanning parameter default values, is only provided with the
+    # value as a simple C expression string.  (py)gccxml does not
+    # report the type of the default value.
+
+    # As a workaround, here we iterate over all parameters of all
+    # methods of all classes and tell pybindgen what is the type of
+    # the default value for attributes.
+
+    for cls in module.classes:
+        for meth in cls.get_all_methods():
+            for param in meth.parameters:
+                if isinstance(param, cppclass.CppClassRefParameter):
+                    if param.cpp_class.name == 'AttributeValue' \
+                            and param.default_value is not None \
+                            and param.default_value_type is None:
+                        param.default_value_type = 'ns3::EmptyAttributeValue'
+
--- a/bindings/python/wscript	Sat Jul 12 22:06:15 2008 +0100
+++ b/bindings/python/wscript	Sun Jul 13 17:55:48 2008 +0100
@@ -21,7 +21,7 @@
     os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH
 
 ## https://launchpad.net/pybindgen/
-REQUIRED_PYBINDGEN_VERSION = (0, 8, 0, 479)
+REQUIRED_PYBINDGEN_VERSION = (0, 8, 0, 492)
 REQUIRED_PYGCCXML_VERSION = (0, 9, 5)