From 4b7cf8f4e4c373aab86c3ccc6638a849fb3e8b45 Mon Sep 17 00:00:00 2001 From: Gustavo Carneiro Date: Wed, 18 Dec 2013 19:29:25 +0000 Subject: [PATCH] Add a custom typehandler for std::ios::openmode, fixes #1815 --- .../ns3modulegen_core_customizations.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/bindings/python/ns3modulegen_core_customizations.py b/bindings/python/ns3modulegen_core_customizations.py index c9dedc699..c4ff74bea 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.typehandlers.base import ForwardWrapperBase from pybindgen import cppclass import warnings @@ -425,11 +426,24 @@ def add_std_ofstream(module): add_std_ios_openmode(module) -def add_std_ios_openmode(module): - import pybindgen.typehandlers.base - for alias in "std::_Ios_Openmode", "std::ios::openmode": - pybindgen.typehandlers.base.param_type_matcher.add_type_alias(alias, "int") +class IosOpenmodeParam(Parameter): + DIRECTIONS = [Parameter.DIRECTION_IN] + CTYPES = ['std::ios::openmode', 'std::_Ios_Openmode'] + + def convert_c_to_python(self, wrapper): + assert isinstance(wrapper, ReverseWrapperBase) + wrapper.build_params.add_parameter('i', [self.value]) + + def convert_python_to_c(self, wrapper): + assert isinstance(wrapper, ForwardWrapperBase) + name = wrapper.declarations.declare_variable("std::ios::openmode", self.name, self.default_value) + wrapper.parse_params.add_parameter('i', ['&'+name], self.name, optional=bool(self.default_value)) + wrapper.call_params.append(name) + + + +def add_std_ios_openmode(module): for flag in 'in', 'out', 'ate', 'app', 'trunc', 'binary': module.after_init.write_code('PyModule_AddIntConstant(m, (char *) "STD_IOS_%s", std::ios::%s);' % (flag.upper(), flag))