def add_gram_schmidt(la_backend, name): MatrixType = 'Dune::Stuff::LA::' VectorType = 'Dune::Stuff::LA::' if 'eigen_sparse' in la_backend: MatrixType += 'EigenRowMajorSparseMatrix' VectorType += 'EigenDenseVector' elif 'istl_sparse' in la_backend: MatrixType += 'IstlRowMajorSparseMatrix' VectorType += 'IstlDenseVector' MatrixType += '< ' + RangeFieldType + ' >' VectorType += '< ' + RangeFieldType + ' >' module.add_function('gram_schmidt', retval('std::vector< ' + VectorType + ' >'), [param('const std::vector< ' + VectorType + ' >&', 'A'), param('const bool', 'reiterate'), param('const bool', 'check')], throw=exceptions, template_parameters=[VectorType], custom_name='gram_schmidt_' + name) module.add_function('gram_schmidt', retval('std::vector< ' + VectorType + ' >'), [param('const std::vector< ' + VectorType + ' >&', 'A'), param('const ' + MatrixType + '&', 'product'), param('const bool', 'reiterate'), param('const bool', 'check')], throw=exceptions, template_parameters=[VectorType, MatrixType], custom_name='gram_schmidt_' + name)
def inject_ParameterFunctional(module, exceptions, interfaces, CONFIG_H): assert(isinstance(module, pybindgen.module.Module)) assert(isinstance(exceptions, list)) assert(isinstance(interfaces, dict)) for element in interfaces: assert(isinstance(element, str)) assert(len(element) > 0) assert(isinstance(CONFIG_H, dict)) namespace = module.add_cpp_namespace('Dune').add_cpp_namespace('Pymor') ParameterFunctional = namespace.add_class('ParameterFunctional', parent=[interfaces['Dune::Pymor::Parametric']]) ParameterFunctional.add_copy_constructor() ParameterFunctional.add_constructor([param('const Dune::Pymor::ParameterType&', 'tt'), param('const std::string', 'exp')], throw=exceptions) ParameterFunctional.add_method('expression', retval('const std::string'), [], is_const=True) ParameterFunctional.add_method('report', retval('std::string'), [], is_const=True) ParameterFunctional.add_method('report', retval('std::string'), [param('const std::string', 'name')], is_const=True) ParameterFunctional.add_method('evaluate', 'double', [param('const Parameter&', 'mu')], throw=exceptions, is_const=True) ParameterFunctional.allow_subclassing = True return module, ParameterFunctional
def module_gen(name): mod = Module('display') mod.add_include('"display.h"') display = mod.add_class('Display') display.add_constructor([param('int', 'height'), param('int', 'width')]) display.add_method('stop', None, []) display.add_method('getHeight', retval('int'), []) display.add_method('getWidth', retval('int'), []) display.add_method('getValue', retval('int'), [param('int', 'row'), param('int', 'col')]) display.add_method('setValue', None, [param('int', 'row'), param('int', 'col'), param('int', 'color')]) display.add_method('drawRectangle', None, [param('int', 'x'), param('int', 'y'), param('int', 'width'), param('int', 'height'), param('int', 'color')]) display.add_method('drawTriangle', None, [param('int', 'x'), param('int', 'y'), param('int', 'width'), param('int', 'height'), param('int', 'color')]) display.add_method('clear', None, []) mod.add_function('loop', retval('int'), [param('Display *', 'disp', transfer_ownership=False)]) mod.generate(name)
def inject_Parametric(module, exceptions, CONFIG_H): assert(isinstance(module, pybindgen.module.Module)) assert(isinstance(exceptions, list)) assert(isinstance(CONFIG_H, dict)) namespace = module.add_cpp_namespace('Dune').add_cpp_namespace('Pymor') Parametric = namespace.add_class('Parametric') ################################################################### # The following code leads to segfaults of the python interpreter. # Not excactly sure why, but probably not needed on the python side # anyway. # Parametric.add_constructor([]) # Parametric.add_constructor([param('Dune::Pymor::ParameterType', 'tt')]) # Parametric.add_constructor([param('std::string', 'kk'), # param(CONFIG_H['DUNE_STUFF_SSIZE_T'], 'vv')]) # Parametric.add_constructor([param('std::vector< std::string >', 'kk'), # param('std::vector< ' + CONFIG_H['DUNE_STUFF_SSIZE_T'] + ' >', 'vv')]) # Parametric.add_copy_constructor() ################################################################### Parametric.add_method('parameter_type', retval('const Dune::Pymor::ParameterType&'), [], is_const=True) Parametric.add_method('parametric', retval('bool'), [], is_const=True) # Parametric.allow_subclassing = True return module, Parametric
def reg_NfdCs(root_module, cls): cls.add_method('size', retval('size_t'), [], is_const=True) cls.add_container_traits(retval('const ns3::ndn::nfd::cs::Entry&', caller_manages_return=False), begin_method='begin', end_method='end', iterator_type='const_iterator') def reg_Entry(cls): cls.add_method('getName', retval('const ns3::ndn::Name&'), [], is_const=True) reg_Entry(root_module['ns3::ndn::nfd::cs::Entry'])
def reg_strategychoicehelper(cls): cls.add_method('Install', retval('void'), [param('ns3::Ptr<ns3::Node>', 'node'), param('const const std::string&', 'name'), param('const const std::string&', 'strategy')], is_const=True, is_static=True) cls.add_method('Install', retval('void'), [param('const ns3::NodeContainer&', 'c'), param('const const std::string&', 'name'), param('const const std::string&', 'strategy')], is_const=True, is_static=True) cls.add_method('InstallAll', retval('void'), [param('const std::string&', 'name'), param('const std::string&', 'strategy')], is_const=True, is_static=True)
def add_functions(mod): mod.add_function('iks_make_session', retval('iks*', caller_owns_return=True), [], custom_name='make_session') mod.add_function('iks_make_pres', retval('iks*', caller_owns_return=True), [param('int', 'show'), param('const char *', 'status')], custom_name='make_pres')
def inject_VectorBasedImplementation(module, exceptions, interfaces, CONFIG_H, Traits, template_parameters=None): assert isinstance(module, pybindgen.module.Module) assert isinstance(exceptions, list) assert isinstance(interfaces, dict) for element in interfaces: assert isinstance(element, str) assert len(element) > 0 assert isinstance(CONFIG_H, dict) assert isinstance(Traits, dict) for key in Traits.keys(): assert isinstance(Traits[key], str) assert len(Traits[key].strip()) > 0 assert "SourceType" in Traits SourceType = Traits["SourceType"] assert "ScalarType" in Traits ScalarType = Traits["ScalarType"] assert "ContainerType" in Traits ContainerType = Traits["ContainerType"] if template_parameters is not None: if isinstance(template_parameters, str): assert len(template_parameters.strip()) > 0 template_parameters = [template_parameters] elif isinstance(template_parameters, list): for element in template_parameters: assert isinstance(element, str) assert len(element.strip()) > 0 module = module.add_cpp_namespace("Dune").add_cpp_namespace("Pymor").add_cpp_namespace("Functionals") Class = module.add_class( "VectorBased", parent=[interfaces["Dune::Pymor::Tags::FunctionalInterface"], interfaces["Dune::Pymor::Parametric"]], template_parameters=template_parameters, ) Class.add_method("type_this", retval("std::string"), [], is_const=True, is_static=True, throw=exceptions) Class.add_method("type_source", retval("std::string"), [], is_const=True, is_static=True, throw=exceptions) Class.add_method("type_scalar", retval("std::string"), [], is_const=True, is_static=True, throw=exceptions) Class.add_method("type_frozen", retval("std::string"), [], is_const=True, is_static=True, throw=exceptions) Class.add_method("linear", retval("bool"), [], is_const=True) Class.add_method("dim_source", retval(CONFIG_H["DUNE_STUFF_SSIZE_T"]), [], is_const=True) Class.add_method( "apply", retval(ScalarType), [param("const " + SourceType + " &", "source")], is_const=True, throw=exceptions ) Class.add_method( "apply", retval(ScalarType), [param("const " + SourceType + " &", "source"), param("const Dune::Pymor::Parameter", "mu")], is_const=True, throw=exceptions, ) Class.add_method( "as_vector_and_return_ptr", retval(ContainerType + " *", caller_owns_return=True), [], is_const=True, throw=exceptions, custom_name="as_vector", ) return Class
def inject_VectorBasedImplementation(module, exceptions, interfaces, CONFIG_H, Traits, template_parameters=None): assert(isinstance(module, pybindgen.module.Module)) assert(isinstance(exceptions, list)) assert(isinstance(interfaces, dict)) for element in interfaces: assert(isinstance(element, str)) assert(len(element) > 0) assert(isinstance(CONFIG_H, dict)) assert(isinstance(Traits, dict)) for key in Traits.keys(): assert(isinstance(Traits[key], str)) assert(len(Traits[key].strip()) > 0) assert('SourceType' in Traits) SourceType = Traits['SourceType'] assert('ScalarType' in Traits) ScalarType = Traits['ScalarType'] assert('ContainerType' in Traits) ContainerType = Traits['ContainerType'] if template_parameters is not None: if isinstance(template_parameters, str): assert(len(template_parameters.strip()) > 0) template_parameters = [ template_parameters ] elif isinstance(template_parameters, list): for element in template_parameters: assert(isinstance(element, str)) assert(len(element.strip()) > 0) module = module.add_cpp_namespace('Dune').add_cpp_namespace('Pymor').add_cpp_namespace('Functionals') Class = module.add_class('VectorBased', parent=[interfaces['Dune::Pymor::Tags::FunctionalInterface'], interfaces['Dune::Pymor::Parametric']], template_parameters=template_parameters) Class.add_method('type_this', retval('std::string'), [], is_const=True, is_static=True, throw=exceptions) Class.add_method('type_source', retval('std::string'), [], is_const=True, is_static=True, throw=exceptions) Class.add_method('type_scalar', retval('std::string'), [], is_const=True, is_static=True, throw=exceptions) Class.add_method('type_frozen', retval('std::string'), [], is_const=True, is_static=True, throw=exceptions) Class.add_method('linear', retval('bool'), [], is_const=True) Class.add_method('dim_source', retval(CONFIG_H['DUNE_STUFF_SSIZE_T']), [], is_const=True) Class.add_method('apply', retval(ScalarType), [param('const ' + SourceType + ' &', 'source')], is_const=True, throw=exceptions) Class.add_method('apply', retval(ScalarType), [param('const ' + SourceType + ' &', 'source'), param('const Dune::Pymor::Parameter', 'mu')], is_const=True, throw=exceptions) Class.add_method('as_vector_and_return_ptr', retval(ContainerType + ' *', caller_owns_return=True), [], is_const=True, throw=exceptions, custom_name='as_vector') return Class
def inject_Parameter(module, exceptions, CONFIG_H): assert(isinstance(module, pybindgen.module.Module)) assert(isinstance(exceptions, list)) assert(isinstance(CONFIG_H, dict)) namespace = module.add_cpp_namespace('Dune').add_cpp_namespace('Pymor') Parameter = namespace.add_class('Parameter') Parameter.add_constructor([]) Parameter.add_constructor([param('std::string', 'kk'), param('double', 'vv')]) Parameter.add_constructor([param('Dune::Pymor::ParameterType', 'tt'), param('double', 'vv')], throw=exceptions) Parameter.add_constructor([param('std::string', 'kk'), param('std::vector< double >', 'vv')], throw=exceptions) Parameter.add_constructor([param('Dune::Pymor::ParameterType', 'tt'), param('std::vector< double >', 'vv')], throw=exceptions) Parameter.add_constructor([param('std::vector< std::string >', 'kk'), param('std::vector< std::vector< double > >', 'vv')], throw=exceptions) Parameter.add_constructor([param('Dune::Pymor::ParameterType', 'tt'), param('std::vector< std::vector< double > >', 'vv')], throw=exceptions) Parameter.add_method('type', retval('Dune::Pymor::ParameterType'), [], is_const=True) Parameter.add_method('empty', retval('bool'), [], is_const=True) Parameter.add_method('keys', retval('std::vector< std::string >'), [], is_const=True) Parameter.add_method('values', retval('std::vector< std::vector< double > >'), [], is_const=True) Parameter.add_method('hasKey', retval('bool'), [param('std::string', 'key')], is_const=True) Parameter.add_method('set', None, [param('std::string', 'key'), param('std::vector< double >', 'value')], throw=exceptions) Parameter.add_method('get', retval('std::vector< double >'), [param('std::string', 'key')], is_const=True, throw=exceptions) Parameter.add_binary_comparison_operator('==') Parameter.add_binary_comparison_operator('!=') Parameter.add_method('size', retval(CONFIG_H['DUNE_STUFF_SSIZE_T']), [], is_const=True) Parameter.add_method('report', retval('std::string'), [], is_const=True) Parameter.add_method('report_for_filename', retval('std::string'), [], is_const=True) Parameter.allow_subclassing = True return module, Parameter
def reg_Name(root_module, cls): cls.add_output_stream_operator() for op in ['==', '!=', '<', '<=', '>', '>=']: cls.add_binary_comparison_operator(op) cls.add_container_traits(retval('const ns3::ndn::name::Component&'), begin_method='begin', end_method='end', iterator_type='const_iterator') cls.add_constructor([]) cls.add_constructor([param('const ns3::ndn::Name&', 'other')]) cls.add_constructor([param('const std::string&', 'url')]) cls.add_method('append', 'ns3::ndn::Name &', [param('const ns3::ndn::name::Component&', 'comp')]) cls.add_method('get', 'const ns3::ndn::name::Component&', [param('int', 'index')], is_const=True) cls.add_method('getPrefix', 'ns3::ndn::Name', [param('size_t', 'len')], is_const=True) cls.add_method('size', 'size_t', [], is_const=True) cls.add_method('toUri', retval('std::string'), [], is_const=True)
def register_Ns3GlobalRouter_methods(root_module, cls): ## global-router-interface.h: static ns3::TypeId ns3::GlobalRouter::GetTypeId() [member function] cls.add_method("GetTypeId", "ns3::TypeId", [], is_static=True) ## global-router-interface.h: ns3::GlobalRouter::GlobalRouter() [constructor] cls.add_constructor([]) ## global-router-interface.h: void ns3::GlobalRouter::SetRoutingProtocol(ns3::Ptr<ns3::Ipv4GlobalRouting> routing) [member function] cls.add_method("SetRoutingProtocol", "void", [param("ns3::Ptr< ns3::Ipv4GlobalRouting >", "routing")]) ## global-router-interface.h: ns3::Ptr<ns3::Ipv4GlobalRouting> ns3::GlobalRouter::GetRoutingProtocol() [member function] cls.add_method("GetRoutingProtocol", "ns3::Ptr< ns3::Ipv4GlobalRouting >", []) ## global-router-interface.h: ns3::Ipv4Address ns3::GlobalRouter::GetRouterId() const [member function] cls.add_method("GetRouterId", "ns3::Ipv4Address", [], is_const=True) ## global-router-interface.h: uint32_t ns3::GlobalRouter::DiscoverLSAs() [member function] cls.add_method("DiscoverLSAs", "uint32_t", []) ## global-router-interface.h: uint32_t ns3::GlobalRouter::GetNumLSAs() const [member function] cls.add_method("GetNumLSAs", "uint32_t", [], is_const=True) ## global-router-interface.h: bool ns3::GlobalRouter::GetLSA(uint32_t n, ns3::GlobalRoutingLSA & lsa) const [member function] cls.add_method("GetLSA", "bool", [param("uint32_t", "n"), param("ns3::GlobalRoutingLSA &", "lsa")], is_const=True) ## global-router-interface.h: void ns3::GlobalRouter::InjectRoute(ns3::Ipv4Address network, ns3::Ipv4Mask networkMask) [member function] cls.add_method("InjectRoute", "void", [param("ns3::Ipv4Address", "network"), param("ns3::Ipv4Mask", "networkMask")]) ## global-router-interface.h: uint32_t ns3::GlobalRouter::GetNInjectedRoutes() [member function] cls.add_method("GetNInjectedRoutes", "uint32_t", []) ## global-router-interface.h: ns3::Ipv4RoutingTableEntry * ns3::GlobalRouter::GetInjectedRoute(uint32_t i) [member function] cls.add_method( "GetInjectedRoute", retval("ns3::Ipv4RoutingTableEntry *", caller_owns_return=False), [param("uint32_t", "i")] ) ## global-router-interface.h: void ns3::GlobalRouter::RemoveInjectedRoute(uint32_t i) [member function] cls.add_method("RemoveInjectedRoute", "void", [param("uint32_t", "i")]) ## global-router-interface.h: bool ns3::GlobalRouter::WithdrawRoute(ns3::Ipv4Address network, ns3::Ipv4Mask networkMask) [member function] cls.add_method( "WithdrawRoute", "bool", [param("ns3::Ipv4Address", "network"), param("ns3::Ipv4Mask", "networkMask")] ) ## global-router-interface.h: void ns3::GlobalRouter::DoDispose() [member function] cls.add_method("DoDispose", "void", [], visibility="private", is_virtual=True) return
def register_Ns3Ipv4DceRoutingHelper_methods(root_module, cls): ## ipv4-dce-routing-helper.h: ns3::Ipv4DceRoutingHelper::Ipv4DceRoutingHelper() [constructor] cls.add_constructor([]) ## ipv4-dce-routing-helper.h: ns3::Ipv4DceRoutingHelper::Ipv4DceRoutingHelper(ns3::Ipv4DceRoutingHelper const & arg0) [copy constructor] cls.add_constructor([param('ns3::Ipv4DceRoutingHelper const &', 'arg0')]) ## ipv4-dce-routing-helper.h: ns3::Ipv4DceRoutingHelper * ns3::Ipv4DceRoutingHelper::Copy() const [member function] cls.add_method('Copy', retval('ns3::Ipv4DceRoutingHelper *', caller_owns_return=False), [], is_const=True) ## ipv4-dce-routing-helper.h: ns3::Ptr<ns3::Ipv4RoutingProtocol> ns3::Ipv4DceRoutingHelper::Create(ns3::Ptr<ns3::Node> node) const [member function] cls.add_method('Create', retval('ns3::Ptr<ns3::Ipv4RoutingProtocol >', caller_owns_return=False), [param('ns3::Node *', 'node', transfer_ownership=False)], is_const=True, is_virtual=True) return
def inject_Example(module, exceptions, interfaces, CONFIG_H): '''injects the user code into the module''' # first the discretization GridType = 'Dune::SGrid< 2, 2 >' GridLayerType = 'Dune::Stuff::Grid::ChooseLayer::leaf' RangeFieldType = 'double' dimRange = '1' polOrder = '1' SpaceBackendType = 'Dune::GDT::ChooseSpaceBackend::pdelab' LaBackendType = 'Dune::Stuff::LA::ChooseBackend::istl_sparse' if 'istl_sparse' in LaBackendType: MatrixType = 'Dune::Stuff::LA::IstlRowMajorSparseMatrix< ' + RangeFieldType + ' >' VectorType = 'Dune::Stuff::LA::IstlDenseVector< ' + RangeFieldType + ' >' elif 'eigen_sparse' in LaBackendType: MatrixType = 'Dune::Stuff::LA::EigenRowMajorSparseMatrix< ' + RangeFieldType + ' >' VectorType = 'Dune::Stuff::LA::EigenDenseVector< ' + RangeFieldType + ' >' DiscretizationName = 'Dune::HDD::LinearElliptic::Discretizations::CG' DiscretizationFullName = (DiscretizationName + '< ' + GridType + ', ' + GridLayerType + ', ' + RangeFieldType + ', ' + dimRange + ', ' + polOrder + ', ' + SpaceBackendType + ', ' + LaBackendType + ' >') discretization = inject_StationaryDiscretizationImplementation( module, exceptions, interfaces, CONFIG_H, DiscretizationName, Traits={'VectorType': VectorType, 'OperatorType': 'Dune::Pymor::Operators::LinearAffinelyDecomposedContainerBased< ' + MatrixType + ', ' + VectorType + ' >', 'FunctionalType': 'Dune::Pymor::Functionals::LinearAffinelyDecomposedVectorBased< ' + VectorType + ' >', 'ProductType': 'Dune::Pymor::Operators::LinearAffinelyDecomposedContainerBased< ' + MatrixType + ', ' + VectorType + ' > '}, template_parameters=[GridType, GridLayerType, RangeFieldType, dimRange, polOrder, SpaceBackendType, LaBackendType ]) # then add the example LinearellipticExampleCG = module.add_class('LinearellipticExampleCG', template_parameters=['Dune::SGrid< 2, 2 >'], custom_name='LinearellipticExampleCG') LinearellipticExampleCG.add_method('static_id', retval('std::string'), [], is_const=True, throw=[exceptions['Exception']]) LinearellipticExampleCG.add_method('write_config_file', None, [], is_const=True, throw=[exceptions['Exception']]) LinearellipticExampleCG.add_constructor([], throw=[exceptions['Exception']]) LinearellipticExampleCG.add_method('initialize', None, [param('const std::vector< std::string >', 'arguments')], is_const=True, throw=[exceptions['Exception']]) LinearellipticExampleCG.add_method('discretization_and_return_ptr', retval(DiscretizationFullName + ' *', caller_owns_return=True), [], is_const=True, throw=[exceptions['Exception']], custom_name='discretization')
def my_module_gen(out_file): mod = Module('bar') mod.add_include ('"bar.h"') Foo = mod.add_class('Foo', automatic_type_narrowing=True, memory_policy=BoostSharedPtr('::Foo')) Foo.add_static_attribute('instance_count', ReturnValue.new('int')) Foo.add_constructor([Parameter.new('std::string', 'datum')]) Foo.add_constructor([]) Foo.add_method('get_datum', ReturnValue.new('const std::string'), []) Foo.add_method('is_initialized', ReturnValue.new('bool'), [], is_const=True) Foo.add_output_stream_operator() mod.add_function('function_that_takes_foo', ReturnValue.new('void'), [param('boost::shared_ptr<Foo>', 'foo')]) mod.add_function('function_that_returns_foo', retval('boost::shared_ptr<Foo>'), []) cls = mod.add_class('ClassThatTakesFoo', allow_subclassing=True) cls.add_constructor([Parameter.new('boost::shared_ptr<Foo>', 'foo')]) cls.add_method('get_foo', ReturnValue.new('boost::shared_ptr<Foo>'), []) cls.add_method('get_modified_foo', retval('boost::shared_ptr<Foo>'), [param('boost::shared_ptr<Foo>', 'foo')], is_virtual=True, is_const=True) #### --- error handler --- class MyErrorHandler(pybindgen.settings.ErrorHandler): def __init__(self): super(MyErrorHandler, self).__init__() self.num_errors = 0 def handle_error(self, wrapper, exception, traceback_): print("exception %s in wrapper %s" % (exception, wrapper), file=sys.stderr) self.num_errors += 1 if 0: # verbose? import traceback traceback.print_tb(traceback_) return True pybindgen.settings.error_handler = MyErrorHandler() ## ---- finally, generate the whole thing ---- mod.generate(FileCodeSink(out_file))
def reg_NfdFib(root_module, cls): cls.add_method('size', retval('size_t'), [], is_const=True) cls.add_container_traits(retval('const ns3::ndn::nfd::fib::Entry&', caller_manages_return=False), begin_method='begin', end_method='end', iterator_type='const_iterator') # The following is not supported # cls.add_method('findLongestPrefixMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'), # [param('const ns3::ndn::Name&', 'prefix')], is_const=True) # cls.add_method('findExactMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'), # [param('const ns3::ndn::Name&', 'prefix')], is_const=True) # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'), # [param('const pit::Entry&', 'pitEntry')], is_const=True) # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'), # [param('const measurements::Entry&', 'measurementsEntry')], is_const=True) # cls.add_method('insert', retval('std::pair<std::shared_ptr<ns3::ndn::nfd::fib::Entry>, bool>'), [param('const ns3::ndn::Name&', 'prefix')]) cls.add_method('erase', retval('void'), [param('const ns3::ndn::Name&', 'prefix')]) cls.add_method('erase', retval('void'), [param('const ns3::ndn::nfd::fib::Entry&', 'entry')]) # cls.add_method('removeNextHopFromAllEntries', retval('void'), [param('std::shared_ptr<ns3::ndn::Face>', 'face')]) def reg_Entry(cls): cls.add_method('getPrefix', 'const ns3::ndn::Name&', [], is_const=True) cls.add_method('getNextHops', retval('const ns3::ndn::nfd::fib::NextHopList&', caller_manages_return=False), [], is_const=True) cls.add_method('hasNextHops', 'bool', [], is_const=True) reg_Entry(root_module['ns3::ndn::nfd::fib::Entry']) def reg_NextHop(cls): cls.add_constructor([param('const ns3::ndn::Face&', 'face'), param('uint64_t', 'endpointId')]) cls.add_function_as_method('getFaceFromFibNextHop', 'std::shared_ptr<ns3::ndn::Face>', [param('const ns3::ndn::nfd::fib::NextHop&', 'obj')], custom_name='getFace') cls.add_method('setCost', 'void', [param('uint64_t', 'cost')]) cls.add_method('getCost', 'uint64_t', [], is_const=True) reg_NextHop(root_module['ns3::ndn::nfd::fib::NextHop']) def reg_NextHopList(cls): cls.add_method('size', retval('size_t'), [], is_const=True) cls.add_container_traits(retval('const ns3::ndn::nfd::fib::NextHop&', caller_manages_return=False), begin_method='begin', end_method='end', iterator_type='const_iterator') reg_NextHopList(root_module['ns3::ndn::nfd::fib::NextHopList'])
def my_module_gen(out_file): mod = Module('bsp') mod.add_include ('"bsp.h"') Foo = mod.add_class('Foo', memory_policy=BoostSharedPtr('::Foo')) Foo.add_constructor([param('std::string', 'datum')]) Foo.add_constructor([]) Foo.add_method('get_datum', retval('const std::string'), []) Foo.add_method('set_datum', None, [param('const std::string', 'datum')]) mod.add_function('function_that_takes_foo', None, [param('boost::shared_ptr<Foo>', 'foo')]) mod.add_function('function_that_returns_foo', retval('boost::shared_ptr<Foo>'), []) ## ---- finally, generate the whole thing ---- mod.generate(FileCodeSink(out_file))
def reg_stackhelper(cls): cls.add_constructor([]) cls.add_method('Install', 'ns3::Ptr<ns3::ndn::FaceContainer>', [param('ns3::Ptr<ns3::Node>', 'node')], is_const=True) cls.add_method('Install', 'ns3::Ptr<ns3::ndn::FaceContainer>', [param('std::string const&', 'nodeName')], is_const=True) cls.add_method('Install', 'ns3::Ptr<ns3::ndn::FaceContainer>', [param('const ns3::NodeContainer&', 'c')], is_const=True) cls.add_method('InstallAll', 'ns3::Ptr<ns3::ndn::FaceContainer>', [], is_const=True) cls.add_method('SetDefaultRoutes', retval('void'), [param('bool', 'isEnabled', default_value='true')], is_const=True) cls.add_method('SetStackAttributes', retval('void'), [param('const std::string&', 'attr1', default_value='""'), param('const std::string&', 'value1', default_value='""'), param('const std::string&', 'attr2', default_value='""'), param('const std::string&', 'value2', default_value='""'), param('const std::string&', 'attr3', default_value='""'), param('const std::string&', 'value3', default_value='""'), param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')]) cls.add_method('setCsSize', retval('void'), [param('size_t', 'maxSize')]) cls.add_method('SetOldContentStore', retval('void'), [param('const std::string&', 'contentStoreClass'), param('const std::string&', 'attr1', default_value='""'), param('const std::string&', 'value1', default_value='""'), param('const std::string&', 'attr2', default_value='""'), param('const std::string&', 'value2', default_value='""'), param('const std::string&', 'attr3', default_value='""'), param('const std::string&', 'value3', default_value='""'), param('const std::string&', 'attr4', default_value='""'), param('const std::string&', 'value4', default_value='""')])
def reg_fibhelper(cls): cls.add_method('AddRoute', retval('void'), [ param('const std::string&', 'nodeName'), param('const std::string&', 'prefix'), param('uint32_t', 'faceId'), param('int32_t', 'metric'), ], is_const=True, is_static=True) cls.add_method('AddRoute', retval('void'), [ param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'), param('uint32_t', 'faceId'), param('int32_t', 'metric') ], is_const=True, is_static=True) cls.add_method('AddRoute', retval('void'), [ param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'), param('std::shared_ptr<ns3::ndn::Face>', 'face'), param('int32_t', 'metric'), ], is_const=True, is_static=True) cls.add_method('AddRoute', retval('void'), [ param('ns3::Ptr<ns3::Node>', 'node'), param('const ns3::ndn::Name&', 'prefix'), param('ns3::Ptr<ns3::Node>', 'otherNode'), param('int32_t', 'metric'), ], is_const=True, is_static=True) cls.add_method('AddRoute', retval('void'), [ param('const std::string&', 'nodeName'), param('const std::string&', 'prefix'), param('const std::string&', 'otherNodeName'), param('int32_t', 'metric'), ], is_const=True, is_static=True)
def load_module(module, parent): print "Processing module `%s'" % module['name'] mod = SubModule(module['name'], parent) for enum in module['enums']: print " - enum `%s'" % enum['name'] mod.add_enum(enum['name'], enum['entries']) overrided = [] for func in module['functions']: name = func['name']['name'] custom_name = name.replace('ta_%s_' % mod.name, '') func['name']['pyname'] = custom_name # Adding method to a different list. This list holds methods # that are not generated by pybindgen. get_overrided = OVERRIDES.get(name) if get_overrided == '': # this empty string means that we have overrided the # method aiming to do not generate it continue elif get_overrided: # This means that a valid override was found. func['override'] = get_overrided overrided.append(func) continue try: mod.add_function(name, retval(func['rtype'], caller_owns_return=True), handle_params(func, parent), custom_name=custom_name) except Exception, e: warnings.warn('Skipping func %s, something wrong happened. %s' % (name, str(e)))
struct.add_instance_attribute('ILabels', 'std::vector<int>') struct.add_instance_attribute('OLabels', 'std::vector<int>') struct.add_instance_attribute('Uniques', 'std::vector<int>') #Register the vector<PathData> container mod.add_container('std::vector<PathData>', 'PathData', 'vector') g2pklass = mod.add_class('PhonetisaurusScript') std_exception = mod.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()') g2pklass.add_constructor([param('std::string', 'model')], throw=[std_exception]) g2pklass.add_method('Phoneticize', retval('std::vector<PathData>'), [ param('std::string', 'word'), param('int', 'nbest'), param('int', 'beam'), param('float', 'threshold'), param('bool', 'write_fsts'), param('bool', 'accumulate'), param('float', 'pmass') ]) # Helper methods for the symbol lookup g2pklass.add_method('FindIsym', retval('std::string'), [param('int', 'symbol_id')]) g2pklass.add_method('FindIsym', retval('int'), [param('std::string', 'symbol')]) g2pklass.add_method('FindOsym', retval('std::string'),
def add_example(name): Example = module.add_class(name, template_parameters=[GridType], custom_name=name) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings'), param('const bool', 'enable_colors'), param('const std::string', 'info_color'), param('const std::string', 'debug_color'), param('const std::string', 'warn_color')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings'), param('const bool', 'enable_colors'), param('const std::string', 'info_color'), param('const std::string', 'debug_color')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings'), param('const bool', 'enable_colors'), param('const std::string', 'info_color')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings'), param('const bool', 'enable_colors')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements')], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning')], throw=exceptions) Example.add_constructor([], throw=exceptions) Example.add_method('discretization_and_return_ptr', retval(DiscretizationFullName + ' *', caller_owns_return=True), [], is_const=True, throw=exceptions, custom_name='discretization') Example.add_method('visualize', None, [param('const std::string&', 'filename_prefix')], is_const=True, throw=exceptions) Example.add_method('project', retval(VectorType), [param('const std::string', 'expression')], is_const=True, throw=exceptions) Example.add_method('compute_error', retval(RangeFieldType), [param('const ' + VectorType + '&', 'solution'), param('const std::string', 'product_type'), param('const Dune::Pymor::Parameter', 'mu'), param('const Dune::Pymor::Parameter', 'mu_product')], is_const=True, throw=exceptions) Example.add_method('compute_error', retval(RangeFieldType), [param('const ' + VectorType + '&', 'solution'), param('const std::string', 'product_type'), param('const Dune::Pymor::Parameter', 'mu')], is_const=True, throw=exceptions) Example.add_method('compute_error', retval(RangeFieldType), [param('const ' + VectorType + '&', 'solution'), param('const std::string', 'product_type')], is_const=True, throw=exceptions) Example.add_method('compute_error', retval(RangeFieldType), [param('const ' + VectorType + '&', 'solution')], is_const=True, throw=exceptions) Example.add_method('available_estimators', retval('std::vector< std::string >'), [], is_const=True, throw=exceptions) Example.add_method('estimate', retval(RangeFieldType), [param('const ' + VectorType + '&', 'vector'), param('const std::string', 'type'), param('const Dune::Pymor::Parameter', 'mu_hat'), param('const Dune::Pymor::Parameter', 'mu_bar'), param('const Dune::Pymor::Parameter', 'mu')], is_const=True, throw=exceptions) Example.add_method('estimate', retval(RangeFieldType), [param('const ' + VectorType + '&', 'vector'), param('const std::string', 'type')], is_const=True, throw=exceptions) Example.add_method('available_local_estimators', retval('std::vector< std::string >'), [], is_const=True, throw=exceptions) Example.add_method('estimate_local', retval('std::vector< ' + RangeFieldType + ' >'), [param('const ' + VectorType + '&', 'vector'), param('const std::string', 'type'), param('const Dune::Pymor::Parameter', 'mu_hat'), param('const Dune::Pymor::Parameter', 'mu_bar'), param('const Dune::Pymor::Parameter', 'mu')], is_const=True, throw=exceptions) Example.add_method('estimate_local', retval('std::vector< ' + RangeFieldType + ' >'), [param('const ' + VectorType + '&', 'vector'), param('const std::string', 'type')], is_const=True, throw=exceptions) Example.add_method('pb_project_global_to_oversampled', retval(VectorType + '*', caller_owns_return=True), [param('const ' + VectorType + '&', 'global_vector'), param('const ' + ssize_t, 'subdomain')], is_const=True, throw=exceptions, custom_name='project_global_to_oversampled') Example.add_method('pb_project_global_to_local', retval(VectorType + '*', caller_owns_return=True), [param('const ' + VectorType + '&', 'global_vector'), param('const ' + ssize_t, 'subdomain')], is_const=True, throw=exceptions, custom_name='project_global_to_local') Example.add_method('pb_project_oversampled_to_local', retval(VectorType + '*', caller_owns_return=True), [param('const ' + VectorType + '&', 'oversampled_vector'), param('const ' + ssize_t, 'subdomain')], is_const=True, throw=exceptions, custom_name='project_oversampled_to_local') Example.add_method('solve_for_local_correction', retval(VectorType), [param('std::vector< ' + VectorType + ' >&', 'local_vectors'), param('const ' + ssize_t, 'subdomain'), param('const Dune::Pymor::Parameter', 'mu')], is_const=True, throw=exceptions) Example.add_method('solve_for_local_correction', retval(VectorType), [param('std::vector< ' + VectorType + ' >&', 'local_vectors'), param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'subdomain')], is_const=True, throw=exceptions) Example.add_method('solve_oversampled', retval(VectorType), [param('const ' + ssize_t, 'subdomain'), param('const std::string&', 'boundary_value_type'), param('const ' + VectorType + '&', 'boundary_value_type'), param('const Dune::Pymor::Parameter', 'mu')], is_const=True, throw=exceptions) Example.add_method('solve_oversampled', retval(VectorType), [param('const ' + ssize_t, 'subdomain'), param('const std::string&', 'boundary_value_type'), param('const ' + VectorType + '&', 'boundary_value_type')], is_const=True, throw=exceptions) Example.add_method('visualize_on_coarse_grid', None, [param('const std::vector< double >&', 'vector'), param('const std::string&', 'filename'), param('const std::string&', 'name')], is_const=True, throw=exceptions) Example.add_method('alpha', retval(RangeFieldType), [param('const Dune::Pymor::Parameter&', 'mu_1'), param('const Dune::Pymor::Parameter&', 'mu_2')], is_const=True, throw=exceptions) Example.add_method('gamma', retval(RangeFieldType), [param('const Dune::Pymor::Parameter&', 'mu_1'), param('const Dune::Pymor::Parameter&', 'mu_2')], is_const=True, throw=exceptions)
# python build stubs for package interpreter # File is generated by gopy. Do not edit. # gopy build -output=interpreter github.com/google/cel-go/interpreter from pybindgen import retval, param, Module import sys mod = Module('_interpreter') mod.add_include('"interpreter_go.h"') mod.add_function('GoPyInit', None, []) mod.add_function('DecRef', None, [param('int64_t', 'handle')]) mod.add_function('IncRef', None, [param('int64_t', 'handle')]) mod.add_function('NumHandles', retval('int'), []) mod.add_function('Slice_bool_CTor', retval('int64_t'), []) mod.add_function('Slice_bool_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_bool_elem', retval('bool'), [param('int64_t', 'handle'), param('int', 'idx')]) mod.add_function( 'Slice_bool_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('bool', 'value')]) mod.add_function('Slice_bool_append', None, [param('int64_t', 'handle'), param('bool', 'value')]) mod.add_function('Slice_byte_CTor', retval('int64_t'), []) mod.add_function('Slice_byte_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_byte_elem', retval('uint8_t'), [param('int64_t', 'handle'), param('int', 'idx')])
def register_Ns3Ipv4GlobalRouting_methods(root_module, cls): ## ipv4-global-routing.h: ns3::Ipv4GlobalRouting::Ipv4GlobalRouting(ns3::Ipv4GlobalRouting const & arg0) [copy constructor] cls.add_constructor([param("ns3::Ipv4GlobalRouting const &", "arg0")]) ## ipv4-global-routing.h: ns3::Ipv4GlobalRouting::Ipv4GlobalRouting() [constructor] cls.add_constructor([]) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::AddASExternalRouteTo(ns3::Ipv4Address network, ns3::Ipv4Mask networkMask, ns3::Ipv4Address nextHop, uint32_t interface) [member function] cls.add_method( "AddASExternalRouteTo", "void", [ param("ns3::Ipv4Address", "network"), param("ns3::Ipv4Mask", "networkMask"), param("ns3::Ipv4Address", "nextHop"), param("uint32_t", "interface"), ], ) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::AddHostRouteTo(ns3::Ipv4Address dest, ns3::Ipv4Address nextHop, uint32_t interface) [member function] cls.add_method( "AddHostRouteTo", "void", [param("ns3::Ipv4Address", "dest"), param("ns3::Ipv4Address", "nextHop"), param("uint32_t", "interface")], ) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::AddHostRouteTo(ns3::Ipv4Address dest, uint32_t interface) [member function] cls.add_method("AddHostRouteTo", "void", [param("ns3::Ipv4Address", "dest"), param("uint32_t", "interface")]) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::AddNetworkRouteTo(ns3::Ipv4Address network, ns3::Ipv4Mask networkMask, ns3::Ipv4Address nextHop, uint32_t interface) [member function] cls.add_method( "AddNetworkRouteTo", "void", [ param("ns3::Ipv4Address", "network"), param("ns3::Ipv4Mask", "networkMask"), param("ns3::Ipv4Address", "nextHop"), param("uint32_t", "interface"), ], ) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::AddNetworkRouteTo(ns3::Ipv4Address network, ns3::Ipv4Mask networkMask, uint32_t interface) [member function] cls.add_method( "AddNetworkRouteTo", "void", [param("ns3::Ipv4Address", "network"), param("ns3::Ipv4Mask", "networkMask"), param("uint32_t", "interface")], ) ## ipv4-global-routing.h: uint32_t ns3::Ipv4GlobalRouting::GetNRoutes() [member function] cls.add_method("GetNRoutes", "uint32_t", []) ## ipv4-global-routing.h: ns3::Ipv4RoutingTableEntry * ns3::Ipv4GlobalRouting::GetRoute(uint32_t i) [member function] cls.add_method( "GetRoute", retval("ns3::Ipv4RoutingTableEntry *", caller_owns_return=False), [param("uint32_t", "i")] ) ## ipv4-global-routing.h: static ns3::TypeId ns3::Ipv4GlobalRouting::GetTypeId() [member function] cls.add_method("GetTypeId", "ns3::TypeId", [], is_static=True) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::NotifyAddAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] cls.add_method( "NotifyAddAddress", "void", [param("uint32_t", "interface"), param("ns3::Ipv4InterfaceAddress", "address")], is_virtual=True, ) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::NotifyInterfaceDown(uint32_t interface) [member function] cls.add_method("NotifyInterfaceDown", "void", [param("uint32_t", "interface")], is_virtual=True) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::NotifyInterfaceUp(uint32_t interface) [member function] cls.add_method("NotifyInterfaceUp", "void", [param("uint32_t", "interface")], is_virtual=True) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::NotifyRemoveAddress(uint32_t interface, ns3::Ipv4InterfaceAddress address) [member function] cls.add_method( "NotifyRemoveAddress", "void", [param("uint32_t", "interface"), param("ns3::Ipv4InterfaceAddress", "address")], is_virtual=True, ) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::RemoveRoute(uint32_t i) [member function] cls.add_method("RemoveRoute", "void", [param("uint32_t", "i")]) ## ipv4-global-routing.h: bool ns3::Ipv4GlobalRouting::RouteInput(ns3::Ptr<ns3::Packet const> p, ns3::Ipv4Header const & header, ns3::Ptr<const ns3::NetDevice> idev, ns3::Callback<void, ns3::Ptr<ns3::Ipv4Route>, ns3::Ptr<ns3::Packet const>, ns3::Ipv4Header const&, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty> ucb, ns3::Callback<void,ns3::Ptr<ns3::Ipv4MulticastRoute>,ns3::Ptr<const ns3::Packet>,const ns3::Ipv4Header&,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty> mcb, ns3::Callback<void,ns3::Ptr<const ns3::Packet>,const ns3::Ipv4Header&,unsigned int,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty,ns3::empty> lcb, ns3::Callback<void, ns3::Ptr<ns3::Packet const>, ns3::Ipv4Header const&, ns3::Socket::SocketErrno, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty> ecb) [member function] cls.add_method( "RouteInput", "bool", [ param("ns3::Ptr< ns3::Packet const >", "p"), param("ns3::Ipv4Header const &", "header"), param("ns3::Ptr< ns3::NetDevice const >", "idev"), param( "ns3::Callback< void, ns3::Ptr< ns3::Ipv4Route >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >", "ucb", ), param( "ns3::Callback< void, ns3::Ptr< ns3::Ipv4MulticastRoute >, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >", "mcb", ), param( "ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, unsigned int, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >", "lcb", ), param( "ns3::Callback< void, ns3::Ptr< ns3::Packet const >, ns3::Ipv4Header const &, ns3::Socket::SocketErrno, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty, ns3::empty >", "ecb", ), ], is_virtual=True, ) ## ipv4-global-routing.h: ns3::Ptr<ns3::Ipv4Route> ns3::Ipv4GlobalRouting::RouteOutput(ns3::Ptr<ns3::Packet> p, ns3::Ipv4Header const & header, ns3::Ptr<ns3::NetDevice> oif, ns3::Socket::SocketErrno & sockerr) [member function] cls.add_method( "RouteOutput", "ns3::Ptr< ns3::Ipv4Route >", [ param("ns3::Ptr< ns3::Packet >", "p"), param("ns3::Ipv4Header const &", "header"), param("ns3::Ptr< ns3::NetDevice >", "oif"), param("ns3::Socket::SocketErrno &", "sockerr"), ], is_virtual=True, ) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::SetIpv4(ns3::Ptr<ns3::Ipv4> ipv4) [member function] cls.add_method("SetIpv4", "void", [param("ns3::Ptr< ns3::Ipv4 >", "ipv4")], is_virtual=True) ## ipv4-global-routing.h: void ns3::Ipv4GlobalRouting::DoDispose() [member function] cls.add_method("DoDispose", "void", [], visibility="protected", is_virtual=True) return
def inject_VectorImplementation(module, exceptions, interfaces, CONFIG_H, name, Traits, template_parameters=None, provides_data=False): assert(isinstance(module, pybindgen.module.Module)) assert(isinstance(exceptions, list)) assert(isinstance(interfaces, dict)) for element in interfaces: assert(isinstance(element, str)) assert(len(element) > 0) assert(isinstance(CONFIG_H, dict)) assert(len(name.strip()) > 0) assert(isinstance(Traits, dict)) for key in Traits.keys(): assert(isinstance(Traits[key], str)) assert(len(Traits[key].strip()) > 0) assert('ThisType' in Traits) ThisType = Traits['ThisType'] assert('ScalarType' in Traits) ScalarType = Traits['ScalarType'] if template_parameters is not None: if isinstance(template_parameters, str): assert(len(template_parameters.strip()) > 0) template_parameters = [ template_parameters ] elif isinstance(template_parameters, list): for element in template_parameters: assert(isinstance(element, str)) assert(len(element.strip()) > 0) namespace = module namespaces = [nspace.strip() for nspace in name.split('::')[:-1]] name = name.split('::')[-1].strip() if len(namespaces) > 0: for nspace in namespaces: namespace = namespace.add_cpp_namespace(nspace) Class = namespace.add_class(name, parent=interfaces['Dune::Stuff::LA::Tags::VectorInterface'], template_parameters=template_parameters) Class.add_constructor([]) Class.add_constructor([param(CONFIG_H['DUNE_STUFF_SSIZE_T'], 'size')]) Class.add_constructor([param(CONFIG_H['DUNE_STUFF_SSIZE_T'], 'size'), param(ScalarType, 'value')]) Class.add_copy_constructor() # what we want from ContainerInterface Class.add_method('type_this', retval('std::string'), [], is_const=True, is_static=True, throw=exceptions) Class.add_method('copy', retval(ThisType), [], is_const=True, throw=exceptions) Class.add_method('scal', None, [param('const ' + ScalarType + ' &', 'alpha')], throw=exceptions) Class.add_method('axpy', None, [param('const ' + ScalarType + ' &', 'alpha'), param('const ' + ThisType + ' &', 'xx')], throw=exceptions) Class.add_method('has_equal_shape', 'bool', [param('const ' + ThisType + ' &', 'other')], is_const=True, throw=exceptions) Class.add_method('valid', 'bool', [], is_const=True, throw=exceptions) # what we want from ProvidesData interface if provides_data: Class.add_method('data', BufferReturn(ScalarType + ' *', 'self->obj->size() * sizeof(' + ScalarType + ')'), []) # what we want from VectorInterface Class.add_method('almost_equal', retval('bool'), [param('const ' + ThisType + ' &', 'other'), param('const ' + ScalarType, 'epsilon')], is_const=True, throw=exceptions) Class.add_method('almost_equal', retval('bool'), [param('const ' + ThisType + ' &', 'other')], is_const=True, throw=exceptions) Class.add_method('dot', retval(ScalarType), [param('const ' + ThisType + ' &', 'other')], is_const=True, throw=exceptions) Class.add_method('l1_norm', retval(ScalarType), [], is_const=True, throw=exceptions) Class.add_method('l2_norm', retval(ScalarType), [], is_const=True, throw=exceptions) Class.add_method('sup_norm', retval(ScalarType), [], is_const=True, throw=exceptions) Class.add_method('add', None, [param('const ' + ThisType + ' &', 'other'), param(ThisType + ' &', 'result')], is_const=True, throw=exceptions) Class.add_method('add', retval(ThisType), [param('const ' + ThisType + ' &', 'other')], is_const=True, throw=exceptions) Class.add_method('iadd', None, [param('const ' + ThisType + ' &', 'other')], throw=exceptions) Class.add_method('sub', None, [param('const ' + ThisType + ' &', 'other'), param(ThisType + ' &', 'result')], is_const=True, throw=exceptions) Class.add_method('sub', retval(ThisType), [param('const ' + ThisType + ' &', 'other')], is_const=True, throw=exceptions) Class.add_method('isub', None, [param('const ' + ThisType + ' &', 'other')], throw=exceptions) Class.add_method('pb_dim', retval(CONFIG_H['DUNE_STUFF_SSIZE_T']), [], is_const=True, throw=exceptions, custom_name='dim') Class.add_method('pb_add_to_entry', None, [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'ii'), param('const ' + ScalarType + ' &', 'value')], throw=exceptions, custom_name='add_to_entry') Class.add_method('pb_set_entry', None, [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'ii'), param('const ' + ScalarType + ' &', 'value')], throw=exceptions, custom_name='set_entry') Class.add_method('pb_get_entry', retval(ScalarType), [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'ii')], throw=exceptions, is_const=True, custom_name='get_entry') Class.add_method('pb_amax', retval('std::vector< ' + ScalarType + ' >'), [], is_const=True, throw=exceptions, custom_name='amax') Class.add_method('max', retval(ScalarType), [], is_const=True, throw=exceptions) Class.add_method('min', retval(ScalarType), [], is_const=True, throw=exceptions) Class.add_method('mean', retval(ScalarType), [], is_const=True, throw=exceptions) Class.add_method('components', retval('std::vector< ' + ScalarType + ' >'), [param('const std::vector< ' + CONFIG_H['DUNE_STUFF_SSIZE_T'] + '> &', 'component_indices')], is_const=True, throw=exceptions) return module, Class
# python build stubs for package ext # File is generated by gopy. Do not edit. # gopy build -output=ext github.com/google/cel-go/ext from pybindgen import retval, param, Module import sys mod = Module('_ext') mod.add_include('"ext_go.h"') mod.add_function('GoPyInit', None, []) mod.add_function('DecRef', None, [param('int64_t', 'handle')]) mod.add_function('IncRef', None, [param('int64_t', 'handle')]) mod.add_function('NumHandles', retval('int'), []) mod.add_function('Slice_bool_CTor', retval('int64_t'), []) mod.add_function('Slice_bool_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_bool_elem', retval('bool'), [param('int64_t', 'handle'), param('int', 'idx')]) mod.add_function('Slice_bool_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('bool', 'value')]) mod.add_function('Slice_bool_append', None, [param('int64_t', 'handle'), param('bool', 'value')]) mod.add_function('Slice_byte_CTor', retval('int64_t'), []) mod.add_function('Slice_byte_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_byte_elem', retval('uint8_t'), [param('int64_t', 'handle'), param('int', 'idx')]) mod.add_function('Slice_byte_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('uint8_t', 'value')]) mod.add_function('Slice_byte_append', None, [param('int64_t', 'handle'), param('uint8_t', 'value')]) mod.add_function('Slice_float32_CTor', retval('int64_t'), []) mod.add_function('Slice_float32_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_float32_elem', retval('float'), [param('int64_t', 'handle'), param('int', 'idx')]) mod.add_function('Slice_float32_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('float', 'value')]) mod.add_function('Slice_float32_append', None, [param('int64_t', 'handle'), param('float', 'value')]) mod.add_function('Slice_float64_CTor', retval('int64_t'), []) mod.add_function('Slice_float64_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_float64_elem', retval('double'), [param('int64_t', 'handle'), param('int', 'idx')])
def reg_NfdFaceTable(root_module, cls): cls.add_method('size', retval('size_t'), [], is_const=True) cls.add_container_traits(retval('const ns3::ndn::nfd::Face&', caller_manages_return=False), begin_method='begin', end_method='end', iterator_type='const_iterator')
def reg_NfdFib(root_module, cls): cls.add_method('size', retval('size_t'), [], is_const=True) cls.add_container_traits(retval('const ns3::ndn::nfd::fib::Entry&', caller_manages_return=False), begin_method='begin', end_method='end', iterator_type='const_iterator') # The following is not supported # cls.add_method('findLongestPrefixMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'), # [param('const ns3::ndn::Name&', 'prefix')], is_const=True) # cls.add_method('findExactMatch', retval('std::shared_ptr<ns3::ndn::nfd::fib::Entry>'), # [param('const ns3::ndn::Name&', 'prefix')], is_const=True) # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'), # [param('const pit::Entry&', 'pitEntry')], is_const=True) # cls.add_method('findLongestPrefixMatch', retval('shared_ptr<ns3::ndn::nfd::fib::Entry>'), # [param('const measurements::Entry&', 'measurementsEntry')], is_const=True) # cls.add_method('insert', retval('std::pair<std::shared_ptr<ns3::ndn::nfd::fib::Entry>, bool>'), [param('const ns3::ndn::Name&', 'prefix')]) cls.add_method('erase', retval('void'), [param('const ns3::ndn::Name&', 'prefix')]) cls.add_method('erase', retval('void'), [param('const ns3::ndn::nfd::fib::Entry&', 'entry')]) # cls.add_method('removeNextHopFromAllEntries', retval('void'), [param('std::shared_ptr<ns3::ndn::Face>', 'face')]) def reg_Entry(cls): cls.add_method('getPrefix', 'const ns3::ndn::Name&', [], is_const=True) cls.add_method('getNextHops', retval('const ns3::ndn::nfd::fib::NextHopList&', caller_manages_return=False), [], is_const=True) cls.add_method('hasNextHops', 'bool', [], is_const=True) reg_Entry(root_module['ns3::ndn::nfd::fib::Entry']) def reg_NextHop(cls): cls.add_constructor([param('const ns3::ndn::Face&', 'face')]) cls.add_function_as_method( 'getFaceFromFibNextHop', 'std::shared_ptr<ns3::ndn::Face>', [param('const ns3::ndn::nfd::fib::NextHop&', 'obj')], custom_name='getFace') cls.add_method('setCost', 'void', [param('uint64_t', 'cost')]) cls.add_method('getCost', 'uint64_t', [], is_const=True) reg_NextHop(root_module['ns3::ndn::nfd::fib::NextHop']) def reg_NextHopList(cls): cls.add_method('size', retval('size_t'), [], is_const=True) cls.add_container_traits(retval( 'const ns3::ndn::nfd::fib::NextHop&', caller_manages_return=False), begin_method='begin', end_method='end', iterator_type='const_iterator') reg_NextHopList(root_module['ns3::ndn::nfd::fib::NextHopList'])
def reg_Face(cls): cls.add_output_stream_operator() cls.add_method('getId', retval('int64_t'), [], is_const=True)
import pybindgen import sys mod = pybindgen.Module('TestModule') mod.add_include('"test.h"') ## no params no return # mod.add_function('test_func', None, []) ## return value and multiple params # modd.add_function('test_func', pybindgen.retval('int'), [pybindgen.param('int', 'a'), pybindgen.param('int', 'b')]) ## param and return pointer mod.add_function('test_func', pybindgen.retval('char*', caller_owns_return=False), [pybindgen.param('char*', 'txt', transfer_ownership=False)]) mod.generate(sys.stdout)
def reg_Entry(cls): cls.add_method('getName', retval('const ns3::ndn::Name&'), [], is_const=True)
'vector') # declare a container only once Vector = mod.add_class('Vector') Vector.add_constructor( [pybindgen.param('int', 'size'), pybindgen.param('double', 'value')]) Vector.add_constructor([pybindgen.param('const Vector&', 'othter')]) Vector.add_instance_attribute('dim', 'int', is_const=True) Vector.add_method('scal', None, [pybindgen.param('double', 'val')]) Vector.add_method( 'axpy', None, [pybindgen.param('double', 'a'), pybindgen.param('const Vector&', 'x')]) Vector.add_method('dot', pybindgen.retval('double'), [pybindgen.param('const Vector&', 'other')], is_const=True) Vector.add_method('data', BufferReturn('double*', 'self->obj->dim * sizeof(double)'), []) DiffusionOperator = mod.add_class('DiffusionOperator') DiffusionOperator.add_constructor([ pybindgen.param('int', 'n'), pybindgen.param('double', 'left'), pybindgen.param('double', 'right') ]) DiffusionOperator.add_instance_attribute('dim_source', 'int', is_const=True) DiffusionOperator.add_instance_attribute('dim_range', 'int', is_const=True) DiffusionOperator.add_method(
def my_module_gen(out_file): mod = Module('foo') foomodulegen_common.customize_module_pre(mod) mod.add_include('"foo.h"') mod.add_function('TypeNameGet', 'std::string', [], custom_name='IntegerTypeNameGet', template_parameters=['int']) Foo = mod.add_class('Foo', automatic_type_narrowing=True) Foo.add_static_attribute('instance_count', ReturnValue.new('int')) Foo.add_constructor([Parameter.new('std::string', 'datum')]) Foo.add_constructor([]) Foo.add_constructor([Parameter.new('const Foo&', 'foo')]) Foo.add_method('get_datum', ReturnValue.new('const std::string'), []) Foo.add_method('is_initialized', ReturnValue.new('bool'), [], is_const=True) Foo.add_output_stream_operator() Foo.add_method('add_sub', ReturnValue.new('int'), [ Parameter.new('int', 'a'), Parameter.new('int', 'b', default_value='3'), Parameter.new('bool', 'subtract', default_value='false') ], is_static=True) Foo.add_custom_instance_attribute("is_unique", "bool", getter="is_unique", is_const=True) Zoo = mod.add_class('Zoo', automatic_type_narrowing=True) Zoo.add_constructor([Parameter.new('std::string', 'datum')]) Zoo.add_constructor([]) Zoo.add_method('get_datum', ReturnValue.new('std::string'), []) Zoo.implicitly_converts_to(Foo) Foobar = mod.add_class('Foobar', allow_subclassing=True) Foobar.add_static_attribute('instance_count', ReturnValue.new('int')) Bar = mod.add_class('Bar', parent=Foo) Bar.inherit_default_constructors() ## a static method.. Bar.add_method('Hooray', ReturnValue.new('std::string'), [], is_static=True) ## to test RTTI with a hidden subclass mod.add_function('get_hidden_subclass_pointer', ReturnValue.new('Foo*', caller_owns_return=True), []) ## Zbr is a reference counted class Zbr = mod.add_class('Zbr', memory_policy=cppclass.ReferenceCountingMethodsPolicy( incref_method='Ref', decref_method='Unref', peekref_method="GetReferenceCount"), allow_subclassing=True) def helper_class_hook(helper_class): helper_class.add_custom_method( declaration="static int custom_method_added_by_a_hook(int x);", body=""" int %s::custom_method_added_by_a_hook(int x) { return x + 1; } """ % helper_class.name) helper_class.add_post_generation_code( "// this comment was written by a helper class hook function") Zbr.add_helper_class_hook(helper_class_hook) Zbr.add_constructor([]) Zbr.add_constructor([Parameter.new('std::string', 'datum')]) Zbr.add_method('get_datum', ReturnValue.new('std::string'), []) Zbr.add_method('get_int', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_virtual=True) Zbr.add_static_attribute('instance_count', ReturnValue.new('int')) Zbr.add_method( 'get_value', ReturnValue.new('int'), [Parameter.new('int*', 'x', direction=Parameter.DIRECTION_OUT)]) mod.add_function('store_zbr', None, [Parameter.new('Zbr*', 'zbr', transfer_ownership=True)]) mod.add_function('invoke_zbr', ReturnValue.new('int'), [Parameter.new('int', 'x')]) mod.add_function('delete_stored_zbr', None, []) mod.add_function('print_something', ReturnValue.new('int'), [Parameter.new('const char*', 'message')], deprecated=True) mod.add_function('print_something_else', ReturnValue.new('int'), [Parameter.new('const char*', 'message2')]) ## test overloaded functions mod.add_function('get_int_from_string', ReturnValue.new('int'), [ Parameter.new('const char*', 'from_string'), Parameter.new('int', 'multiplier', default_value='1') ], custom_name="get_int") mod.add_function('get_int_from_float', ReturnValue.new('int'), [ Parameter.new('double', 'from_float'), Parameter.new('int', 'multiplier', default_value='1') ], custom_name="get_int") SomeObject = mod.add_class('SomeObject', allow_subclassing=True) SomeObject.add_instance_attribute('foo', ReturnValue.new('Foo'), getter='get_foo_value', setter='set_foo_value') SomeObject.add_instance_attribute('m_prefix', ReturnValue.new('std::string')) SomeObject.add_static_attribute('staticData', ReturnValue.new('std::string')) SomeObject.add_static_attribute('instance_count', ReturnValue.new('int')) SomeObject.add_method('add_prefix', ReturnValue.new('int'), [ Parameter.new( 'std::string&', 'message', direction=Parameter.DIRECTION_INOUT) ]) SomeObject.add_constructor([Parameter.new('std::string', 'prefix')]) SomeObject.add_constructor([Parameter.new('int', 'prefix_len')]) SomeObject.add_method( 'operator()', ReturnValue.new('int'), [ Parameter.new( 'std::string&', 'message', direction=Parameter.DIRECTION_INOUT) ], custom_name='__call__') # --- some virtual methods --- SomeObject.add_method('get_prefix', ReturnValue.new('std::string'), [], is_virtual=True, is_const=True) SomeObject.add_method('get_prefix_with_foo_value', ReturnValue.new('std::string'), [Parameter.new('Foo', 'foo')], is_virtual=True, is_const=True) SomeObject.add_method( 'get_prefix_with_foo_ref', ReturnValue.new('std::string'), [ Parameter.new( 'const Foo&', 'foo', direction=Parameter.DIRECTION_INOUT) ], is_virtual=True, is_const=True) SomeObject.add_method( 'get_prefix_with_foo_ptr', ReturnValue.new('std::string'), [Parameter.new('const Foo*', 'foo', transfer_ownership=False)], is_virtual=True, is_const=True) ## overloaded virtual methods SomeObject.add_method('get_something', ReturnValue.new('std::string'), [], is_virtual=True, is_const=True) SomeObject.add_method('get_something', ReturnValue.new('std::string'), [Parameter.new('int', 'x')], is_virtual=True, is_const=True) SomeObject.add_method( 'set_pyobject', None, [Parameter.new('PyObject*', 'pyobject', transfer_ownership=False)], is_virtual=True) SomeObject.add_method('get_pyobject', ReturnValue.new('PyObject*', caller_owns_return=True), [], is_virtual=True) ## add a function that appears as a method of an object SomeObject.add_function_as_method( 'some_object_get_something_prefixed', ReturnValue.new('std::string'), [ Parameter.new('const SomeObject*', 'obj', transfer_ownership=False), Parameter.new('std::string', 'something') ], custom_name='get_something_prefixed') ## add a function that appears as a method of an object SomeObject.add_function_as_method( 'some_object_val_get_something_prefixed', ReturnValue.new('std::string'), [ Parameter.new('SomeObject', 'obj'), Parameter.new('std::string', 'something') ], custom_name='val_get_something_prefixed') ## add a function that appears as a method of an object SomeObject.add_function_as_method( 'some_object_ref_get_something_prefixed', ReturnValue.new('std::string'), [ Parameter.new('const SomeObject&', 'obj'), Parameter.new('std::string', 'something') ], custom_name='ref_get_something_prefixed') # --- SomeObject.add_method('call_get_prefix', ReturnValue.new('std::string'), []) SomeObject.add_method('set_foo_value', None, [Parameter.new('Foo', 'foo')]) SomeObject.add_method('get_foo_value', ReturnValue.new('Foo'), []) SomeObject.add_method( 'set_foo_ptr', ReturnValue.new('void'), [Parameter.new('Foo*', 'foo', transfer_ownership=True)]) SomeObject.add_method( 'set_foo_shared_ptr', ReturnValue.new('void'), [Parameter.new('Foo*', 'foo', transfer_ownership=False)]) SomeObject.add_method( 'get_foo_shared_ptr', ReturnValue.new('const Foo*', caller_owns_return=False), []) SomeObject.add_method('get_foo_ptr', ReturnValue.new('Foo*', caller_owns_return=True), []) SomeObject.add_method( 'set_foo_by_ref', ReturnValue.new('void'), [Parameter.new('Foo&', 'foo', direction=Parameter.DIRECTION_IN)]) SomeObject.add_method( 'get_foo_by_ref', ReturnValue.new('void'), [Parameter.new('Foo&', 'foo', direction=Parameter.DIRECTION_OUT)]) ## custodian/ward tests SomeObject.add_method( 'get_foobar_with_self_as_custodian', ReturnValue.new('Foobar*', custodian=0, reference_existing_object=True), []) SomeObject.add_method( 'get_foobar_with_other_as_custodian', ReturnValue.new('Foobar*', custodian=1, reference_existing_object=True), [Parameter.new('SomeObject*', 'other', transfer_ownership=False)]) SomeObject.add_method( 'set_foobar_with_self_as_custodian', ReturnValue.new('void'), [ Parameter.new( 'Foobar*', 'foobar', transfer_ownership=True, custodian=0) ]) mod.add_function( 'get_foobar_with_other_as_custodian', ReturnValue.new('Foobar*', custodian=1, reference_existing_object=True), [Parameter.new('SomeObject*', 'other', transfer_ownership=False)]) mod.add_function('create_new_foobar', ReturnValue.new('Foobar*', caller_owns_return=True), []) mod.add_function( 'set_foobar_with_other_as_custodian', ReturnValue.new('void'), [ Parameter.new( 'Foobar*', 'foobar', transfer_ownership=True, custodian=2), Parameter.new('SomeObject*', 'other', transfer_ownership=False) ]) mod.add_function( 'set_foobar_with_return_as_custodian', ReturnValue.new('SomeObject*', caller_owns_return=True), [ Parameter.new( 'Foobar*', 'foobar', transfer_ownership=True, custodian=-1) ]) ## get/set recfcounted object Zbr SomeObject.add_method('get_zbr', ReturnValue.new('Zbr*', caller_owns_return=True), []) SomeObject.add_method('get_internal_zbr', ReturnValue.new('Zbr*', caller_owns_return=True), []) SomeObject.add_method('peek_zbr', ReturnValue.new('Zbr*', caller_owns_return=False), []) SomeObject.add_method( 'set_zbr_transfer', ReturnValue.new('void'), [Parameter.new('Zbr*', 'zbr', transfer_ownership=True)]) SomeObject.add_method( 'set_zbr_shared', ReturnValue.new('void'), [Parameter.new('Zbr*', 'zbr', transfer_ownership=False)]) ## methods with transformed types SomeObject.add_method('set_zbr_pholder', ReturnValue.new('void'), [Parameter.new('PointerHolder<Zbr>', 'zbr')]) SomeObject.add_method('get_zbr_pholder', ReturnValue.new('PointerHolder<Zbr>'), []) ## test overloaded methods SomeObject.add_method('get_int', ReturnValue.new('int'), [Parameter.new('const char*', 'from_string')], custom_name="get_int") SomeObject.add_method('get_int', ReturnValue.new('int'), [Parameter.new('double', 'from_float')], custom_name="get_int") # Bug #508577 SomeObject.add_method('protected_method_that_is_not_virtual', ReturnValue.new('std::string'), [Parameter.new('std::string', 'arg')], is_const=True, visibility='protected') SomeObject.add_method('method_returning_cstring', ReturnValue.new('const char *'), [], is_virtual=True, is_const=True) mod.add_function( 'store_some_object', ReturnValue.new('void'), [Parameter.new('SomeObject*', 'obj', transfer_ownership=True)]) mod.add_function('invoke_some_object_get_prefix', ReturnValue.new('std::string'), []) mod.add_function('take_some_object', ReturnValue.new('SomeObject*', caller_owns_return=True), []) mod.add_function('delete_some_object', ReturnValue.new('void'), []) xpto = mod.add_cpp_namespace("xpto") xpto.add_function('some_function', ReturnValue.new('std::string'), []) ## enums.. xpto.add_enum('FooType', ['FOO_TYPE_AAA', 'FOO_TYPE_BBB', 'FOO_TYPE_CCC']) xpto.add_function('get_foo_type', ReturnValue.new('FooType'), []) xpto.add_function('set_foo_type', ReturnValue.new('void'), [Parameter.new("FooType", 'type')]) xpto.add_function('set_foo_type_inout', ReturnValue.new('void'), [ Parameter.new("FooType&", 'type', direction=Parameter.DIRECTION_INOUT) ]) xpto.add_function('set_foo_type_ptr', ReturnValue.new('void'), [ Parameter.new("FooType*", 'type', direction=Parameter.DIRECTION_INOUT) ]) xpto_SomeClass = xpto.add_class( 'SomeClass', docstring="This is the docstring for SomeClass") xpto_SomeClass.add_constructor([]) xpto.add_typedef(Foo, 'FooXpto') xpto.add_function('get_foo_datum', 'std::string', [Parameter.new('const xpto::FooXpto&', 'foo')]) typehandlers.add_type_alias('uint32_t', 'xpto::FlowId') xpto.add_function('get_flow_id', 'xpto::FlowId', [Parameter.new('xpto::FlowId', 'flowId')]) # bug #798383 XptoClass = xpto.add_struct('XptoClass') XptoClass.add_method("GetSomeClass", retval("xpto::SomeClass*", caller_owns_return=True), []) ## ---- some implicity conversion APIs mod.add_function('function_that_takes_foo', ReturnValue.new('void'), [Parameter.new('Foo', 'foo')]) mod.add_function('function_that_returns_foo', ReturnValue.new('Foo'), []) cls = mod.add_class('ClassThatTakesFoo') cls.add_constructor([Parameter.new('Foo', 'foo')]) cls.add_method('get_foo', ReturnValue.new('Foo'), []) cls = mod.add_class('SingletonClass', is_singleton=True) cls.add_method('GetInstance', ReturnValue.new('SingletonClass*', caller_owns_return=True), [], is_static=True) ## A class that has no public default constructor... cls = mod.add_class('InterfaceId', is_singleton=True) ## A function that returns such a class... mod.add_function('make_interface_id', ReturnValue.new('InterfaceId'), []) ## A class the cannot be constructed; this will cause late CodeGenerationError's cls = mod.add_class('CannotBeConstructed') cls.set_cannot_be_constructed("no reason") cls.add_method('get_value', ReturnValue.new('CannotBeConstructed'), [], is_static=True) cls.add_method('get_ptr', ReturnValue.new('CannotBeConstructed*', caller_owns_return=True), [], is_static=True) mod.add_function('get_cannot_be_constructed_value', ReturnValue.new('CannotBeConstructed'), []) mod.add_function( 'get_cannot_be_constructed_ptr', ReturnValue.new('CannotBeConstructed*', caller_owns_return=True), []) ## A nested class #NestedClass = mod.add_class('NestedClass', automatic_type_narrowing=True, outer_class=SomeObject) NestedClass = SomeObject.add_class('NestedClass', automatic_type_narrowing=True) NestedClass.add_static_attribute('instance_count', ReturnValue.new('int')) NestedClass.add_constructor([Parameter.new('std::string', 'datum')]) NestedClass.add_constructor([]) NestedClass.add_method('get_datum', ReturnValue.new('std::string'), []) ## A nested enum.. #mod.add_enum('NestedEnum', ['FOO_TYPE_AAA', 'FOO_TYPE_BBB', 'FOO_TYPE_CCC'], outer_class=SomeObject) SomeObject.add_enum('NestedEnum', ['FOO_TYPE_AAA', 'FOO_TYPE_BBB', 'FOO_TYPE_CCC']) ## anonymous enum SomeObject.add_enum('', ['CONSTANT_A', 'CONSTANT_B', 'CONSTANT_C']) AbstractBaseClass2 = mod.add_class('AbstractBaseClass2', allow_subclassing=True) AbstractBaseClass2.add_method('invoke_private_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_const=True) AbstractBaseClass2.add_method('invoke_protected_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_const=True) AbstractBaseClass2.add_method('invoke_protected_pure_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_const=True) AbstractBaseClass2.add_constructor([], visibility='protected') AbstractBaseClass2.add_method('protected_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_virtual=True, visibility='protected', is_const=True) AbstractBaseClass2.add_method('protected_pure_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_virtual=True, is_pure_virtual=True, visibility='protected', is_const=True) AbstractBaseClass2.add_method('private_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_virtual=True, is_pure_virtual=True, visibility='private', is_const=True) AbstractXpto = mod.add_class('AbstractXpto', allow_subclassing=True) AbstractXpto.add_method('something', ReturnValue.new('void'), [Parameter.new('int', 'x')], is_const=True, is_virtual=True, is_pure_virtual=True) AbstractXpto.add_constructor([]) AbstractXptoImpl = mod.add_class('AbstractXptoImpl', parent=AbstractXpto) AbstractXptoImpl.add_method('something', ReturnValue.new('void'), [Parameter.new('int', 'x')], is_const=True, is_virtual=True, is_pure_virtual=False) AbstractXptoImpl.add_constructor([]) Word = mod.add_class('Word') Word.add_instance_attribute('low', 'uint8_t', is_const=False) Word.add_instance_attribute('high', 'uint8_t', is_const=False) Word.add_instance_attribute('word', 'uint16_t', is_const=False) Word.add_constructor([]) mod.add_function('matrix_sum_of_elements', ReturnValue.new('float'), [ Parameter.new("float*", 'matrix', direction=Parameter.DIRECTION_IN, array_length=6) ]) mod.add_function('matrix_identity_new', ReturnValue.new('void'), [ Parameter.new("float*", 'matrix', direction=Parameter.DIRECTION_OUT, array_length=6) ]) top_ns = mod.add_cpp_namespace('TopNs') outer_base = top_ns.add_class('OuterBase') bottom_ns = top_ns.add_cpp_namespace('PrefixBottomNs') inner = bottom_ns.add_class('PrefixInner', parent=outer_base) inner.add_constructor([]) inner.add_method('Do', 'void', []) Socket = mod.add_class('Socket', allow_subclassing=True) Socket.add_constructor([]) Socket.add_method('Bind', ReturnValue.new('int'), [], is_virtual=True) Socket.add_method('Bind', ReturnValue.new('int'), [Parameter.new('int', 'address')], is_virtual=True) UdpSocket = mod.add_class('UdpSocket', parent=Socket) UdpSocket.add_constructor([]) UdpSocket.add_method('Bind', ReturnValue.new('int'), [], is_virtual=True) simple_struct_t = mod.add_struct('simple_struct_t') simple_struct_t.add_instance_attribute('xpto', 'int') # containers... mod.add_container('SimpleStructList', ReturnValue.new('simple_struct_t'), 'list') mod.add_function('get_simple_list', ReturnValue.new('SimpleStructList'), []) mod.add_function('set_simple_list', 'int', [Parameter.new('SimpleStructList', 'list')]) mod.add_container('std::set<float>', 'float', 'set') TestContainer = mod.add_class('TestContainer', allow_subclassing=True) TestContainer.add_constructor([]) TestContainer.add_instance_attribute('m_floatSet', 'std::set<float>') TestContainer.add_method('get_simple_list', ReturnValue.new('SimpleStructList'), [], is_virtual=True) TestContainer.add_method('set_simple_list', 'int', [Parameter.new('SimpleStructList', 'list')], is_virtual=True) TestContainer.add_method( 'set_simple_list_by_ref', 'int', [ Parameter.new('SimpleStructList&', 'inout_list', direction=Parameter.DIRECTION_INOUT) ], is_virtual=True) mod.add_container('std::vector<simple_struct_t>', ReturnValue.new('simple_struct_t'), 'vector') TestContainer.add_method('get_simple_vec', ReturnValue.new('std::vector<simple_struct_t>'), [], is_virtual=True) TestContainer.add_method( 'set_simple_vec', 'int', [Parameter.new('std::vector<simple_struct_t>', 'vec')], is_virtual=True) mod.add_container('std::vector<std::string>', 'std::string', 'vector') TestContainer.add_method('get_vec', 'void', [ Parameter.new('std::vector<std::string> &', 'outVec', direction=Parameter.DIRECTION_OUT) ]) TestContainer.add_method('set_vec_ptr', 'void', [ Parameter.new('std::vector<std::string>*', 'inVec', direction=Parameter.DIRECTION_IN, transfer_ownership=True) ]) TestContainer.add_method('get_vec_ptr', 'void', [ Parameter.new('std::vector<std::string>*', 'outVec', direction=Parameter.DIRECTION_OUT) ]) mod.add_container( 'std::map<std::string, simple_struct_t>', (ReturnValue.new('std::string'), ReturnValue.new('simple_struct_t')), 'map') TestContainer.add_method( 'get_simple_map', ReturnValue.new('std::map<std::string, simple_struct_t>'), [], is_virtual=True) TestContainer.add_method( 'set_simple_map', 'int', [Parameter.new('std::map<std::string, simple_struct_t>', 'map')], is_virtual=True) Tupl = mod.add_class('Tupl') Tupl.add_binary_comparison_operator('<') Tupl.add_binary_comparison_operator('<=') Tupl.add_binary_comparison_operator('>=') Tupl.add_binary_comparison_operator('>') Tupl.add_binary_comparison_operator('==') Tupl.add_binary_comparison_operator('!=') Tupl.add_binary_numeric_operator('+') Tupl.add_binary_numeric_operator('-') Tupl.add_binary_numeric_operator('*') Tupl.add_binary_numeric_operator('/') Tupl.add_instance_attribute('x', 'int', is_const=False) Tupl.add_instance_attribute('y', 'int', is_const=False) Tupl.add_constructor([Parameter.new('Tupl const &', 'arg0')]) Tupl.add_constructor([]) Tupl.add_inplace_numeric_operator('+=') Tupl.add_inplace_numeric_operator('-=') Tupl.add_inplace_numeric_operator('*=') Tupl.add_inplace_numeric_operator('/=') Tupl.add_unary_numeric_operator('-') Tupl.add_inplace_numeric_operator('+=', right='int') ManipulatedObject = mod.add_class('ManipulatedObject') ManipulatedObject.add_constructor([]) ManipulatedObject.add_method('GetValue', 'int', [], is_const=True) ManipulatedObject.add_method('SetValue', 'void', [Parameter.new('int', 'value')]) ReferenceManipulator = mod.add_class('ReferenceManipulator', allow_subclassing=True) ReferenceManipulator.add_constructor([]) ReferenceManipulator.add_method('manipulate_object', 'int', []) ReferenceManipulator.add_method( 'do_manipulate_object', 'void', [ Parameter.new('ManipulatedObject&', 'obj', direction=Parameter.DIRECTION_INOUT) ], is_virtual=True, is_pure_virtual=True) VectorLike = mod.add_class('VectorLike') VectorLike.add_constructor([]) VectorLike.add_constructor([Parameter.new("VectorLike&", "obj")]) VectorLike.add_method('get_len', 'size_t', [], custom_name='__len__') VectorLike.add_method('add_VectorLike', 'VectorLike', [Parameter.new('VectorLike', 'rhs')], custom_name='__add__') VectorLike.add_method('iadd_VectorLike', 'VectorLike', [Parameter.new('VectorLike', 'rhs')], custom_name='__iadd__') VectorLike.add_method('mul_VectorLike', 'VectorLike', [Parameter.new('unsigned int', 'n')], custom_name='__mul__') VectorLike.add_method('imul_VectorLike', 'VectorLike', [Parameter.new('unsigned int', 'n')], custom_name='__imul__') VectorLike.add_method( 'set_item', 'int', [Parameter.new('int', 'index'), Parameter.new('double', 'value')], custom_name='__setitem__') VectorLike.add_method('get_item', 'double', [Parameter.new('int', 'index')], custom_name='__getitem__') VectorLike.add_method('set_slice', 'int', [ Parameter.new('int', 'index1'), Parameter.new('int', 'index2'), Parameter.new('VectorLike', 'values') ], custom_name='__setslice__') VectorLike.add_method( 'get_slice', 'VectorLike', [Parameter.new('int', 'index1'), Parameter.new('int', 'index2')], custom_name='__getslice__') VectorLike.add_method('contains_value', 'int', [Parameter.new('double', 'value')], custom_name='__contains__') VectorLike.add_method('append', 'void', [Parameter.new('double', 'value')]) VectorLike2 = mod.add_class('VectorLike2') VectorLike2.add_constructor([]) VectorLike2.add_method('append', 'void', [Parameter.new('double', 'value')]) MapLike = mod.add_class('MapLike') MapLike.add_constructor([]) MapLike.add_method( 'set', 'void', [Parameter.new('int', 'key'), Parameter.new('double', 'value')]) Error = mod.add_exception('Error') DomainError = mod.add_exception('DomainError', parent=Error) mod.add_function('my_inverse_func', 'double', [Parameter.new('double', 'x')], throw=[DomainError]) ClassThatThrows = mod.add_class('ClassThatThrows', allow_subclassing=True) ClassThatThrows.add_constructor([Parameter.new('double', 'x')], throw=[DomainError]) ClassThatThrows.add_method('my_inverse_method', 'double', [Parameter.new('double', 'x')], throw=[DomainError]) std_exception = mod.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()') mod.add_function('my_inverse_func2', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) ClassThatThrows.add_method('my_inverse_method2', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) mod.add_function('my_inverse_func3', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) ClassThatThrows.add_method('my_inverse_method3', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) ClassThatThrows.add_method('throw_error', 'int', [], throw=[mod["out_of_range"]], is_const=True, is_virtual=True) ClassThatThrows.add_method('throw_out_of_range', 'int', [], throw=[mod["out_of_range"]]) # https://bugs.launchpad.net/pybindgen/+bug/450255 ProtectedConstructor = mod.add_class('ProtectedConstructor') ProtectedConstructor.add_constructor([]) ProtectedConstructor.add_constructor( [Parameter.new('ProtectedConstructor&', 'c')], visibility='protected') # https://bugs.launchpad.net/pybindgen/+bug/455689 property_std_string = mod.add_struct('property', template_parameters=['std::string']) Box = mod.add_class('Box') Box.add_constructor([]) Box.add_static_attribute('instance_count', ReturnValue.new('int')) Box.add_method( 'getFoobarInternalPtr', ReturnValue.new('const Foobar*', reference_existing_object=True), []) Box.add_method('getFoobarInternalRef', ReturnValue.new('Foobar&', reference_existing_object=True), []) Box.add_method('getFoobarInternalPtr2', ReturnValue.new('Foobar*', return_internal_reference=True), []) Box.add_method('getFoobarInternalRef2', ReturnValue.new('Foobar&', return_internal_reference=True), []) Box.add_instance_attribute( 'm_internalFoobar', ReturnValue.new('Foobar*', reference_existing_object=True)) # multiple inheritance MIRoot = mod.add_class('MIRoot') MIRoot.add_constructor([]) MIRoot.add_method('root_method', 'int', [], is_const=True) MIBase1 = mod.add_class('MIBase1', parent=MIRoot) MIBase1.add_constructor([]) MIBase1.add_method('base1_method', 'int', [], is_const=True) MIBase2 = mod.add_class('MIBase2', parent=MIRoot) MIBase2.add_constructor([]) MIBase2.add_method('base2_method', 'int', [], is_const=True) MIMixed = mod.add_class('MIMixed', parent=[MIBase1, MIBase2]) MIMixed.add_constructor([]) MIMixed.add_method('mixed_method', 'int', [], is_const=True) mod.add_function('my_throwing_func', 'Tupl', [], throw=[std_exception]) IFoo = mod.add_class("IFoo", destructor_visibility='protected', allow_subclassing=True) IFoo.add_method("DoSomething", None, [], is_pure_virtual=True) IFooImpl = mod.add_class("IFooImpl", parent=IFoo, destructor_visibility='public') IFooImpl.add_constructor([]) IFooImpl.add_method("DoSomething", None, [], is_virtual=True) mod.add_function( "test_args_kwargs", "int", [param("const char *", "args"), param("const char *", "kwargs")]) # https://github.com/gjcarneiro/pybindgen/issues/21 cls = mod.add_class('RAStruct') cls.add_constructor([]) cls.add_constructor([param('RAStruct const &', 'arg0')]) cls.add_instance_attribute('a', 'int', is_const=False) cls = mod.add_class('ReturnConstRef', allow_subclassing=True) cls.add_constructor([]) cls.add_constructor([param('ReturnConstRef const &', 'arg0')]) cls.add_method('ReturnMyAStruct', 'RAStruct const &', [], is_pure_virtual=True, is_virtual=True) cls = mod.add_class('RAReturnConstRef', parent=mod['ReturnConstRef']) cls.add_constructor([]) cls.add_constructor([param('int', 'value')]) cls.add_constructor([param('RAReturnConstRef const &', 'arg0')]) cls.add_method('ReturnMyAStruct', 'RAStruct const &', [], is_virtual=True) #### --- error handler --- class MyErrorHandler(pybindgen.settings.ErrorHandler): def __init__(self): super(MyErrorHandler, self).__init__() self.num_errors = 0 def handle_error(self, wrapper, exception, traceback_): print("exception %s in wrapper %s" % (exception, wrapper), file=sys.stderr) self.num_errors += 1 if 0: # verbose? import traceback traceback.print_tb(traceback_) return True pybindgen.settings.error_handler = MyErrorHandler() foomodulegen_common.customize_module(mod) ## ---- finally, generate the whole thing ---- mod.generate(FileCodeSink(out_file))
def register_Tr_session_methods(root_module, cls): cls.docstring = ( 'Class that manages the Transmission session\\n' '\\n' 'Args:\\n' ' tag (str): \'gtk\', \'macosx\', \'daemon\', etc...\\n' ' this is only for pre-1.30 resume files\\n' ' config_dir (str): directory for configuration files\\n' ' message_queueing (bool): if True, messages will be queued\\n' ' settings (BencDict): session settings') con = cls.add_function_as_constructor( "tr_sessionInit", ReturnValue.new("tr_session *", caller_owns_return=True), [ param('const char *', 'tag'), param('const char *', 'config_dir'), param('bool', 'message_queueing'), param('BencDict *', 'settings', transfer_ownership=False) ]) root_module.header.writeln( "double _wrap_tr_sessionGetActiveSpeedLimit(const tr_session *session,\n" " tr_direction dir);") root_module.body.writeln( "double _wrap_tr_sessionGetActiveSpeedLimit(const tr_session *session,\n" " tr_direction dir)\n" "{\n" " double speed;\n" " if (tr_sessionGetActiveSpeedLimit_KBps(session, dir, &speed))\n" " return speed;\n" " return -1;\n" "}") cls.add_instance_attribute('active_speed_limit_up', 'double', is_const=True, is_pure_c=True, getter='_wrap_tr_sessionGetActiveSpeedLimit', closure='&tr_up', closure_cast='*(tr_direction*)', docstring="Get the active upload speed limit") cls.add_instance_attribute('active_speed_limit_down', 'double', is_const=True, is_pure_c=True, getter='_wrap_tr_sessionGetActiveSpeedLimit', closure='&tr_down', closure_cast='*(tr_direction*)', docstring="Get the active download speed limit") cls.add_instance_attribute( 'alt_speed_up', 'int', is_pure_c=True, getter='tr_sessionGetAltSpeed_KBps', setter='tr_sessionSetAltSpeed_KBps', closure='&tr_up', closure_cast='*(tr_direction*)', docstring="Get/set the upload alternate speed limit") cls.add_instance_attribute( 'alt_speed_down', 'int', is_pure_c=True, getter='tr_sessionGetAltSpeed_KBps', setter='tr_sessionSetAltSpeed_KBps', closure='&tr_down', closure_cast='*(tr_direction*)', docstring="Get/set the download alternate speed limit") cls.add_instance_attribute( 'alt_speed_begin', 'int', is_pure_c=True, getter='tr_sessionGetAltSpeedBegin', setter='tr_sessionSetAltSpeedBegin', docstring= "Get/set the time (in minutes since midnight) to begin the alt speed") cls.add_instance_attribute( 'alt_speed_end', 'int', is_pure_c=True, getter='tr_sessionGetAltSpeedEnd', setter='tr_sessionSetAltSpeedEnd', docstring= "Get/set the time (in minutes since midnight) to end the alt speed") cls.add_instance_attribute( 'alt_speed_day', 'tr_sched_day', is_pure_c=True, getter='tr_sessionGetAltSpeedDay', setter='tr_sessionSetAltSpeedDay', docstring="Get/set the alt speed transmission.scheduled_days") cls.add_instance_attribute( 'blocklist_enabled', 'bool', is_pure_c=True, getter='tr_blocklistIsEnabled', setter='tr_blocklistSetEnabled', docstring="Get/set whether or not to use the peer blocklist") cls.add_instance_attribute('blocklist_exists', 'bool', is_const=True, is_pure_c=True, getter='tr_blocklistExists', docstring="Check if the blocklist exists") cls.add_instance_attribute( 'blocklist_rule_count', 'int', is_const=True, is_pure_c=True, getter='tr_blocklistGetRuleCount', docstring="Get/set the number of rules in the blocklist") cls.add_instance_attribute('blocklist_URL', 'char const *', is_pure_c=True, getter='tr_blocklistGetURL', setter='tr_blocklistSetURL', docstring="Get/set the blocklist URL") cls.add_instance_attribute('cache_limit', 'int', is_pure_c=True, getter='tr_sessionGetCacheLimit_MB', setter='tr_sessionSetCacheLimit_MB', docstring="Get/set the cache limit in MB") cls.add_instance_attribute( 'config_directory', 'char const *', is_const=True, is_pure_c=True, getter='tr_sessionGetConfigDir', docstring="Get the directory used for configuration files") root_module.header.writeln( "tr_session_stats *_wrap_tr_sessionGetCumulativeStats(const tr_session * session);" ) root_module.body.writeln( "tr_session_stats *_wrap_tr_sessionGetCumulativeStats(const tr_session * session)\n" "{\n" " tr_session_stats *stats = tr_new0(tr_session_stats, 1);\n" " tr_sessionGetCumulativeStats(session, stats);\n" " return stats;\n" "}") cls.add_instance_attribute( 'cumulative_stats', ReturnValue.new("tr_session_stats *", caller_owns_return=True), is_pure_c=True, is_const=True, getter='_wrap_tr_sessionGetCumulativeStats', docstring="Get the total (cumulative) session stats") cls.add_instance_attribute('delete_source', 'bool', is_pure_c=True, getter='tr_sessionGetDeleteSource', setter='tr_sessionSetDeleteSource', docstring="") cls.add_instance_attribute('download_directory', 'char const *', is_pure_c=True, getter='tr_sessionGetDownloadDir', setter='tr_sessionSetDownloadDir', docstring="Get/set the download directory") cls.add_instance_attribute( 'download_directory_free_space', 'int64_t', is_const=True, is_pure_c=True, getter='tr_sessionGetDownloadDirFreeSpace', docstring="Get the download directory free space") cls.add_instance_attribute( 'encryption_mode', 'tr_encryption_mode', is_pure_c=True, getter='tr_sessionGetEncryption', setter='tr_sessionSetEncryption', docstring="Get/set the session transmission.encryption_mode") cls.add_instance_attribute( 'idle_limit', 'uint16_t', is_pure_c=True, getter='tr_sessionGetIdleLimit', setter='tr_sessionSetIdleLimit', docstring="Get/set the torrent idle limit in minutes") cls.add_instance_attribute( 'incomplete_directory', 'char const *', is_pure_c=True, getter='tr_sessionGetIncompleteDir', setter='tr_sessionSetIncompleteDir', docstring="Get/set the directory for incomplete torrents") cls.add_instance_attribute('paused', 'bool', is_pure_c=True, getter='tr_sessionGetPaused', setter='tr_sessionSetPaused', docstring="Pause/unpause the session") cls.add_instance_attribute('peer_limit', 'uint16_t', is_pure_c=True, getter='tr_sessionGetPeerLimit', setter='tr_sessionSetPeerLimit', docstring="Get/set the peer limit per session") cls.add_instance_attribute('peer_limit_per_torrent', 'uint16_t', is_pure_c=True, getter='tr_sessionGetPeerLimitPerTorrent', setter='tr_sessionSetPeerLimitPerTorrent', docstring="Get/set the peer limit per torrent") cls.add_instance_attribute('peer_port', 'tr_port', is_pure_c=True, getter='tr_sessionGetPeerPort', setter='tr_sessionSetPeerPort', docstring="Get/set the peer port") cls.add_instance_attribute( 'peer_port_random_on_start', 'bool', is_pure_c=True, getter='tr_sessionGetPeerPortRandomOnStart', setter='tr_sessionSetPeerPortRandomOnStart', docstring="Get/set whether or not to use a random peer port on start") cls.add_instance_attribute( 'port_forwarding', 'tr_port_forwarding', is_const=True, is_pure_c=True, getter='tr_sessionGetPortForwarding', docstring="Get the session transmission.port_forwarding value") cls.add_instance_attribute( 'queue_enabled_up', 'bool', is_pure_c=True, getter='tr_sessionGetQueueEnabled', setter='tr_sessionSetQueueEnabled', closure='&tr_up', closure_cast='*(tr_direction*)', docstring="Get/set whether or not to limit how many torrents can upload" ) cls.add_instance_attribute( 'queue_enabled_down', 'bool', is_pure_c=True, getter='tr_sessionGetQueueEnabled', setter='tr_sessionSetQueueEnabled', closure='&tr_down', closure_cast='*(tr_direction*)', docstring= "Get/set whether or not to limit how many torrents can download") cls.add_instance_attribute( 'queue_size_up', 'int', is_pure_c=True, getter='tr_sessionGetQueueSize', setter='tr_sessionSetQueueSize', closure='&tr_up', closure_cast='*(tr_direction*)', docstring="Get/set the number of torrents allowed to upload") cls.add_instance_attribute( 'queue_size_down', 'int', is_pure_c=True, getter='tr_sessionGetQueueSize', setter='tr_sessionSetQueueSize', closure='&tr_down', closure_cast='*(tr_direction*)', docstring="Get/set the number of torrents allowed to download") cls.add_instance_attribute( 'queue_stalled_minutes', 'int', is_pure_c=True, getter='tr_sessionGetQueueStalledMinutes', setter='tr_sessionSetQueueStalledMinutes', docstring= "Set whether or not to count torrents idle for over N minutes as `stalled\'" ) cls.add_instance_attribute('queue_stalled_enabled', 'bool', is_pure_c=True, getter='tr_sessionGetQueueStalledEnabled', setter='tr_sessionSetQueueStalledEnabled') cls.add_instance_attribute('RPC_bind_address', 'char const *', is_const=True, is_pure_c=True, getter='tr_sessionGetRPCBindAddress', docstring="Get/set RPC bind address") cls.add_instance_attribute('RPC_password', 'char const *', is_pure_c=True, getter='tr_sessionGetRPCPassword', setter='tr_sessionSetRPCPassword', docstring="Get/set RPC password") cls.add_instance_attribute('RPC_port', 'tr_port', is_pure_c=True, getter='tr_sessionGetRPCPort', setter='tr_sessionSetRPCPort', docstring="Get/set RPC port") cls.add_instance_attribute('RPC_url', 'char const *', is_pure_c=True, getter='tr_sessionGetRPCUrl', setter='tr_sessionSetRPCUrl', docstring="Get/set RPC URL") cls.add_instance_attribute('RPC_username', 'char const *', is_pure_c=True, getter='tr_sessionGetRPCUsername', setter='tr_sessionSetRPCUsername', docstring="Get/set RPC username") cls.add_instance_attribute( 'RPC_whitelist', 'char const *', is_pure_c=True, getter='tr_sessionGetRPCWhitelist', setter='tr_sessionSetRPCWhitelist', docstring="Get/set RPC Access Control List filename") cls.add_instance_attribute( 'RPC_whitelist_enabled', 'bool', is_pure_c=True, getter='tr_sessionGetRPCWhitelistEnabled', setter='tr_sessionSetRPCWhitelistEnabled', docstring= "Get/set if session uses the RPC whitelist for allowing/denying RPC requests" ) cls.add_instance_attribute('ratio_limit', 'double', is_pure_c=True, getter='tr_sessionGetRatioLimit', setter='tr_sessionSetRatioLimit', docstring="Get/set the session ratio limit") cls.add_instance_attribute( 'raw_speed_up', 'double', is_pure_c=True, is_const=True, getter='tr_sessionGetRawSpeed_KBps', closure='&tr_up', closure_cast='*(tr_direction*)', docstring="Get the raw upload speed limit in KBps") cls.add_instance_attribute( 'raw_speed_down', 'double', is_pure_c=True, is_const=True, getter='tr_sessionGetRawSpeed_KBps', closure='&tr_up', closure_cast='*(tr_direction*)', docstring="Get the raw download speed limit in KBps") cls.add_instance_attribute( 'speed_limit_up', 'int', is_pure_c=True, getter='tr_sessionGetSpeedLimit_KBps', setter='tr_sessionSetSpeedLimit_KBps', closure='&tr_up', closure_cast='*(tr_direction*)', docstring="Get/set the upload speed limit in KBps") cls.add_instance_attribute( 'speed_limit_down', 'int', is_pure_c=True, getter='tr_sessionGetSpeedLimit_KBps', setter='tr_sessionSetSpeedLimit_KBps', closure='&tr_down', closure_cast='*(tr_direction*)', docstring="Get/set the download speed limit in KBps") root_module.header.writeln( "tr_session_stats *_wrap_tr_sessionGetStats(const tr_session * session);" ) root_module.body.writeln( "tr_session_stats *_wrap_tr_sessionGetStats(const tr_session * session)\n" "{\n" " tr_session_stats *stats = tr_new0(tr_session_stats, 1);\n" " tr_sessionGetStats(session, stats);\n" " return stats;\n" "}") cls.add_instance_attribute('stats', ReturnValue.new("tr_session_stats *", caller_owns_return=True), is_const=True, is_pure_c=True, getter='_wrap_tr_sessionGetStats', docstring="Get session stats") cls.add_instance_attribute( 'torrent_done_script', 'char const *', is_pure_c=True, getter='tr_sessionGetTorrentDoneScript', setter='tr_sessionSetTorrentDoneScript', docstring= "Get/set filename of script to be called on torrent completion") cls.add_instance_attribute('DHT_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsDHTEnabled', setter='tr_sessionSetDHTEnabled', docstring="Check/set if session uses DHT") cls.add_instance_attribute( 'idle_limited_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsIdleLimited', setter='tr_sessionSetIdleLimited', docstring= "Check/set if session suspends torrent if idle limit is exceded") cls.add_instance_attribute( 'incomplete_directory_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsIncompleteDirEnabled', setter='tr_sessionSetIncompleteDirEnabled', docstring= "Check/set if session uses incomplete directory until download is complete" ) cls.add_instance_attribute( 'incomplete_file_naming_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsIncompleteFileNamingEnabled', setter='tr_sessionSetIncompleteFileNamingEnabled', docstring= "Check/set if session appends `.part\' to files until download is complete" ) cls.add_instance_attribute('LPD_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsLPDEnabled', setter='tr_sessionSetLPDEnabled', docstring="Check/set if session uses LPD") cls.add_instance_attribute('pex_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsPexEnabled', setter='tr_sessionSetPexEnabled', docstring="Check/set if session uses Pex") cls.add_instance_attribute( 'port_forwarding_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsPortForwardingEnabled', setter='tr_sessionSetPortForwardingEnabled', docstring="Check/set if session uses port forwarding") cls.add_instance_attribute( 'RPC_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsRPCEnabled', setter='tr_sessionSetRPCEnabled', docstring="Check/set if session uses RPC server") cls.add_instance_attribute( 'RPC_password_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsRPCPasswordEnabled', setter='tr_sessionSetRPCPasswordEnabled', docstring="Check/set if RPC server requires password") cls.add_instance_attribute( 'ratio_limit_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsRatioLimited', setter='tr_sessionSetRatioLimited', docstring="Check/set if session is ratio limited") cls.add_instance_attribute( 'speed_limit_enabled_up', 'bool', is_pure_c=True, getter='tr_sessionIsSpeedLimited', setter='tr_sessionLimitSpeed', closure='&tr_up', closure_cast='*(tr_direction*)', docstring="Check/set if session limits upload speed") cls.add_instance_attribute( 'speed_limit_enabled_down', 'bool', is_pure_c=True, getter='tr_sessionIsSpeedLimited', setter='tr_sessionLimitSpeed', closure='&tr_down', closure_cast='*(tr_direction*)', docstring="Check/set if session limits download speed") cls.add_instance_attribute( 'torrent_done_script_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsTorrentDoneScriptEnabled', setter='tr_sessionSetTorrentDoneScriptEnabled', docstring="Check/set if session uses calls Session.torrent_done_script" ) cls.add_instance_attribute('UTP_enabled', 'bool', is_pure_c=True, getter='tr_sessionIsUTPEnabled', setter='tr_sessionSetUTPEnabled', docstring="Check/set if session uses UTP") cls.add_instance_attribute('alt_speed_enabled', 'bool', is_pure_c=True, getter='tr_sessionUsesAltSpeed', setter='tr_sessionUseAltSpeed', docstring="Check/set if session uses alt speed") cls.add_instance_attribute( 'alt_speed_time_enabled', 'bool', is_pure_c=True, getter='tr_sessionUsesAltSpeedTime', setter='tr_sessionUseAltSpeedTime', docstring="Check/set if session uses alt speed time") cls.add_function_as_method( 'tr_sessionReloadBlocklists', 'void', [param('tr_session *', 'session', transfer_ownership=False)], custom_name='blocklists_reload', docstring="Reload blocklists") cls.add_function_as_method( 'tr_blocklistSetContent', 'int', [ param('tr_session *', 'session', transfer_ownership=False), param('char const *', 'filename', default_value='NULL') ], custom_name='blocklist_set', docstring="Set blocklist content\\n\\n" "Args:\\n" " filename (str): blocklist filename or nothing to clear\\n" "Returns:\\n" " number of entries added") cls.add_function_as_method( 'tr_sessionClearStats', 'void', [param('tr_session *', 'session', transfer_ownership=False)], custom_name='stats_clear', docstring="Clear session stats") cls.add_function_as_method( 'tr_sessionSetPeerPortRandom', 'tr_port', [param('tr_session *', 'session', transfer_ownership=False)], custom_name='peer_port_set_random', docstring="Set incoming peer port to a random port\\n\\n" "Returns:\\n" " the port number") root_module.header.writeln( """void _wrap_alt_speed_callback(tr_session *session, bool active, bool userDriven, void *data);""" ) root_module.body.writeln(""" void _wrap_alt_speed_callback(tr_session *session, bool active, bool userDriven, void *data) { PyObject *callback = (PyObject*) data; PyTr_session *py_session = PyObject_New(PyTr_session, &PyTr_session_Type); py_session->obj = session; py_session->flags = PYBINDGEN_WRAPPER_FLAG_OBJECT_NOT_OWNED; PyObject_CallFunction(callback, (char*)"Obb", (PyObject*)py_session, active, userDriven); Py_DECREF(py_session); } """) cls.add_function_as_method( 'tr_sessionSetAltSpeedFunc', 'void', [ param('tr_session *', 'session', transfer_ownership=False), param('tr_altSpeedFunc *', 'callback', callback_func="_wrap_alt_speed_callback") ], custom_name='alt_speed_function_set', docstring= "Function to be called when alternate speed is enabled/disabled\\n\\n" "Args:\\n" " callback (function): callable object or function\\n" " pass `None\' to clear existing callback") root_module.header.writeln( """tr_rpc_callback_status _wrap_rpc_callback(tr_session *session, tr_rpc_callback_type type, struct tr_torrent *tor, void *data);""" ) root_module.body.writeln(""" tr_rpc_callback_status _wrap_rpc_callback(tr_session *session, tr_rpc_callback_type type, struct tr_torrent *tor, void *data) { PyObject *py_torrent, *py_retval; PyObject *callback = (PyObject*) data; int retval = 0; PyTr_session *py_session = PyObject_New(PyTr_session, &PyTr_session_Type); py_session->obj = session; py_session->flags = PYBINDGEN_WRAPPER_FLAG_OBJECT_NOT_OWNED; if (tor) { PyTr_torrent *tmp = PyObject_New(PyTr_torrent, &PyTr_torrent_Type); tmp->obj = tor; tmp->flags = PYBINDGEN_WRAPPER_FLAG_OBJECT_NOT_OWNED; py_torrent = (PyObject *)tmp; } else { Py_INCREF(Py_None); py_torrent = Py_None; } py_retval = PyObject_CallFunction(callback, (char*)"OiO", (PyObject*)py_session, type, py_torrent); if (py_retval && PyLong_Check(py_retval)) retval = PyLong_AsLong(py_retval); Py_DECREF(py_session); Py_DECREF(py_torrent); Py_DECREF(py_retval); return retval == (int)TR_RPC_NOREMOVE ? TR_RPC_NOREMOVE : TR_RPC_OK; } """) cls.add_function_as_method( 'tr_sessionSetRPCCallback', 'void', [ param('tr_session *', 'session', transfer_ownership=False), param( 'tr_rpc_func', 'callback', callback_func="_wrap_rpc_callback") ], custom_name='RPC_callback', docstring= "Function to be called whenever something is changed via RPC\\n\\n" "Args:\\n" " callback (function): callable object or function\\n" " pass `None\' to clear existing callback") cls.add_function_as_method( 'tr_sessionGetSettings', 'void', [ param('tr_session *', 'session', transfer_ownership=False), BencOutParam('BencDict *', 'dict') ], custom_name='settings', docstring="Get a `BencDict\' of session settings") cls.add_function_as_method( 'tr_sessionLoadTorrents', retval("tr_torrent **", array_length='count', reference_existing_object=True), [ param('tr_session *', 'session', transfer_ownership=False), param('tr_ctor *', 'torrent_constructor', transfer_ownership=False), CountParam('int', 'count') ], custom_name='load_torrents', docstring="Load all the torrents in the torrent directory") root_module.header.writeln( "#define _wrap_tr_torrentNew(s, ctor, err) tr_torrentNew(ctor, err)") cls.add_function_as_method( "_wrap_tr_torrentNew", ReturnValue.new("tr_torrent *", reference_existing_object=True), [ param('tr_session *', 'session', transfer_ownership=False), param('tr_ctor *', 'ctor', transfer_ownership=False), TorrentErrorParam('int', 'setmeError') ], custom_name='torrent_new') root_module.header.writeln( "#define _wrap_tr_torrentFree(s, tor) tr_torrentFree(tor)") cls.add_function_as_method( '_wrap_tr_torrentFree', 'void', [ param('tr_session *', 'session', transfer_ownership=False), param('tr_torrent *', 'torrent', transfer_ownership=True) ], unblock_threads=True, custom_name='torrent_free') root_module.header.writeln( "#define _wrap_tr_torrentRemove(s, tor, rem, fn) tr_torrentRemove(tor, rem, fn)" ) cls.add_function_as_method( '_wrap_tr_torrentRemove', 'void', [ param('tr_session *', 'session', transfer_ownership=False), param('tr_torrent *', 'torrent', transfer_ownership=True), param('bool', 'remove_local_data', default_value='0'), param('NULL', 'removeFunc') ], custom_name='torrent_remove') cls.add_custom_method_wrapper('torrents', '_wrap_tr_torrentList', flags=["METH_NOARGS"], wrapper_body=""" static PyObject* _wrap_tr_torrentList(PyTr_session *self, PyObject **return_exception) { tr_torrent *torrent = NULL; PyObject *py_list = PyList_New(0); while ((torrent = tr_torrentNext(self->obj, torrent)) != NULL) { PyTr_torrent *elem = PyObject_New(PyTr_torrent, &PyTr_torrent_Type); elem->obj = torrent; elem->flags = PYBINDGEN_WRAPPER_FLAG_OBJECT_NOT_OWNED; PyList_Append(py_list, (PyObject*)elem); } return py_list; } """) cls.add_function_as_method( 'tr_sessionSaveSettings', 'void', [ param('tr_session *', 'session', transfer_ownership=False), param('char const *', 'directory'), param('BencDict const *', 'settings', transfer_ownership=False) ], custom_name='settings_save', docstring="Save `settings\' to `directory\'") cls.add_function_as_method( 'tr_sessionSet', 'void', [ param('tr_session *', 'session', transfer_ownership=False), param('BencDict *', 'settings', transfer_ownership=False) ], custom_name='update', docstring="Update session settings from `BencDict\'") return
def reg_Entry(cls): cls.add_method('getPrefix', 'const ns3::ndn::Name&', [], is_const=True) cls.add_method('getNextHops', retval('const ns3::ndn::nfd::fib::NextHopList&', caller_manages_return=False), [], is_const=True) cls.add_method('hasNextHops', 'bool', [], is_const=True)
import pybindgen import sys mod = pybindgen.Module('Maestro') mod.add_include('"maestro.h"') mod.add_function('maestroGetPosition', pybindgen.retval('int'), [ pybindgen.param('int', 'fd'), pybindgen.param('unsigned char', 'channel') ]) mod.add_function('maestroSetTarget', pybindgen.retval('int'), [ pybindgen.param('int', 'fd'), pybindgen.param('unsigned char', 'channel'), pybindgen.param('unsigned short', 'target') ]) mod.add_function('maestroSetSpeed', pybindgen.retval('int'), [ pybindgen.param('int', 'fd'), pybindgen.param('unsigned char', 'channel'), pybindgen.param('unsigned short', 'target') ]) mod.add_function('maestroSetAccel', pybindgen.retval('int'), [ pybindgen.param('int', 'fd'), pybindgen.param('unsigned char', 'channel'), pybindgen.param('unsigned short', 'target') ]) mod.add_function('maestroConnect', pybindgen.retval('int'), [pybindgen.param('const char *', 'device')]) mod.generate(sys.stdout)
def reg_NextHopList(cls): cls.add_method('size', retval('size_t'), [], is_const=True) cls.add_container_traits(retval('const ns3::ndn::nfd::fib::NextHop&', caller_manages_return=False), begin_method='begin', end_method='end', iterator_type='const_iterator')
# python build stubs for package common # File is generated by gopy. Do not edit. # gopy build -output=common github.com/google/cel-go/common from pybindgen import retval, param, Module import sys mod = Module('_common') mod.add_include('"common_go.h"') mod.add_function('GoPyInit', None, []) mod.add_function('DecRef', None, [param('int64_t', 'handle')]) mod.add_function('IncRef', None, [param('int64_t', 'handle')]) mod.add_function('NumHandles', retval('int'), []) mod.add_function('Slice_bool_CTor', retval('int64_t'), []) mod.add_function('Slice_bool_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_bool_elem', retval('bool'), [param('int64_t', 'handle'), param('int', 'idx')]) mod.add_function('Slice_bool_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('bool', 'value')]) mod.add_function('Slice_bool_append', None, [param('int64_t', 'handle'), param('bool', 'value')]) mod.add_function('Slice_byte_CTor', retval('int64_t'), []) mod.add_function('Slice_byte_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_byte_elem', retval('uint8_t'), [param('int64_t', 'handle'), param('int', 'idx')]) mod.add_function('Slice_byte_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('uint8_t', 'value')]) mod.add_function('Slice_byte_append', None, [param('int64_t', 'handle'), param('uint8_t', 'value')]) mod.add_function('Slice_float32_CTor', retval('int64_t'), []) mod.add_function('Slice_float32_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_float32_elem', retval('float'), [param('int64_t', 'handle'), param('int', 'idx')]) mod.add_function('Slice_float32_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('float', 'value')]) mod.add_function('Slice_float32_append', None, [param('int64_t', 'handle'), param('float', 'value')]) mod.add_function('Slice_float64_CTor', retval('int64_t'), []) mod.add_function('Slice_float64_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_float64_elem', retval('double'), [param('int64_t', 'handle'), param('int', 'idx')])
# python build stubs for package cel # File is generated by gopy. Do not edit. # gopy pkg github.com/google/cel-go/cel from pybindgen import retval, param, Module import sys mod = Module('_cel') mod.add_include('"cel_go.h"') mod.add_function('GoPyInit', None, []) mod.add_function('DecRef', None, [param('int64_t', 'handle')]) mod.add_function('IncRef', None, [param('int64_t', 'handle')]) mod.add_function('NumHandles', retval('int'), []) mod.add_function('Slice_bool_CTor', retval('int64_t'), []) mod.add_function('Slice_bool_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_bool_elem', retval('bool'), [param('int64_t', 'handle'), param('int', 'idx')]) mod.add_function( 'Slice_bool_set', None, [param('int64_t', 'handle'), param('int', 'idx'), param('bool', 'value')]) mod.add_function('Slice_bool_append', None, [param('int64_t', 'handle'), param('bool', 'value')]) mod.add_function('Slice_byte_CTor', retval('int64_t'), []) mod.add_function('Slice_byte_len', retval('int'), [param('int64_t', 'handle')]) mod.add_function('Slice_byte_elem', retval('uint8_t'), [param('int64_t', 'handle'), param('int', 'idx')])
def add_example(GridType, space_backend, la_backend, name): # build all types needed for the discretization dimRange = '1' polOrder = '1' grid_layer = 'Dune::Stuff::Grid::ChooseLayer::leaf' MatrixType = 'Dune::Stuff::LA::' VectorType = 'Dune::Stuff::LA::' if 'eigen_sparse' in la_backend: MatrixType += 'EigenRowMajorSparseMatrix' VectorType += 'EigenDenseVector' elif 'istl_sparse' in la_backend: MatrixType += 'IstlRowMajorSparseMatrix' VectorType += 'IstlDenseVector' MatrixType += '< ' + RangeFieldType + ' >' VectorType += '< ' + RangeFieldType + ' >' OperatorType = 'Dune::Pymor::Operators::LinearAffinelyDecomposedContainerBased< ' + MatrixType + ', ' + VectorType + ' >' ProductType = OperatorType FunctionalType = 'Dune::Pymor::Functionals::LinearAffinelyDecomposedVectorBased< ' + VectorType + ' >' LocalDiscretizationName = 'Dune::HDD::LinearElliptic::Discretizations::SWIPDG' local_layer = 'Dune::Stuff::Grid::ChooseLayer::local' LocalDiscretizationFullName = (LocalDiscretizationName + '< ' + GridType + ', ' + local_layer + ', ' + RangeFieldType + ', ' + dimRange + ', ' + polOrder + ', ' + space_backend + ', ' + la_backend + ' >') inject_StationaryDiscretizationImplementation( module, exceptions, interfaces, CONFIG_H, LocalDiscretizationName, Traits={ 'VectorType': VectorType, 'OperatorType': OperatorType, 'FunctionalType': FunctionalType, 'ProductType': ProductType }, template_parameters=[ GridType, local_layer, RangeFieldType, dimRange, polOrder, space_backend, la_backend ]) oversampled_layer = 'Dune::Stuff::Grid::ChooseLayer::local_oversampled' OversampledDiscretizationFullName = ( LocalDiscretizationName + '< ' + GridType + ', ' + oversampled_layer + ', ' + RangeFieldType + ', ' + dimRange + ', ' + polOrder + ', ' + space_backend + ', ' + la_backend + ' >') inject_StationaryDiscretizationImplementation( module, exceptions, interfaces, CONFIG_H, LocalDiscretizationName, Traits={ 'VectorType': VectorType, 'OperatorType': OperatorType, 'FunctionalType': FunctionalType, 'ProductType': ProductType }, template_parameters=[ GridType, oversampled_layer, RangeFieldType, dimRange, polOrder, space_backend, la_backend ]) DiscretizationName = 'Dune::HDD::LinearElliptic::Discretizations::BlockSWIPDG' DiscretizationType = ( DiscretizationName + '< ' + GridType + ', ' # + GridType + ', ' + grid_layer + ', ' + RangeFieldType + ', ' + dimRange + ', ' + polOrder + ', ' + la_backend + '>') inject_StationaryMultiscaleDiscretizationImplementation( module, exceptions, interfaces, CONFIG_H, DiscretizationName, Traits={ 'VectorType': VectorType, 'OperatorType': OperatorType, 'FunctionalType': FunctionalType, 'ProductType': ProductType, 'LocalDiscretizationType': LocalDiscretizationFullName, 'OversampledDiscretizationType': OversampledDiscretizationFullName }, template_parameters=[ GridType, RangeFieldType, dimRange, polOrder, la_backend ]) # then create the example Example = module.add_class( 'PbGenericLinearellipticMultiscaleExample', template_parameters=[GridType, space_backend, la_backend], custom_name=name) Example.add_method('logger_options', retval('Dune::Stuff::Common::Configuration'), [], is_static=True, throw=exceptions) Example.add_method('grid_options', retval('std::vector< std::string >'), [], is_static=True, throw=exceptions) Example.add_method('grid_options', retval('Dune::Stuff::Common::Configuration'), [param('const std::string&', 'type')], is_static=True, throw=exceptions) Example.add_method('boundary_options', retval('std::vector< std::string >'), [], is_static=True, throw=exceptions) Example.add_method('boundary_options', retval('Dune::Stuff::Common::Configuration'), [param('const std::string&', 'type')], is_static=True, throw=exceptions) Example.add_method('problem_options', retval('std::vector< std::string >'), [], is_static=True, throw=exceptions) Example.add_method('problem_options', retval('Dune::Stuff::Common::Configuration'), [param('const std::string&', 'type')], is_static=True, throw=exceptions) Example.add_method('solver_options', retval('std::vector< std::string >'), [], is_static=True, throw=exceptions) Example.add_method('solver_options', retval('Dune::Stuff::Common::Configuration'), [param('const std::string&', 'type')], is_static=True, throw=exceptions) Example.add_constructor([ param('const Dune::Stuff::Common::Configuration&', 'logger_cfg'), param('const Dune::Stuff::Common::Configuration&', 'grid_cfg'), param('const Dune::Stuff::Common::Configuration&', 'boundary_cfg'), param('const Dune::Stuff::Common::Configuration&', 'problem_cfg'), param('const std::vector<std::string>&', 'only_these_products') ], throw=exceptions) Example.add_method('pb_discretization_and_return_ptr', retval(DiscretizationType + ' *', caller_owns_return=True), [], is_const=True, throw=exceptions, custom_name='discretization') Example.add_method('visualize', None, [param('const std::string&', 'filename_prefix')], is_const=True, throw=exceptions) Example.add_method('project', retval(VectorType), [param('const std::string', 'expression')], is_const=True, throw=exceptions) Example.add_method( 'prolong', retval(VectorType), [ param('const ' + DiscretizationType + '&', 'source_disc'), param('const ' + VectorType + '&', 'source_vec') ], is_const=True, throw=exceptions) Example.add_method('oswald_interpolate', retval(VectorType), [param('const ' + VectorType + '&', 'vector')], is_const=True, throw=exceptions) Example.add_method('alpha', retval('double'), [ param('const Dune::Pymor::Parameter&', 'mu_1'), param('const Dune::Pymor::Parameter&', 'mu_2') ], is_const=True, throw=exceptions) Example.add_method('gamma', retval('double'), [ param('const Dune::Pymor::Parameter&', 'mu_1'), param('const Dune::Pymor::Parameter&', 'mu_2') ], is_const=True, throw=exceptions) Example.add_method('min_diffusion_ev', retval('double'), [param('const Dune::Pymor::Parameter&', 'mu')], is_const=True, throw=exceptions) Example.add_method('max_diffusion_ev', retval('double'), [param('const Dune::Pymor::Parameter&', 'mu')], is_const=True, throw=exceptions) Example.add_method( 'elliptic_reconstruction_estimate', retval('double'), [ param('const ' + VectorType + '&', 'p_h'), param('const Dune::Pymor::Parameter&', 'mu_min'), param('const Dune::Pymor::Parameter&', 'mu_max'), param('const Dune::Pymor::Parameter&', 'mu_hat'), param('const Dune::Pymor::Parameter&', 'mu_bar'), param('const Dune::Pymor::Parameter&', 'mu'), param('const std::string', 'visualize') ], is_const=True, throw=exceptions) Example.add_method( 'elliptic_reconstruction_estimate', retval('double'), [ param('const ' + VectorType + '&', 'p_h'), param('const ' + VectorType + '&', 'w_h'), param('const ' + VectorType + '&', 'f_h'), param('const Dune::Pymor::Parameter&', 'mu_min'), param('const Dune::Pymor::Parameter&', 'mu_max'), param('const Dune::Pymor::Parameter&', 'mu_hat'), param('const Dune::Pymor::Parameter&', 'mu_bar'), param('const Dune::Pymor::Parameter&', 'mu'), param('const std::string', 'visualize') ], is_const=True, throw=exceptions) Example.add_method('max_grid_width', retval('double'), [], is_const=True, throw=exceptions) Example.add_method('domain_diameter', retval('double'), [], is_const=True, throw=exceptions)
from pybindgen import retval, param, Module import sys mod = Module('testsum') mod.add_include('"sum.h"') mod.add_function('Sum', retval('int'), [param('int', 'a'), param('int', 'b')]) mod.generate(sys.stdout)
def inject_MatrixImplementation(module, exceptions, interfaces, CONFIG_H, name, Traits, template_parameters=None): assert(isinstance(module, pybindgen.module.Module)) assert(isinstance(exceptions, list)) assert(isinstance(interfaces, dict)) for element in interfaces: assert(isinstance(element, str)) assert(len(element) > 0) assert(isinstance(CONFIG_H, dict)) assert(len(name.strip()) > 0) assert(isinstance(Traits, dict)) # for key in Traits.keys(): # assert(isinstance(Traits[key], str)) # assert(len(Traits[key].strip()) > 0) assert('ThisType' in Traits) ThisType = Traits['ThisType'] assert('ScalarType' in Traits) ScalarType = Traits['ScalarType'] if template_parameters is not None: if isinstance(template_parameters, str): assert(len(template_parameters.strip()) > 0) template_parameters = [ template_parameters ] elif isinstance(template_parameters, list): for element in template_parameters: assert(isinstance(element, str)) assert(len(element.strip()) > 0) namespace = module namespaces = [nspace.strip() for nspace in name.split('::')[:-1]] name = name.split('::')[-1].strip() if len(namespaces) > 0: for nspace in namespaces: namespace = namespace.add_cpp_namespace(nspace) Class = namespace.add_class(name, parent=interfaces['Dune::Stuff::LA::Tags::MatrixInterface'], template_parameters=template_parameters) Class.add_constructor([]) # what we want from ContainerInterface Class.add_method('type_this', retval('std::string'), [], is_const=True, is_static=True, throw=exceptions) Class.add_method('copy', retval(ThisType), [], is_const=True, throw=exceptions) Class.add_method('scal', None, [param('const ' + ScalarType + ' &', 'alpha')], throw=exceptions) Class.add_method('axpy', None, [param('const ' + ScalarType + ' &', 'alpha'), param('const ' + ThisType + ' &', 'xx')], throw=exceptions) Class.add_method('has_equal_shape', retval('bool'), [param('const ' + ThisType + ' &', 'other')], is_const=True, throw=exceptions) # what we want from MatrixInterface Class.add_method('pb_rows', retval(CONFIG_H['DUNE_STUFF_SSIZE_T']), [], is_const=True, throw=exceptions, custom_name='rows') Class.add_method('pb_cols', retval(CONFIG_H['DUNE_STUFF_SSIZE_T']), [], is_const=True, throw=exceptions, custom_name='cols') Class.add_method('pb_add_to_entry', None, [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'ii'), param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'jj'), param(ScalarType, 'value')], throw=exceptions, custom_name='add_to_entry') Class.add_method('pb_set_entry', None, [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'ii'), param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'jj'), param(ScalarType, 'value')], throw=exceptions, custom_name='set_entry') Class.add_method('pb_get_entry', retval(ScalarType), [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'ii'), param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'jj')], is_const=True, throw=exceptions, custom_name='get_entry') Class.add_method('valid', 'bool', [], is_const=True, throw=exceptions) Class.add_method('pb_non_zeros', CONFIG_H['DUNE_STUFF_SSIZE_T'], [], is_const=True, throw=exceptions, custom_name='non_zeros') Class.add_method('pb_clear_row', None, [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'ii')], throw=exceptions, custom_name='clear_row') Class.add_method('pb_unit_col', None, [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'jj')], throw=exceptions, custom_name='unit_col') Class.add_method('pb_clear_row', None, [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'ii')], throw=exceptions, custom_name='clear_row') Class.add_method('pb_unit_col', None, [param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'jj')], throw=exceptions, custom_name='unit_col') if 'VectorType' in Traits: VectorTypes = Traits['VectorType'] if not isinstance(VectorTypes, list): VectorTypes = [VectorTypes] for VectorType in VectorTypes: Class.add_method('mv', None, [param('const ' + VectorType + '&', 'xx'), param(VectorType + '&', 'yy')], is_const=True, throw=exceptions) return module, Class
def post_register_types(root_module): root_module.add_include('"ns3/propagation-module.h"') root_module["WifiMacHelper"].add_method( "SetType", retval("void"), [ param("std::string", "type"), ], ) root_module["WifiMacHelper"].add_method( "SetType", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), ], ) root_module["WifiMacHelper"].add_method( "SetType", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), ], ) root_module["WifiMacHelper"].add_method( "SetType", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), ], ) root_module["WifiMacHelper"].add_method( "SetType", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), param("std::string &", "param4_name"), param("ns3::AttributeValue const &", "param4_value"), ], ) root_module["WifiMacHelper"].add_method( "SetType", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), param("std::string &", "param4_name"), param("ns3::AttributeValue const &", "param4_value"), param("std::string &", "param5_name"), param("ns3::AttributeValue const &", "param5_value"), ], ) root_module["WifiMacHelper"].add_method( "SetType", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), param("std::string &", "param4_name"), param("ns3::AttributeValue const &", "param4_value"), param("std::string &", "param5_name"), param("ns3::AttributeValue const &", "param5_value"), param("std::string &", "param6_name"), param("ns3::AttributeValue const &", "param6_value"), ], ) root_module["WifiMacHelper"].add_method( "SetProtectionManager", retval("void"), [ param("std::string", "type"), ], ) root_module["WifiMacHelper"].add_method( "SetProtectionManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), ], ) root_module["WifiMacHelper"].add_method( "SetProtectionManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), ], ) root_module["WifiMacHelper"].add_method( "SetProtectionManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), ], ) root_module["WifiMacHelper"].add_method( "SetProtectionManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), param("std::string &", "param4_name"), param("ns3::AttributeValue const &", "param4_value"), ], ) root_module["WifiMacHelper"].add_method( "SetProtectionManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), param("std::string &", "param4_name"), param("ns3::AttributeValue const &", "param4_value"), param("std::string &", "param5_name"), param("ns3::AttributeValue const &", "param5_value"), ], ) root_module["WifiMacHelper"].add_method( "SetProtectionManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), param("std::string &", "param4_name"), param("ns3::AttributeValue const &", "param4_value"), param("std::string &", "param5_name"), param("ns3::AttributeValue const &", "param5_value"), param("std::string &", "param6_name"), param("ns3::AttributeValue const &", "param6_value"), ], ) root_module["WifiMacHelper"].add_method( "SetAckManager", retval("void"), [ param("std::string", "type"), ], ) root_module["WifiMacHelper"].add_method( "SetAckManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), ], ) root_module["WifiMacHelper"].add_method( "SetAckManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), ], ) root_module["WifiMacHelper"].add_method( "SetAckManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), ], ) root_module["WifiMacHelper"].add_method( "SetAckManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), param("std::string &", "param4_name"), param("ns3::AttributeValue const &", "param4_value"), ], ) root_module["WifiMacHelper"].add_method( "SetAckManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), param("std::string &", "param4_name"), param("ns3::AttributeValue const &", "param4_value"), param("std::string &", "param5_name"), param("ns3::AttributeValue const &", "param5_value"), ], ) root_module["WifiMacHelper"].add_method( "SetAckManager", retval("void"), [ param("std::string", "type"), param("std::string &", "param1_name"), param("ns3::AttributeValue const &", "param1_value"), param("std::string &", "param2_name"), param("ns3::AttributeValue const &", "param2_value"), param("std::string &", "param3_name"), param("ns3::AttributeValue const &", "param3_value"), param("std::string &", "param4_name"), param("ns3::AttributeValue const &", "param4_value"), param("std::string &", "param5_name"), param("ns3::AttributeValue const &", "param5_value"), param("std::string &", "param6_name"), param("ns3::AttributeValue const &", "param6_value"), ], )
def my_module_gen(out_file): mod = Module('cmrclient') mod.add_include('"cmrclient.h"') mod.add_container('std::vector<std::string>', 'std::string', 'vector'); cl = mod.add_class('Client', allow_subclassing=True) cl.add_constructor([Parameter.new('const std::string&', 'id')]) # HOST setting functions cl.add_method('reset_hosts', None, []); cl.add_method('add_host', None, [Parameter.new('const std::string&', 'hostname'), Parameter.new('int', 'port')]) cl.add_method('send_host_list', None, []) # GET functions cl.add_method('get', retval('PyObject*', caller_owns_return=True), [param('const std::string&', 'key')]) cl.add_method('gets', retval('PyObject*', caller_owns_return=True), [param('const std::string&', 'key')]) cl.add_method('get_multi', retval('PyObject*', caller_owns_return=True), [param('const std::vector<std::string>&', 'keys')]) # SET functions cl.add_method('set', retval('bool'), [param('const std::string&', 'key'), param('PyObject*', 'val', transfer_ownership=False), param('uint64_t', 'time', default_value='0')]) cl.add_method('add', retval('bool'), [param('const std::string&', 'key'), param('PyObject*', 'val', transfer_ownership=False), param('uint64_t', 'time', default_value='0')]) cl.add_method('cas', retval('bool'), [param('const std::string&', 'key'), param('PyObject*', 'val', transfer_ownership=False), param('uint64_t', 'cas_unique'), param('uint64_t', 'time', default_value='0')]) # INCREMENT functions cl.add_method('incr', retval('uint64_t'), [param('const std::string&', 'key'), param('int', 'offset')]) cl.add_method('decr', retval('uint64_t'), [param('const std::string&', 'key'), param('int', 'offset')]) # TEST functions cl.add_method('Echo', retval('std::string'), [param('const std::vector<std::string>&', 'messages')]) cl.add_method('Test', retval('PyObject*', caller_owns_return=True), [param('PyObject*', 'obj', transfer_ownership=False)]) cl.add_method('DecompressTest', retval('std::string'), [param('const std::string&', 'input')]) # Now generate code. mod.generate(FileCodeSink(out_file))
def add_example(name): Example = module.add_class(name, template_parameters=[GridType], custom_name=name) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings'), param('const bool', 'enable_colors'), param('const std::string', 'info_color'), param('const std::string', 'debug_color'), param('const std::string', 'warn_color') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings'), param('const bool', 'enable_colors'), param('const std::string', 'info_color'), param('const std::string', 'debug_color') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings'), param('const bool', 'enable_colors'), param('const std::string', 'info_color') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings'), param('const bool', 'enable_colors') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels'), param('const bool', 'enable_warnings') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels'), param('const ' + ssize_t, 'debug_log_levels') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference'), param('const ' + ssize_t, 'info_log_levels') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products'), param('const bool', 'with_reference') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers'), param('const std::vector< std::string >', 'products') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements'), param('const ' + ssize_t, 'oversampling_layers') ], throw=exceptions) Example.add_constructor([ param('const std::string', 'partitioning'), param('const ' + ssize_t, 'num_refinements') ], throw=exceptions) Example.add_constructor([param('const std::string', 'partitioning')], throw=exceptions) Example.add_constructor([], throw=exceptions) Example.add_method('discretization_and_return_ptr', retval(DiscretizationFullName + ' *', caller_owns_return=True), [], is_const=True, throw=exceptions, custom_name='discretization') Example.add_method('visualize', None, [param('const std::string&', 'filename_prefix')], is_const=True, throw=exceptions) Example.add_method('project', retval(VectorType), [param('const std::string', 'expression')], is_const=True, throw=exceptions) Example.add_method( 'compute_error', retval(RangeFieldType), [ param('const ' + VectorType + '&', 'solution'), param('const std::string', 'product_type'), param('const Dune::Pymor::Parameter', 'mu'), param('const Dune::Pymor::Parameter', 'mu_product') ], is_const=True, throw=exceptions) Example.add_method('compute_error', retval(RangeFieldType), [ param('const ' + VectorType + '&', 'solution'), param('const std::string', 'product_type'), param('const Dune::Pymor::Parameter', 'mu') ], is_const=True, throw=exceptions) Example.add_method('compute_error', retval(RangeFieldType), [ param('const ' + VectorType + '&', 'solution'), param('const std::string', 'product_type') ], is_const=True, throw=exceptions) Example.add_method('compute_error', retval(RangeFieldType), [param('const ' + VectorType + '&', 'solution')], is_const=True, throw=exceptions) Example.add_method('available_estimators', retval('std::vector< std::string >'), [], is_const=True, throw=exceptions) Example.add_method('estimate', retval(RangeFieldType), [ param('const ' + VectorType + '&', 'vector'), param('const std::string', 'type'), param('const Dune::Pymor::Parameter', 'mu_hat'), param('const Dune::Pymor::Parameter', 'mu_bar'), param('const Dune::Pymor::Parameter', 'mu') ], is_const=True, throw=exceptions) Example.add_method('estimate', retval(RangeFieldType), [ param('const ' + VectorType + '&', 'vector'), param('const std::string', 'type') ], is_const=True, throw=exceptions) Example.add_method('available_local_estimators', retval('std::vector< std::string >'), [], is_const=True, throw=exceptions) Example.add_method('estimate_local', retval('std::vector< ' + RangeFieldType + ' >'), [ param('const ' + VectorType + '&', 'vector'), param('const std::string', 'type'), param('const Dune::Pymor::Parameter', 'mu_hat'), param('const Dune::Pymor::Parameter', 'mu_bar'), param('const Dune::Pymor::Parameter', 'mu') ], is_const=True, throw=exceptions) Example.add_method('estimate_local', retval('std::vector< ' + RangeFieldType + ' >'), [ param('const ' + VectorType + '&', 'vector'), param('const std::string', 'type') ], is_const=True, throw=exceptions) Example.add_method( 'pb_project_global_to_oversampled', retval(VectorType + '*', caller_owns_return=True), [ param('const ' + VectorType + '&', 'global_vector'), param('const ' + ssize_t, 'subdomain') ], is_const=True, throw=exceptions, custom_name='project_global_to_oversampled') Example.add_method( 'pb_project_global_to_local', retval(VectorType + '*', caller_owns_return=True), [ param('const ' + VectorType + '&', 'global_vector'), param('const ' + ssize_t, 'subdomain') ], is_const=True, throw=exceptions, custom_name='project_global_to_local') Example.add_method( 'pb_project_oversampled_to_local', retval(VectorType + '*', caller_owns_return=True), [ param('const ' + VectorType + '&', 'oversampled_vector'), param('const ' + ssize_t, 'subdomain') ], is_const=True, throw=exceptions, custom_name='project_oversampled_to_local') Example.add_method( 'solve_for_local_correction', retval(VectorType), [ param('std::vector< ' + VectorType + ' >&', 'local_vectors'), param('const ' + ssize_t, 'subdomain'), param('const Dune::Pymor::Parameter', 'mu') ], is_const=True, throw=exceptions) Example.add_method( 'solve_for_local_correction', retval(VectorType), [ param('std::vector< ' + VectorType + ' >&', 'local_vectors'), param('const ' + CONFIG_H['DUNE_STUFF_SSIZE_T'], 'subdomain') ], is_const=True, throw=exceptions) Example.add_method( 'solve_oversampled', retval(VectorType), [ param('const ' + ssize_t, 'subdomain'), param('const std::string&', 'boundary_value_type'), param('const ' + VectorType + '&', 'boundary_value_type'), param('const Dune::Pymor::Parameter', 'mu') ], is_const=True, throw=exceptions) Example.add_method( 'solve_oversampled', retval(VectorType), [ param('const ' + ssize_t, 'subdomain'), param('const std::string&', 'boundary_value_type'), param('const ' + VectorType + '&', 'boundary_value_type') ], is_const=True, throw=exceptions) Example.add_method('visualize_on_coarse_grid', None, [ param('const std::vector< double >&', 'vector'), param('const std::string&', 'filename'), param('const std::string&', 'name') ], is_const=True, throw=exceptions) Example.add_method('alpha', retval(RangeFieldType), [ param('const Dune::Pymor::Parameter&', 'mu_1'), param('const Dune::Pymor::Parameter&', 'mu_2') ], is_const=True, throw=exceptions) Example.add_method('gamma', retval(RangeFieldType), [ param('const Dune::Pymor::Parameter&', 'mu_1'), param('const Dune::Pymor::Parameter&', 'mu_2') ], is_const=True, throw=exceptions)
def my_module_gen(out_file): mod = Module('foo') mod.add_include ('"foo.h"') mod.add_function('TypeNameGet', 'std::string', [], custom_name='IntegerTypeNameGet', template_parameters=['int']) Foo = mod.add_class('Foo', automatic_type_narrowing=True) Foo.add_static_attribute('instance_count', ReturnValue.new('int')) Foo.add_constructor([Parameter.new('std::string', 'datum')]) Foo.add_constructor([]) Foo.add_method('get_datum', ReturnValue.new('const std::string'), []) Foo.add_method('is_initialized', ReturnValue.new('bool'), [], is_const=True) Foo.add_output_stream_operator() Foo.add_method('add_sub', ReturnValue.new('int'), [ Parameter.new('int', 'a'), Parameter.new('int', 'b', default_value='3'), Parameter.new('bool', 'subtract', default_value='false') ], is_static=True) Foo.add_custom_instance_attribute("is_unique", "bool", getter="is_unique", is_const=True) Zoo = mod.add_class('Zoo', automatic_type_narrowing=True) Zoo.add_constructor([Parameter.new('std::string', 'datum')]) Zoo.add_constructor([]) Zoo.add_method('get_datum', ReturnValue.new('std::string'), []) Zoo.implicitly_converts_to(Foo) Foobar = mod.add_class('Foobar', allow_subclassing=True) Foobar.add_static_attribute('instance_count', ReturnValue.new('int')) Bar = mod.add_class('Bar', parent=Foo) Bar.inherit_default_constructors() ## a static method.. Bar.add_method('Hooray', ReturnValue.new('std::string'), [], is_static=True) ## to test RTTI with a hidden subclass mod.add_function('get_hidden_subclass_pointer', ReturnValue.new('Foo*', caller_owns_return=True), []) ## Zbr is a reference counted class Zbr = mod.add_class('Zbr', memory_policy=cppclass.ReferenceCountingMethodsPolicy( incref_method='Ref', decref_method='Unref', peekref_method="GetReferenceCount"), allow_subclassing=True) def helper_class_hook(helper_class): helper_class.add_custom_method( declaration="static int custom_method_added_by_a_hook(int x);", body=""" int %s::custom_method_added_by_a_hook(int x) { return x + 1; } """ % helper_class.name) helper_class.add_post_generation_code("// this comment was written by a helper class hook function") Zbr.add_helper_class_hook(helper_class_hook) Zbr.add_constructor([]) Zbr.add_constructor([Parameter.new('std::string', 'datum')]) Zbr.add_method('get_datum', ReturnValue.new('std::string'), []) Zbr.add_method('get_int', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_virtual=True) Zbr.add_static_attribute('instance_count', ReturnValue.new('int')) Zbr.add_method('get_value', ReturnValue.new('int'), [Parameter.new('int*', 'x', direction=Parameter.DIRECTION_OUT)]) mod.add_function('store_zbr', None, [Parameter.new('Zbr*', 'zbr', transfer_ownership=True)]) mod.add_function('invoke_zbr', ReturnValue.new('int'), [Parameter.new('int', 'x')]) mod.add_function('delete_stored_zbr', None, []) mod.add_function('print_something', ReturnValue.new('int'), [Parameter.new('const char*', 'message')], deprecated=True) mod.add_function('print_something_else', ReturnValue.new('int'), [Parameter.new('const char*', 'message2')]) ## test overloaded functions mod.add_function('get_int_from_string', ReturnValue.new('int'), [Parameter.new('const char*', 'from_string'), Parameter.new('int', 'multiplier', default_value='1')], custom_name="get_int") mod.add_function('get_int_from_float', ReturnValue.new('int'), [Parameter.new('double', 'from_float'), Parameter.new('int', 'multiplier', default_value='1')], custom_name="get_int") SomeObject = mod.add_class('SomeObject', allow_subclassing=True) SomeObject.add_instance_attribute('foo', ReturnValue.new('Foo'), getter='get_foo_value', setter='set_foo_value') SomeObject.add_instance_attribute('m_prefix', ReturnValue.new('std::string')) SomeObject.add_static_attribute('staticData', ReturnValue.new('std::string')) SomeObject.add_static_attribute('instance_count', ReturnValue.new('int')) SomeObject.add_method('add_prefix', ReturnValue.new('int'), [Parameter.new('std::string&', 'message', direction=Parameter.DIRECTION_INOUT)]) SomeObject.add_constructor([Parameter.new('std::string', 'prefix')]) SomeObject.add_constructor([Parameter.new('int', 'prefix_len')]) SomeObject.add_method('operator()', ReturnValue.new('int'), [Parameter.new('std::string&', 'message', direction=Parameter.DIRECTION_INOUT)], custom_name='__call__') # --- some virtual methods --- SomeObject.add_method('get_prefix', ReturnValue.new('std::string'), [], is_virtual=True, is_const=True) SomeObject.add_method('get_prefix_with_foo_value', ReturnValue.new('std::string'), [Parameter.new('Foo', 'foo')], is_virtual=True, is_const=True) SomeObject.add_method('get_prefix_with_foo_ref', ReturnValue.new('std::string'), [Parameter.new('const Foo&', 'foo', direction=Parameter.DIRECTION_INOUT)], is_virtual=True, is_const=True) SomeObject.add_method('get_prefix_with_foo_ptr', ReturnValue.new('std::string'), [Parameter.new('const Foo*', 'foo', transfer_ownership=False)], is_virtual=True, is_const=True) ## overloaded virtual methods SomeObject.add_method('get_something', ReturnValue.new('std::string'), [], is_virtual=True, is_const=True) SomeObject.add_method('get_something', ReturnValue.new('std::string'), [Parameter.new('int', 'x')], is_virtual=True, is_const=True) SomeObject.add_method('set_pyobject', None, [Parameter.new('PyObject*', 'pyobject', transfer_ownership=False)], is_virtual=True) SomeObject.add_method('get_pyobject', ReturnValue.new('PyObject*', caller_owns_return=True), [], is_virtual=True) ## add a function that appears as a method of an object SomeObject.add_function_as_method('some_object_get_something_prefixed', ReturnValue.new('std::string'), [Parameter.new('const SomeObject*', 'obj', transfer_ownership=False), Parameter.new('std::string', 'something')], custom_name='get_something_prefixed') ## add a function that appears as a method of an object SomeObject.add_function_as_method('some_object_val_get_something_prefixed', ReturnValue.new('std::string'), [Parameter.new('SomeObject', 'obj'), Parameter.new('std::string', 'something')], custom_name='val_get_something_prefixed') ## add a function that appears as a method of an object SomeObject.add_function_as_method('some_object_ref_get_something_prefixed', ReturnValue.new('std::string'), [Parameter.new('const SomeObject&', 'obj'), Parameter.new('std::string', 'something')], custom_name='ref_get_something_prefixed') # --- SomeObject.add_method('call_get_prefix', ReturnValue.new('std::string'), []) SomeObject.add_method('set_foo_value', None, [Parameter.new('Foo', 'foo')]) SomeObject.add_method('get_foo_value', ReturnValue.new('Foo'), []) SomeObject.add_method('set_foo_ptr', ReturnValue.new('void'), [Parameter.new('Foo*', 'foo', transfer_ownership=True)]) SomeObject.add_method('set_foo_shared_ptr', ReturnValue.new('void'), [Parameter.new('Foo*', 'foo', transfer_ownership=False)]) SomeObject.add_method('get_foo_shared_ptr', ReturnValue.new('const Foo*', caller_owns_return=False), []) SomeObject.add_method('get_foo_ptr', ReturnValue.new('Foo*', caller_owns_return=True), []) SomeObject.add_method('set_foo_by_ref', ReturnValue.new('void'), [Parameter.new('Foo&', 'foo', direction=Parameter.DIRECTION_IN)]) SomeObject.add_method('get_foo_by_ref', ReturnValue.new('void'), [Parameter.new('Foo&', 'foo', direction=Parameter.DIRECTION_OUT)]) ## custodian/ward tests SomeObject.add_method('get_foobar_with_self_as_custodian', ReturnValue.new('Foobar*', custodian=0, reference_existing_object=True), []) SomeObject.add_method('get_foobar_with_other_as_custodian', ReturnValue.new('Foobar*', custodian=1, reference_existing_object=True), [Parameter.new('SomeObject*', 'other', transfer_ownership=False)]) SomeObject.add_method('set_foobar_with_self_as_custodian', ReturnValue.new('void'), [Parameter.new('Foobar*', 'foobar', transfer_ownership=True, custodian=0)]) mod.add_function('get_foobar_with_other_as_custodian', ReturnValue.new('Foobar*', custodian=1, reference_existing_object=True), [Parameter.new('SomeObject*', 'other', transfer_ownership=False)]) mod.add_function('create_new_foobar', ReturnValue.new('Foobar*', caller_owns_return=True), []) mod.add_function('set_foobar_with_other_as_custodian', ReturnValue.new('void'), [Parameter.new('Foobar*', 'foobar', transfer_ownership=True, custodian=2), Parameter.new('SomeObject*', 'other', transfer_ownership=False)]) mod.add_function('set_foobar_with_return_as_custodian', ReturnValue.new('SomeObject*', caller_owns_return=True), [Parameter.new('Foobar*', 'foobar', transfer_ownership=True, custodian=-1)]) ## get/set recfcounted object Zbr SomeObject.add_method('get_zbr', ReturnValue.new('Zbr*', caller_owns_return=True), []) SomeObject.add_method('get_internal_zbr', ReturnValue.new('Zbr*', caller_owns_return=True), []) SomeObject.add_method('peek_zbr', ReturnValue.new('Zbr*', caller_owns_return=False), []) SomeObject.add_method('set_zbr_transfer', ReturnValue.new('void'), [Parameter.new('Zbr*', 'zbr', transfer_ownership=True)]) SomeObject.add_method('set_zbr_shared', ReturnValue.new('void'), [Parameter.new('Zbr*', 'zbr', transfer_ownership=False)]) ## methods with transformed types SomeObject.add_method('set_zbr_pholder', ReturnValue.new('void'), [Parameter.new('PointerHolder<Zbr>', 'zbr')]) SomeObject.add_method('get_zbr_pholder', ReturnValue.new('PointerHolder<Zbr>'), []) ## test overloaded methods SomeObject.add_method('get_int', ReturnValue.new('int'), [Parameter.new('const char*', 'from_string')], custom_name="get_int") SomeObject.add_method('get_int', ReturnValue.new('int'), [Parameter.new('double', 'from_float')], custom_name="get_int") # Bug #508577 SomeObject.add_method('protected_method_that_is_not_virtual', ReturnValue.new('std::string'), [Parameter.new('std::string', 'arg')], is_const=True, visibility='protected') SomeObject.add_method('method_returning_cstring', ReturnValue.new('const char *'), [], is_virtual=True, is_const=True) mod.add_function('store_some_object', ReturnValue.new('void'), [Parameter.new('SomeObject*', 'obj', transfer_ownership=True)]) mod.add_function('invoke_some_object_get_prefix', ReturnValue.new('std::string'), []) mod.add_function('take_some_object', ReturnValue.new('SomeObject*', caller_owns_return=True), []) mod.add_function('delete_some_object', ReturnValue.new('void'), []) xpto = mod.add_cpp_namespace("xpto") xpto.add_function('some_function', ReturnValue.new('std::string'), []) ## enums.. xpto.add_enum('FooType', ['FOO_TYPE_AAA', 'FOO_TYPE_BBB', 'FOO_TYPE_CCC']) xpto.add_function('get_foo_type', ReturnValue.new('FooType'), []) xpto.add_function('set_foo_type', ReturnValue.new('void'), [Parameter.new("FooType", 'type')]) xpto.add_function('set_foo_type_inout', ReturnValue.new('void'), [Parameter.new("FooType&", 'type', direction=Parameter.DIRECTION_INOUT)]) xpto.add_function('set_foo_type_ptr', ReturnValue.new('void'), [Parameter.new("FooType*", 'type', direction=Parameter.DIRECTION_INOUT)]) xpto_SomeClass = xpto.add_class('SomeClass', docstring="This is the docstring for SomeClass") xpto_SomeClass.add_constructor([]) xpto.add_typedef(Foo, 'FooXpto') xpto.add_function('get_foo_datum', 'std::string', [Parameter.new('const xpto::FooXpto&', 'foo')]) typehandlers.add_type_alias('uint32_t', 'xpto::FlowId') xpto.add_function('get_flow_id', 'xpto::FlowId', [Parameter.new('xpto::FlowId', 'flowId')]) # bug #798383 XptoClass = xpto.add_struct('XptoClass') XptoClass.add_method("GetSomeClass", retval("xpto::SomeClass*", caller_owns_return=True), []) ## ---- some implicity conversion APIs mod.add_function('function_that_takes_foo', ReturnValue.new('void'), [Parameter.new('Foo', 'foo')]) mod.add_function('function_that_returns_foo', ReturnValue.new('Foo'), []) cls = mod.add_class('ClassThatTakesFoo') cls.add_constructor([Parameter.new('Foo', 'foo')]) cls.add_method('get_foo', ReturnValue.new('Foo'), []) cls = mod.add_class('SingletonClass', is_singleton=True) cls.add_method('GetInstance', ReturnValue.new('SingletonClass*', caller_owns_return=True), [], is_static=True) ## A class that has no public default constructor... cls = mod.add_class('InterfaceId', is_singleton=True) ## A function that returns such a class... mod.add_function('make_interface_id', ReturnValue.new('InterfaceId'), []) ## A class the cannot be constructed; this will cause late CodeGenerationError's cls = mod.add_class('CannotBeConstructed') cls.set_cannot_be_constructed("no reason") cls.add_method('get_value', ReturnValue.new('CannotBeConstructed'), [], is_static=True) cls.add_method('get_ptr', ReturnValue.new('CannotBeConstructed*', caller_owns_return=True), [], is_static=True) mod.add_function('get_cannot_be_constructed_value', ReturnValue.new('CannotBeConstructed'), []) mod.add_function('get_cannot_be_constructed_ptr', ReturnValue.new('CannotBeConstructed*', caller_owns_return=True), []) ## A nested class #NestedClass = mod.add_class('NestedClass', automatic_type_narrowing=True, outer_class=SomeObject) NestedClass = SomeObject.add_class('NestedClass', automatic_type_narrowing=True) NestedClass.add_static_attribute('instance_count', ReturnValue.new('int')) NestedClass.add_constructor([Parameter.new('std::string', 'datum')]) NestedClass.add_constructor([]) NestedClass.add_method('get_datum', ReturnValue.new('std::string'), []) ## A nested enum.. #mod.add_enum('NestedEnum', ['FOO_TYPE_AAA', 'FOO_TYPE_BBB', 'FOO_TYPE_CCC'], outer_class=SomeObject) SomeObject.add_enum('NestedEnum', ['FOO_TYPE_AAA', 'FOO_TYPE_BBB', 'FOO_TYPE_CCC']) ## anonymous enum SomeObject.add_enum('', ['CONSTANT_A', 'CONSTANT_B', 'CONSTANT_C']) AbstractBaseClass2 = mod.add_class('AbstractBaseClass2', allow_subclassing=True) AbstractBaseClass2.add_method('invoke_private_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_const=True) AbstractBaseClass2.add_method('invoke_protected_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_const=True) AbstractBaseClass2.add_method('invoke_protected_pure_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_const=True) AbstractBaseClass2.add_constructor([], visibility='protected') AbstractBaseClass2.add_method('protected_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_virtual=True, visibility='protected', is_const=True) AbstractBaseClass2.add_method('protected_pure_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_virtual=True, is_pure_virtual=True, visibility='protected', is_const=True) AbstractBaseClass2.add_method('private_virtual', ReturnValue.new('int'), [Parameter.new('int', 'x')], is_virtual=True, is_pure_virtual=True, visibility='private', is_const=True) AbstractXpto = mod.add_class('AbstractXpto', allow_subclassing=True) AbstractXpto.add_method('something', ReturnValue.new('void'), [Parameter.new('int', 'x')], is_const=True, is_virtual=True, is_pure_virtual=True) AbstractXpto.add_constructor([]) AbstractXptoImpl = mod.add_class('AbstractXptoImpl', parent=AbstractXpto) AbstractXptoImpl.add_method('something', ReturnValue.new('void'), [Parameter.new('int', 'x')], is_const=True, is_virtual=True, is_pure_virtual=False) AbstractXptoImpl.add_constructor([]) Word = mod.add_class('Word') Word.add_instance_attribute('low', 'uint8_t', is_const=False) Word.add_instance_attribute('high', 'uint8_t', is_const=False) Word.add_instance_attribute('word', 'uint16_t', is_const=False) Word.add_constructor([]) mod.add_function('matrix_sum_of_elements', ReturnValue.new('float'), [Parameter.new("float*", 'matrix', direction=Parameter.DIRECTION_IN, array_length=6)]) mod.add_function('matrix_identity_new', ReturnValue.new('void'), [Parameter.new("float*", 'matrix', direction=Parameter.DIRECTION_OUT, array_length=6)]) top_ns = mod.add_cpp_namespace('TopNs') outer_base = top_ns.add_class('OuterBase') bottom_ns = top_ns.add_cpp_namespace('PrefixBottomNs') inner = bottom_ns.add_class('PrefixInner',parent=outer_base) inner.add_constructor([]) inner.add_method('Do', 'void', []) Socket = mod.add_class('Socket', allow_subclassing=True) Socket.add_constructor([]) Socket.add_method('Bind', ReturnValue.new('int'), [], is_virtual=True) Socket.add_method('Bind', ReturnValue.new('int'), [Parameter.new('int', 'address')], is_virtual=True) UdpSocket = mod.add_class('UdpSocket', parent=Socket) UdpSocket.add_constructor([]) UdpSocket.add_method('Bind', ReturnValue.new('int'), [], is_virtual=True) simple_struct_t = mod.add_struct('simple_struct_t') simple_struct_t.add_instance_attribute('xpto', 'int') # containers... mod.add_container('SimpleStructList', ReturnValue.new('simple_struct_t'), 'list') mod.add_function('get_simple_list', ReturnValue.new('SimpleStructList'), []) mod.add_function('set_simple_list', 'int', [Parameter.new('SimpleStructList', 'list')]) mod.add_container('std::set<float>', 'float', 'set') TestContainer = mod.add_class('TestContainer', allow_subclassing=True) TestContainer.add_constructor([]) TestContainer.add_instance_attribute('m_floatSet', 'std::set<float>') TestContainer.add_method('get_simple_list', ReturnValue.new('SimpleStructList'), [], is_virtual=True) TestContainer.add_method('set_simple_list', 'int', [Parameter.new('SimpleStructList', 'list')], is_virtual=True) TestContainer.add_method('set_simple_list_by_ref', 'int', [Parameter.new('SimpleStructList&', 'inout_list', direction=Parameter.DIRECTION_INOUT)], is_virtual=True) mod.add_container('std::vector<simple_struct_t>', ReturnValue.new('simple_struct_t'), 'vector') TestContainer.add_method('get_simple_vec', ReturnValue.new('std::vector<simple_struct_t>'), [], is_virtual=True) TestContainer.add_method('set_simple_vec', 'int', [Parameter.new('std::vector<simple_struct_t>', 'vec')], is_virtual=True) mod.add_container('std::vector<std::string>', 'std::string', 'vector') TestContainer.add_method('get_vec', 'void', [Parameter.new('std::vector<std::string> &', 'outVec', direction=Parameter.DIRECTION_OUT)]) TestContainer.add_method('set_vec_ptr', 'void', [Parameter.new('std::vector<std::string>*', 'inVec', direction=Parameter.DIRECTION_IN, transfer_ownership=True)]) TestContainer.add_method('get_vec_ptr', 'void', [Parameter.new('std::vector<std::string>*', 'outVec', direction=Parameter.DIRECTION_OUT)]) mod.add_container('std::map<std::string, simple_struct_t>', (ReturnValue.new('std::string'), ReturnValue.new('simple_struct_t')), 'map') TestContainer.add_method('get_simple_map', ReturnValue.new('std::map<std::string, simple_struct_t>'), [], is_virtual=True) TestContainer.add_method('set_simple_map', 'int', [Parameter.new('std::map<std::string, simple_struct_t>', 'map')], is_virtual=True) Tupl = mod.add_class('Tupl') Tupl.add_binary_comparison_operator('<') Tupl.add_binary_comparison_operator('<=') Tupl.add_binary_comparison_operator('>=') Tupl.add_binary_comparison_operator('>') Tupl.add_binary_comparison_operator('==') Tupl.add_binary_comparison_operator('!=') Tupl.add_binary_numeric_operator('+') Tupl.add_binary_numeric_operator('-') Tupl.add_binary_numeric_operator('*') Tupl.add_binary_numeric_operator('/') Tupl.add_instance_attribute('x', 'int', is_const=False) Tupl.add_instance_attribute('y', 'int', is_const=False) Tupl.add_constructor([Parameter.new('Tupl const &', 'arg0')]) Tupl.add_constructor([]) Tupl.add_inplace_numeric_operator('+=') Tupl.add_inplace_numeric_operator('-=') Tupl.add_inplace_numeric_operator('*=') Tupl.add_inplace_numeric_operator('/=') Tupl.add_unary_numeric_operator('-') Tupl.add_inplace_numeric_operator('+=', right='int') ManipulatedObject = mod.add_class('ManipulatedObject') ManipulatedObject.add_constructor([]) ManipulatedObject.add_method('GetValue', 'int', [], is_const=True) ManipulatedObject.add_method('SetValue', 'void', [Parameter.new('int', 'value')]) ReferenceManipulator = mod.add_class('ReferenceManipulator', allow_subclassing=True) ReferenceManipulator.add_constructor([]) ReferenceManipulator.add_method('manipulate_object', 'int', []) ReferenceManipulator.add_method('do_manipulate_object', 'void', [Parameter.new('ManipulatedObject&', 'obj', direction=Parameter.DIRECTION_INOUT)], is_virtual=True, is_pure_virtual=True) VectorLike = mod.add_class('VectorLike') VectorLike.add_constructor([]) VectorLike.add_method('get_len', 'size_t', [], custom_name='__len__') VectorLike.add_method('add_VectorLike', 'VectorLike', [Parameter.new('VectorLike', 'rhs')], custom_name='__add__') VectorLike.add_method('iadd_VectorLike', 'VectorLike', [Parameter.new('VectorLike', 'rhs')], custom_name='__iadd__') VectorLike.add_method('mul_VectorLike', 'VectorLike', [Parameter.new('unsigned int', 'n')], custom_name='__mul__') VectorLike.add_method('imul_VectorLike', 'VectorLike', [Parameter.new('unsigned int', 'n')], custom_name='__imul__') VectorLike.add_method('set_item', 'int', [Parameter.new('int', 'index'), Parameter.new('double', 'value')], custom_name='__setitem__') VectorLike.add_method('get_item', 'double', [Parameter.new('int', 'index')], custom_name='__getitem__') VectorLike.add_method('set_slice', 'int', [Parameter.new('int', 'index1'), Parameter.new('int', 'index2'), Parameter.new('VectorLike', 'values')], custom_name='__setslice__') VectorLike.add_method('get_slice', 'VectorLike', [Parameter.new('int', 'index1'), Parameter.new('int', 'index2')], custom_name='__getslice__') VectorLike.add_method('contains_value', 'int', [Parameter.new('double', 'value')], custom_name='__contains__') VectorLike.add_method('append', 'void', [Parameter.new('double', 'value')]) VectorLike2 = mod.add_class('VectorLike2') VectorLike2.add_constructor([]) VectorLike2.add_method('append', 'void', [Parameter.new('double', 'value')]) MapLike = mod.add_class('MapLike') MapLike.add_constructor([]) MapLike.add_method('set', 'void', [Parameter.new('int', 'key'), Parameter.new('double', 'value')]) Error = mod.add_exception('Error') DomainError = mod.add_exception('DomainError', parent=Error) mod.add_function('my_inverse_func', 'double', [Parameter.new('double', 'x')], throw=[DomainError]) ClassThatThrows = mod.add_class('ClassThatThrows', allow_subclassing=True) ClassThatThrows.add_constructor([Parameter.new('double', 'x')], throw=[DomainError]) ClassThatThrows.add_method('my_inverse_method', 'double', [Parameter.new('double', 'x')], throw=[DomainError]) std_exception = mod.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()') mod.add_function('my_inverse_func2', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) ClassThatThrows.add_method('my_inverse_method2', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) mod.add_function('my_inverse_func3', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) ClassThatThrows.add_method('my_inverse_method3', 'double', [Parameter.new('double', 'x')], throw=[std_exception]) ClassThatThrows.add_method('throw_error', 'int', [], throw=[std_exception], is_const=True, is_virtual=True) # https://bugs.launchpad.net/pybindgen/+bug/450255 ProtectedConstructor = mod.add_class('ProtectedConstructor') ProtectedConstructor.add_constructor([]) ProtectedConstructor.add_constructor([Parameter.new('ProtectedConstructor&', 'c')], visibility='protected') # https://bugs.launchpad.net/pybindgen/+bug/455689 property_std_string = mod.add_struct('property', template_parameters=['std::string']) Box = mod.add_class('Box') Box.add_constructor([]) Box.add_static_attribute('instance_count', ReturnValue.new('int')) Box.add_method('getFoobarInternalPtr', ReturnValue.new('const Foobar*', reference_existing_object=True), []) Box.add_method('getFoobarInternalRef', ReturnValue.new('Foobar&', reference_existing_object=True), []) Box.add_method('getFoobarInternalPtr2', ReturnValue.new('Foobar*', return_internal_reference=True), []) Box.add_method('getFoobarInternalRef2', ReturnValue.new('Foobar&', return_internal_reference=True), []) Box.add_instance_attribute('m_internalFoobar', ReturnValue.new('Foobar*', reference_existing_object=True)) # multiple inheritance MIRoot = mod.add_class('MIRoot') MIRoot.add_constructor([]) MIRoot.add_method('root_method', 'int', [], is_const=True) MIBase1 = mod.add_class('MIBase1', parent=MIRoot) MIBase1.add_constructor([]) MIBase1.add_method('base1_method', 'int', [], is_const=True) MIBase2 = mod.add_class('MIBase2', parent=MIRoot) MIBase2.add_constructor([]) MIBase2.add_method('base2_method', 'int', [], is_const=True) MIMixed = mod.add_class('MIMixed', parent=[MIBase1, MIBase2]) MIMixed.add_constructor([]) MIMixed.add_method('mixed_method', 'int', [], is_const=True) mod.add_function('my_throwing_func', 'Tupl', [], throw=[std_exception]) IFoo = mod.add_class("IFoo", destructor_visibility='protected', allow_subclassing=True) IFoo.add_method("DoSomething", None, [], is_pure_virtual=True) IFooImpl = mod.add_class("IFooImpl", parent=IFoo, destructor_visibility='public') IFooImpl.add_constructor([]) IFooImpl.add_method("DoSomething", None, [], is_virtual=True) mod.add_function("test_args_kwargs", "int", [param("const char *", "args"), param("const char *", "kwargs")]) #### --- error handler --- class MyErrorHandler(pybindgen.settings.ErrorHandler): def __init__(self): super(MyErrorHandler, self).__init__() self.num_errors = 0 def handle_error(self, wrapper, exception, traceback_): print >> sys.stderr, "exception %s in wrapper %s" % (exception, wrapper) self.num_errors += 1 if 0: # verbose? import traceback traceback.print_tb(traceback_) return True pybindgen.settings.error_handler = MyErrorHandler() foomodulegen_common.customize_module(mod) ## ---- finally, generate the whole thing ---- mod.generate(FileCodeSink(out_file))
def add_example(GridType, space_backend, la_backend, name): # build all types needed for the discretization dimRange = '1' polOrder = '1' grid_layer = 'Dune::Stuff::Grid::ChooseLayer::leaf' MatrixType = 'Dune::Stuff::LA::' VectorType = 'Dune::Stuff::LA::' if 'eigen_sparse' in la_backend: MatrixType += 'EigenRowMajorSparseMatrix' VectorType += 'EigenDenseVector' elif 'istl_sparse' in la_backend: MatrixType += 'IstlRowMajorSparseMatrix' VectorType += 'IstlDenseVector' MatrixType += '< ' + RangeFieldType + ' >' VectorType += '< ' + RangeFieldType + ' >' OperatorType = 'Dune::Pymor::Operators::LinearAffinelyDecomposedContainerBased< ' + MatrixType + ', ' + VectorType + ' >' ProductType = OperatorType FunctionalType = 'Dune::Pymor::Functionals::LinearAffinelyDecomposedVectorBased< ' + VectorType + ' >' DiscretizationName = 'Dune::HDD::LinearElliptic::Discretizations::CG' DiscretizationType = (DiscretizationName + '< ' + GridType + ', ' + grid_layer + ', ' + RangeFieldType + ', ' + dimRange + ', ' + polOrder + ', ' + space_backend + ', ' + la_backend + '>') inject_StationaryDiscretizationImplementation(module, exceptions, interfaces, CONFIG_H, DiscretizationName, Traits={ 'VectorType': VectorType, 'OperatorType': OperatorType, 'FunctionalType': FunctionalType, 'ProductType': ProductType }, template_parameters=[ GridType, grid_layer, RangeFieldType, dimRange, polOrder, space_backend, la_backend ]) # then create the example Example = module.add_class( 'PbGenericLinearellipticExample', template_parameters=[GridType, space_backend, la_backend], custom_name=name) Example.add_method('logger_options', retval('Dune::Stuff::Common::Configuration'), [], is_static=True, throw=exceptions) Example.add_method('grid_options', retval('std::vector< std::string >'), [], is_static=True, throw=exceptions) Example.add_method('grid_options', retval('Dune::Stuff::Common::Configuration'), [param('const std::string&', 'type')], is_static=True, throw=exceptions) Example.add_method('boundary_options', retval('std::vector< std::string >'), [], is_static=True, throw=exceptions) Example.add_method('boundary_options', retval('Dune::Stuff::Common::Configuration'), [param('const std::string&', 'type')], is_static=True, throw=exceptions) Example.add_method('problem_options', retval('std::vector< std::string >'), [], is_static=True, throw=exceptions) Example.add_method('problem_options', retval('Dune::Stuff::Common::Configuration'), [param('const std::string&', 'type')], is_static=True, throw=exceptions) Example.add_method('solver_options', retval('std::vector< std::string >'), [], is_static=True, throw=exceptions) Example.add_method('solver_options', retval('Dune::Stuff::Common::Configuration'), [param('const std::string&', 'type')], is_static=True, throw=exceptions) Example.add_constructor([ param('const Dune::Stuff::Common::Configuration&', 'logger_cfg'), param('const Dune::Stuff::Common::Configuration&', 'grid_cfg'), param('const Dune::Stuff::Common::Configuration&', 'boundary_cfg'), param('const Dune::Stuff::Common::Configuration&', 'problem_cfg') ], throw=exceptions) Example.add_method('pb_discretization_and_return_ptr', retval(DiscretizationType + ' *', caller_owns_return=True), [], is_const=True, throw=exceptions, custom_name='discretization') Example.add_method('project', retval(VectorType), [param('const std::string', 'expression')], is_const=True, throw=exceptions) Example.add_method('visualize_grid', None, [param('const std::string&', 'filename_prefix')], is_const=True, throw=exceptions) Example.add_method('visualize_problem', None, [param('const std::string&', 'filename_prefix')], is_const=True, throw=exceptions) Example.add_method('visualize_problem', None, [ param('const std::string&', 'filename_prefix'), param('const Dune::Pymor::Parameter&', 'mu') ], is_const=True, throw=exceptions) if space_backend == space_backend_fem: Example.add_method( 'visualize_darcy_velocity', None, [ param('const {}&'.format(VectorType), 'cg_vector'), param('const std::string&', 'filename'), param('const std::string&', 'name') ], is_const=True, throw=exceptions) Example.add_method( 'visualize_darcy_velocity', None, [ param('const {}&'.format(VectorType), 'cg_vector'), param('const std::string&', 'filename'), param('const std::string&', 'name'), param('const Dune::Pymor::Parameter&', 'mu') ], is_const=True, throw=exceptions)