當前位置: 首頁>>代碼示例>>Python>>正文


Python ReturnValue.new方法代碼示例

本文整理匯總了Python中pybindgen.ReturnValue.new方法的典型用法代碼示例。如果您正苦於以下問題:Python ReturnValue.new方法的具體用法?Python ReturnValue.new怎麽用?Python ReturnValue.new使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pybindgen.ReturnValue的用法示例。


在下文中一共展示了ReturnValue.new方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: add_std_ofstream

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
def add_std_ofstream(module):
    module.add_include('<fstream>')
    ostream = module.add_class('ostream', foreign_cpp_namespace='::std')
    ostream.set_cannot_be_constructed("abstract base class")
    ofstream = module.add_class('ofstream', foreign_cpp_namespace='::std', parent=ostream)
    ofstream.add_enum('openmode', [
            ('app', 'std::ios_base::app'),
            ('ate', 'std::ios_base::ate'),
            ('binary', 'std::ios_base::binary'),
            ('in', 'std::ios_base::in'),
            ('out', 'std::ios_base::out'),
            ('trunc', 'std::ios_base::trunc'),
            ])
    ofstream.add_constructor([Parameter.new("const char *", 'filename'),
                              Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")])
    ofstream.add_method('close', None, [])
    
    add_std_ios_openmode(module) 
開發者ID:ntu-dsi-dcn,項目名稱:ntu-dsi-dcn,代碼行數:20,代碼來源:ns3modulegen_core_customizations.py

示例2: add_std_ofstream

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
def add_std_ofstream(module):
    module.add_include('<fstream>')
    ostream = module.add_class('ostream', foreign_cpp_namespace='::std')
    ostream.set_cannot_be_constructed("abstract base class")
    ofstream = module.add_class('ofstream', foreign_cpp_namespace='::std', parent=ostream)
    ofstream.add_enum('openmode', [
            ('app', 'std::ios_base::app'),
            ('ate', 'std::ios_base::ate'),
            ('binary', 'std::ios_base::binary'),
            ('in', 'std::ios_base::in'),
            ('out', 'std::ios_base::out'),
            ('trunc', 'std::ios_base::trunc'),
            ])
    ofstream.add_constructor([Parameter.new("const char *", 'filename'),
                              Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")])
    ofstream.add_method('close', None, [])

    import pybindgen.typehandlers.base
    for alias in "std::_Ios_Openmode", "std::ios::openmode":
        pybindgen.typehandlers.base.param_type_matcher.add_type_alias(alias, "int")

    for flag in 'in', 'out', 'ate', 'app', 'trunc', 'binary':
        module.after_init.write_code('PyModule_AddIntConstant(m, (char *) "STD_IOS_%s", std::ios::%s);'
                                     % (flag.upper(), flag)) 
開發者ID:ntu-dsi-dcn,項目名稱:ntu-dsi-dcn,代碼行數:26,代碼來源:modulegen_customizations.py

示例3: add_std_ofstream

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
def add_std_ofstream(module):
    module.add_include('<fstream>')
    ostream = module.add_class('ostream', foreign_cpp_namespace='::std')
    ostream.set_cannot_be_constructed("abstract base class")
    ofstream = module.add_class('ofstream', foreign_cpp_namespace='::std', parent=ostream)
    ofstream.add_enum('openmode', [
            ('app', 'std::ios_base::app'),
            ('ate', 'std::ios_base::ate'),
            ('binary', 'std::ios_base::binary'),
            ('in', 'std::ios_base::in'),
            ('out', 'std::ios_base::out'),
            ('trunc', 'std::ios_base::trunc'),
            ])
    ofstream.add_constructor([Parameter.new("const char *", 'filename'),
                              Parameter.new("::std::ofstream::openmode", 'mode', default_value="std::ios_base::out")])
    ofstream.add_method('close', None, [])

    add_std_ios_openmode(module) 
開發者ID:imec-idlab,項目名稱:IEEE-802.11ah-ns-3,代碼行數:20,代碼來源:ns3modulegen_core_customizations.py

示例4: my_module_gen

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
def my_module_gen(out_file):

    mod = Module('b')
    mod.add_include('"b.h"')

    B = mod.add_class('B')
    B.add_constructor([])
    B.add_copy_constructor()
    B.add_instance_attribute('b_a', ReturnValue.new('uint32_t'))
    B.add_instance_attribute('b_b', ReturnValue.new('uint32_t'))

    mod.add_function('BDoA', None, [Parameter.new('B', 'b')])
    mod.add_function('BDoB', ReturnValue.new('B'), [])

    mod.generate(FileCodeSink(out_file) ) 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:17,代碼來源:modulegen.py

示例5: my_module_gen

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
def my_module_gen(out_file):

    mod = Module('e')
    mod.add_include('"e.h"')

    E = mod.add_class('E', memory_policy=cppclass.ReferenceCountingMethodsPolicy(decref_method='Unref', incref_method='Ref'))
    if 1:
        E.add_function_as_constructor("E::CreateWithRef", ReturnValue.new("E*", caller_owns_return=True), [])
    else:
        ## alternative:
        E.add_function_as_constructor("E::CreateWithoutRef", ReturnValue.new("E*", caller_owns_return=False), [])
    E.add_method("Do", None, [])


    mod.generate(FileCodeSink(out_file) ) 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:17,代碼來源:modulegen.py

示例6: my_module_gen

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
def my_module_gen(out_file):

    mod = Module('c')
    mod.add_include('"c.h"')

    C = mod.add_class('C')
    C.add_constructor([])
    C.add_constructor([Parameter.new('uint32_t', 'c')])
    C.add_method('DoA', None, [], is_static=True)
    C.add_method('DoB', None, [])
    C.add_method('DoC', None, [Parameter.new('uint32_t', 'c')])
    C.add_method('DoD', ReturnValue.new('uint32_t'), [])
    C.add_method('DoE', None, [], is_virtual=True)

    mod.generate(FileCodeSink(out_file) ) 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:17,代碼來源:modulegen.py

示例7: my_module_gen

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
def my_module_gen(out_file):

    mod = Module('d')
    mod.add_include('"d.h"')

    D = mod.add_class('D', memory_policy=cppclass.FreeFunctionPolicy('DDestroy'))
    D.add_instance_attribute('d', ReturnValue.new('bool'))
    D.add_function_as_constructor("DCreate", ReturnValue.new("D*", caller_owns_return=True), [])
    mod.add_function('DDoA', None, [Parameter.new('D*', 'd', transfer_ownership=False)])
    mod.add_function('DDoB', None, [Parameter.new('D&', 'd', direction=Parameter.DIRECTION_IN)])
    mod.add_function('DDoC', None, [Parameter.new('const D&', 'd',
                                                  direction=Parameter.DIRECTION_IN)])


    mod.generate(FileCodeSink(out_file) ) 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:17,代碼來源:modulegen.py

示例8: my_module_gen

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
def my_module_gen(out_file):

    mod = Module('c')
    mod.add_include('"c.h"')

    mod.add_function("GetBuffer", BufferReturn("unsigned short int*", "GetBufferLen()"), [])
    mod.add_function("GetBufferLen", ReturnValue.new("int"), [])
    mod.add_function("GetBufferChecksum", ReturnValue.new("unsigned short"), [])

    mod.generate(FileCodeSink(out_file)) 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:12,代碼來源:modulegen.py

示例9: Object_customizations

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
def Object_customizations(module):
    ## ---------------------------------------------------------------------
    ## Here we generate custom constructor code for all classes that
    ## derive from ns3::Object.  The custom constructors are needed in
    ## order to support kwargs only and to translate kwargs into ns3
    ## attributes, etc.
    ## ---------------------------------------------------------------------
    try:
        Object = module['ns3::Object']
    except KeyError:
        return

    ## add a GetTypeId method to all generatd helper classes
    def helper_class_hook(helper_class):
        decl = """
static ns3::TypeId GetTypeId (void)
{
  static ns3::TypeId tid = ns3::TypeId ("%s")
    .SetParent< %s > ()
    ;
  return tid;
}"""  % (helper_class.name, helper_class.class_.full_name)

        helper_class.add_custom_method(decl)
        helper_class.add_post_generation_code(
            "NS_OBJECT_ENSURE_REGISTERED (%s);" % helper_class.name)
    Object.add_helper_class_hook(helper_class_hook)

    def ns3_object_instance_creation_function(cpp_class, code_block, lvalue,
                                              parameters, construct_type_name):
        assert lvalue
        assert not lvalue.startswith('None')
        if cpp_class.cannot_be_constructed:
            raise CodeGenerationError("%s cannot be constructed (%s)"
                                      % cpp_class.full_name)
        if cpp_class.incomplete_type:
            raise CodeGenerationError("%s cannot be constructed (incomplete type)"
                                      % cpp_class.full_name)
        code_block.write_code("%s = new %s(%s);" % (lvalue, construct_type_name, parameters))
        code_block.write_code("%s->Ref ();" % (lvalue))

    def ns3_object_post_instance_creation_function(cpp_class, code_block, lvalue,
                                                   parameters, construct_type_name):
        code_block.write_code("ns3::CompleteConstruct(%s);" % (lvalue, ))

    Object.set_instance_creation_function(ns3_object_instance_creation_function)
    Object.set_post_instance_creation_function(ns3_object_post_instance_creation_function) 
開發者ID:ntu-dsi-dcn,項目名稱:ntu-dsi-dcn,代碼行數:49,代碼來源:ns3modulegen_core_customizations.py

示例10: my_module_gen

# 需要導入模塊: from pybindgen import ReturnValue [as 別名]
# 或者: from pybindgen.ReturnValue import new [as 別名]
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)) 
開發者ID:KTH,項目名稱:royal-chaos,代碼行數:48,代碼來源:barmodulegen.py


注:本文中的pybindgen.ReturnValue.new方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。