Python pybindgen.FileCodeSink() Examples

The following are 30 code examples of pybindgen.FileCodeSink(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pybindgen , or try the search function .
Example #1
Source File: modulegen.py    From royal-chaos with MIT License 6 votes vote down vote up
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)) 
Example #2
Source File: modulegen.py    From royal-chaos with MIT License 6 votes vote down vote up
def my_module_gen(out_file):

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

    H = mod.add_class('H')
    H.add_constructor([])
    H.add_method('Do', None, [])

    Inner = mod.add_class('Inner', outer_class=H)
    Inner.add_constructor([])
    Inner.add_method('Do', None, [])

    MostInner = mod.add_class('MostInner', outer_class=Inner)
    MostInner.add_constructor([])
    MostInner.add_method('Do', None, [])

    mod.generate(FileCodeSink(out_file)) 
Example #3
Source File: modulegen__gcc_ILP32.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #4
Source File: bmodulegen.py    From royal-chaos with MIT License 5 votes vote down vote up
def my_module_gen(out_file):
    mod = Module('b')
    mod.add_include('"b.h"')

    # Base
    Base = mod.add_class("Base", allow_subclassing = True, import_from_module='a')
    Base.add_constructor([])
    Base.add_method("do_something", None, [], is_virtual=True)

    # Derived
    Derived = mod.add_class("Derived", allow_subclassing=True, parent=Base)
    Derived.add_constructor([])
    Derived.add_method("do_something", None, [], is_virtual=True)

    mod.generate(FileCodeSink(out_file) ) 
Example #5
Source File: ns3modulegen.py    From royal-chaos with MIT License 5 votes vote down vote up
def __init__(self, main_file_name, modules):
        super(MyMultiSectionFactory, self).__init__()
        self.main_file_name = main_file_name
        self.main_sink = FileCodeSink(open(main_file_name, "wt"))
        self.header_name = "ns3module.h"
        header_file_name = os.path.join(os.path.dirname(self.main_file_name), 'pch', self.header_name)
        self.header_sink = FileCodeSink(open(header_file_name, "wt"))
        self.section_sinks = {'__main__': self.main_sink}

        for module in modules:
            section_name = 'ns3_module_%s' % module.replace('-', '_')
            file_name = os.path.join(os.path.dirname(self.main_file_name), "%s.cc" % section_name)
            sink = FileCodeSink(open(file_name, "wt"))
            self.section_sinks[section_name] = sink 
Example #6
Source File: modulegen__gcc_LP64.py    From royal-chaos with MIT License 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #7
Source File: ns3modulegen-modular.py    From royal-chaos with MIT License 5 votes vote down vote up
def __init__(self, main_file_name):
        super(MyMultiSectionFactory, self).__init__()
        self.main_file_name = main_file_name
        self.main_sink = FileCodeSink(open(main_file_name, "wt"))
        self.header_name = "ns3module.h"
        header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name)
        #print >> sys.stderr, ">>>>>>>>>>>>>>>>>", header_file_name, main_file_name
        self.header_sink = FileCodeSink(open(header_file_name, "wt")) 
Example #8
Source File: modulegen.py    From royal-chaos with MIT License 5 votes vote down vote up
def my_module_gen(out_file):
    mod = Module('g')
    mod.add_include('"g.h"')

    mod.add_function('GDoA', None, [])
    G = mod.add_cpp_namespace("G")
    G.add_function('GDoB', None, [])
    GInner = G.add_cpp_namespace("GInner")
    GInner.add_function('GDoC', None, [])

    G.add_include('<fstream>')

    ofstream = G.add_class('ofstream', foreign_cpp_namespace='::std')
    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, [])

    mod.generate(FileCodeSink(out_file)) 
Example #9
Source File: modulegen.py    From royal-chaos with MIT License 5 votes vote down vote up
def my_module_gen(out_file):

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

    mod.add_function('ADoA', None, [])
    mod.add_function('ADoB', None, [Parameter.new('uint32_t', 'b')])
    mod.add_function('ADoC', ReturnValue.new('uint32_t'), [])

    mod.generate(FileCodeSink(out_file) ) 
