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 3421b9424c43753d
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
     1.1 --- a/bindings/python/ns3modulegen.py	Sat Jul 12 22:06:15 2008 +0100
     1.2 +++ b/bindings/python/ns3modulegen.py	Sun Jul 13 17:55:48 2008 +0100
     1.3 @@ -100,6 +100,7 @@
     1.4          mod.register_methods(root_module)
     1.5  
     1.6      ns3modulegen_core_customizations.Object_customizations(root_module)
     1.7 +    ns3modulegen_core_customizations.Attribute_customizations(root_module)
     1.8  
     1.9      register_functions(root_module)
    1.10  
     2.1 --- a/bindings/python/ns3modulegen_core_customizations.py	Sat Jul 12 22:06:15 2008 +0100
     2.2 +++ b/bindings/python/ns3modulegen_core_customizations.py	Sun Jul 13 17:55:48 2008 +0100
     2.3 @@ -5,6 +5,7 @@
     2.4  from pybindgen.cppmethod import CustomCppMethodWrapper, CustomCppConstructorWrapper
     2.5  from pybindgen.typehandlers.codesink import MemoryCodeSink
     2.6  from pybindgen.typehandlers import ctypeparser
     2.7 +from pybindgen import cppclass
     2.8  import warnings
     2.9  
    2.10  from pybindgen.typehandlers.base import CodeGenerationError
    2.11 @@ -493,3 +494,27 @@
    2.12      return 0;
    2.13  }
    2.14  ''')
    2.15 +
    2.16 +
    2.17 +def Attribute_customizations(module):
    2.18 +    # Fix up for the "const AttributeValue &v = EmptyAttribute()"
    2.19 +    # case, as used extensively by helper classes.
    2.20 +
    2.21 +    # Here's why we need to do this: pybindgen.gccxmlscanner, when
    2.22 +    # scanning parameter default values, is only provided with the
    2.23 +    # value as a simple C expression string.  (py)gccxml does not
    2.24 +    # report the type of the default value.
    2.25 +
    2.26 +    # As a workaround, here we iterate over all parameters of all
    2.27 +    # methods of all classes and tell pybindgen what is the type of
    2.28 +    # the default value for attributes.
    2.29 +
    2.30 +    for cls in module.classes:
    2.31 +        for meth in cls.get_all_methods():
    2.32 +            for param in meth.parameters:
    2.33 +                if isinstance(param, cppclass.CppClassRefParameter):
    2.34 +                    if param.cpp_class.name == 'AttributeValue' \
    2.35 +                            and param.default_value is not None \
    2.36 +                            and param.default_value_type is None:
    2.37 +                        param.default_value_type = 'ns3::EmptyAttributeValue'
    2.38 +
     3.1 --- a/bindings/python/wscript	Sat Jul 12 22:06:15 2008 +0100
     3.2 +++ b/bindings/python/wscript	Sun Jul 13 17:55:48 2008 +0100
     3.3 @@ -21,7 +21,7 @@
     3.4      os.environ['PYTHONPATH'] = LOCAL_PYBINDGEN_PATH
     3.5  
     3.6  ## https://launchpad.net/pybindgen/
     3.7 -REQUIRED_PYBINDGEN_VERSION = (0, 8, 0, 479)
     3.8 +REQUIRED_PYBINDGEN_VERSION = (0, 8, 0, 492)
     3.9  REQUIRED_PYGCCXML_VERSION = (0, 9, 5)
    3.10  
    3.11