From 10ee9b9e01bd5f150bf6d5df5b56f05f06ed6760 Mon Sep 17 00:00:00 2001 From: "Gustavo J. A. M. Carneiro" Date: Sun, 13 Jul 2008 17:55:48 +0100 Subject: [PATCH] Python: make helper class methods using attribute optional parameters work. --- bindings/python/ns3modulegen.py | 1 + .../ns3modulegen_core_customizations.py | 25 +++++++++++++++++++ bindings/python/wscript | 2 +- 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/bindings/python/ns3modulegen.py b/bindings/python/ns3modulegen.py index 4ca929a1d..d986e9565 100644 --- a/bindings/python/ns3modulegen.py +++ b/bindings/python/ns3modulegen.py @@ -100,6 +100,7 @@ def main(): mod.register_methods(root_module) ns3modulegen_core_customizations.Object_customizations(root_module) + ns3modulegen_core_customizations.Attribute_customizations(root_module) register_functions(root_module) diff --git a/bindings/python/ns3modulegen_core_customizations.py b/bindings/python/ns3modulegen_core_customizations.py index 95721c5f4..50e6dc849 100644 --- a/bindings/python/ns3modulegen_core_customizations.py +++ b/bindings/python/ns3modulegen_core_customizations.py @@ -5,6 +5,7 @@ from pybindgen import (ReturnValue, Parameter) 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 @@ int KwargsToAttributeList(PyObject *kwargs, ns3::TypeId tid, ns3::AttributeList 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' + diff --git a/bindings/python/wscript b/bindings/python/wscript index d3d8f9616..274620a5b 100644 --- a/bindings/python/wscript +++ b/bindings/python/wscript @@ -21,7 +21,7 @@ else: 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)