Example #10
Source File: module-autoscan.py    From royal-chaos with MIT License 5 votes vote down vote up
def my_module_gen():
    module_parser = ModuleParser('a2', '::')
    module_parser.parse([sys.argv[1]], includes=['"a.h"'], pygen_sink=FileCodeSink(sys.stdout)) 
Example #11
Source File: module-autogen.py    From royal-chaos with MIT License 5 votes vote down vote up
def my_module_gen():
    module_parser = ModuleParser('a1', '::')
    module = module_parser.parse([sys.argv[1]])
    module.add_include('"a.h"')

    module.generate(FileCodeSink(sys.stdout)) 
Example #12
Source File: testapi-pybindgen.py    From royal-chaos with MIT License 5 votes vote down vote up
def my_module_gen(out_file):

    pybindgen.settings.deprecated_virtuals = False

    mod = Module('testapi_pybindgen')
    mod.add_include('"testapi.h"')

    mod.add_function('func1', None, [])
    mod.add_function('func2', 'double', [param('double', 'x'),
                                         param('double', 'y'),
                                         param('double', 'z'),
                                         ])

    Multiplier = mod.add_class('Multiplier', allow_subclassing=True)
    Multiplier.add_constructor([])
    Multiplier.add_constructor([param('double', 'factor')])

    Multiplier.add_method('GetFactor', 'double', [], is_const=True)
    Multiplier.add_method('SetFactor', 'void', [param('double', 'f')], is_const=True)
    Multiplier.add_method('SetFactor', 'void', [], is_const=True)
    Multiplier.add_method('Multiply', 'double', [param('double', 'value')], is_virtual=True, is_const=True)

    mod.add_function('call_virtual_from_cpp', 'double', [param('Multiplier const *', 'obj'), param('double', 'value')])
    

    mod.generate(FileCodeSink(out_file)) 
Example #13
Source File: modulegen__gcc_LP64.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #14
Source File: modulegen__gcc_ILP32.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #15
Source File: modulegen__gcc_LP64.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #16
Source File: modulegen__gcc_LP64.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #17
Source File: modulegen__gcc_LP64.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #18
Source File: modulegen__gcc_LP64.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #19
Source File: modulegen__gcc_ILP32.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #20
Source File: modulegen__gcc_LP64.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #21
Source File: modulegen__gcc_LP64.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #22
Source File: modulegen__gcc_ILP32.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #23
Source File: modulegen__gcc_LP64.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #24
Source File: ns3modulegen.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, main_file_name, modules):
        super(MyMultiSectionFactory, self).__init__()
        self.main_file_name = main_file_name
        self.main_sink = FileCodeSink(open(main_file_name, "wt"))
        self.header_name = "ns3module.h"
        header_file_name = os.path.join(os.path.dirname(self.main_file_name), 'pch', self.header_name)
        self.header_sink = FileCodeSink(open(header_file_name, "wt"))
        self.section_sinks = {'__main__': self.main_sink}

        for module in modules:
            section_name = 'ns3_module_%s' % module.replace('-', '_')
            file_name = os.path.join(os.path.dirname(self.main_file_name), "%s.cc" % section_name)
            sink = FileCodeSink(open(file_name, "wt"))
            self.section_sinks[section_name] = sink 
Example #25
Source File: ns3modulegen-modular.py    From ns3-rdma with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self, main_file_name):
        super(MyMultiSectionFactory, self).__init__()
        self.main_file_name = main_file_name
        self.main_sink = FileCodeSink(open(main_file_name, "wt"))
        self.header_name = "ns3module.h"
        header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name)
        #print >> sys.stderr, ">>>>>>>>>>>>>>>>>", header_file_name, main_file_name
        self.header_sink = FileCodeSink(open(header_file_name, "wt")) 
Example #26
Source File: modulegen__gcc_ILP32.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #27
Source File: modulegen__gcc_LP64.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #28
Source File: modulegen__gcc_LP64.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #29
Source File: modulegen__gcc_ILP32.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out) 
Example #30
Source File: modulegen__gcc_LP64.py    From 802.11ah-ns3 with GNU General Public License v2.0 5 votes vote down vote up
def main():
    out = FileCodeSink(sys.stdout)
    root_module = module_init()
    register_types(root_module)
    register_methods(root_module)
    register_functions(root_module)
    root_module.generate(out)