コード例 #1
0
 def __init__(self, main_file_name):
     self.main_file_name = main_file_name
     self.main_sink = FileCodeSink(open(main_file_name, "wt"))
     self.header_name = "foomodule4.h"
     header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name)
     self.header_sink = FileCodeSink(open(header_file_name, "wt"))
     self.section_sinks = {}
コード例 #2
0
def my_module_gen():
    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[3], "wt")
    module_parser = ModuleParser('foo2', '::')
    module_parser.enable_anonymous_containers = True

    print("PYTHON_INCLUDES:", repr(sys.argv[2]), file=sys.stderr)
    gccxml_options = dict(
        include_paths=eval(sys.argv[2]),
        )

    module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=FileCodeSink(pygen_file),
                             gccxml_options=gccxml_options)
    module = module_parser.module
    foomodulegen_common.customize_module_pre(module)

    module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()')
    module_parser.scan_types()
    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    pygen_file.close()

    foomodulegen_common.customize_module(module)

    module.generate(out)
コード例 #3
0
def my_module_gen():
    pygen = [
        PygenSection('__main__', FileCodeSink(open(sys.argv[3], "wt"))),
        PygenSection('foomodulegen_module1', FileCodeSink(open(sys.argv[4], "wt")),
                     'foomodulegen_module1_local'),
        PygenSection('foomodulegen_module2', FileCodeSink(open(sys.argv[5], "wt")),
                     'foomodulegen_module2_local'),
        ]
    module_parser = ModuleParser('foo4', '::')
    module_parser.enable_anonymous_containers = True

    gccxml_options = dict(
        include_paths=eval(sys.argv[2]),
        )

    module_parser.parse_init([sys.argv[1]], includes=['"foo.h"'], pygen_sink=pygen, pygen_classifier=MyPygenClassifier(),
                             gccxml_options=gccxml_options)
    module = module_parser.module
    module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()')
    module_parser.scan_types()
    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    for sect in pygen:
        sect.code_sink.file.close()
コード例 #4
0
 def __init__(self, dir):
     self.main_file_name = os.path.join(dir, "foomodule4.cc")
     self.main_sink = FileCodeSink(open(self.main_file_name, "wt"))
     self.header_name = "foomodule4.h"
     header_file_name = os.path.join(dir, self.header_name)
     self.header_sink = FileCodeSink(open(header_file_name, "wt"))
     self.section_sinks = {}
コード例 #5
0
 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"))
コード例 #6
0
ファイル: hellomodulegen.py プロジェクト: Be1thaz0r/HoBHIS
def my_module_gen(out_file):
    out = FileCodeSink(out_file)
    #pybindgen.write_preamble(out)
    out.writeln("#include \"hello.h\"")
    module_parser = ModuleParser('hello')
    module_parser.add_pre_scan_hook(pre_scan_hook)
    module = module_parser.parse(sys.argv[1:])
    module.generate(out)
コード例 #7
0
def my_module_gen(out_file):
    out = FileCodeSink(out_file)
    #pybindgen.write_preamble(out)
    out.writeln("#include \"hello.h\"")
    module_parser = ModuleParser('hello')
    module_parser.add_pre_scan_hook(pre_scan_hook)
    module = module_parser.parse(sys.argv[1:])
    module.generate(out)
コード例 #8
0
    def __init__(self, main_file_name):
        self.main_file_name = main_file_name
        self.main_sink = FileCodeSink(open("src/" + main_file_name, "wt"))
        self.header_name = "tr_module.h"
        header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name)
        self.header_sink = FileCodeSink(open("src/" + header_file_name, "wt"))
        self.section_sinks = {}

        self.main_sink.writeln(self._header)
        self.header_sink.writeln(self._header)
コード例 #9
0
 def get_section_code_sink(self, section_name):
     if section_name == "__main__":
         return self.main_sink
     try:
         return self.section_sinks[section_name]
     except KeyError:
         file_name = os.path.join(os.path.dirname(self.main_file_name), "src/%s.cc" % section_name)
         sink = FileCodeSink(open(file_name, "wt"))
         self.section_sinks[section_name] = sink
         sink.writeln(self._header)
         return sink
コード例 #10
0
    def __init__(self, main_file_name):
        self.main_file_name = main_file_name
        self.main_sink = FileCodeSink(open('src/' + main_file_name, "wt"))
        self.header_name = "tr_module.h"
        header_file_name = os.path.join(os.path.dirname(self.main_file_name),
                                        self.header_name)
        self.header_sink = FileCodeSink(open('src/' + header_file_name, "wt"))
        self.section_sinks = {}

        self.main_sink.writeln(self._header)
        self.header_sink.writeln(self._header)
コード例 #11
0
 def get_section_code_sink(self, section_name):
     if section_name == '__main__':
         return self.main_sink
     try:
         return self.section_sinks[section_name]
     except KeyError:
         file_name = os.path.join(os.path.dirname(self.main_file_name),
                                  "src/%s.cc" % section_name)
         sink = FileCodeSink(open(file_name, "wt"))
         self.section_sinks[section_name] = sink
         sink.writeln(self._header)
         return sink
コード例 #12
0
def my_module_gen(out_file, pygccxml_mode):
    if pygccxml_mode == 'castxml':
        from pybindgen.castxmlparser import ModuleParser
    else:
        from pybindgen.gccxmlparser import ModuleParser

    out = FileCodeSink(out_file)
    #pybindgen.write_preamble(out)
    out.writeln("#include \"hello.h\"")
    module_parser = ModuleParser('hello')
    module_parser.add_pre_scan_hook(pre_scan_hook)
    module = module_parser.parse(sys.argv[2:])
    module.generate(out)
コード例 #13
0
ファイル: pybindgen.py プロジェクト: NJannasch/emxArray
def module_gen():
    os.chdir('/home/trevorsweetnam/Dropbox/notebooks/eef/emxarr/codegen/dll/emx_test')
    #module_parser = ModuleParser('emx_test_emxAPI', '::')
    #module = module_parser.parse(['emx_test_emxAPI.h'])
    #module.add_include('"emx_test_emxAPI.h"')
    
    module_parser = ModuleParser('emx_test', '::')
    module = module_parser.parse(['emx_test.h'])
    module.add_include('"rt_noninfite.h"')
    module.add_include('"emx_test_emxutil.h"')
    
    pybindgen.write_preamble(FileCodeSink(sys.stdout))
    module.generate(FileCodeSink(sys.stdout))
コード例 #14
0
    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), 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            
コード例 #15
0
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))
コード例 #16
0
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))
コード例 #17
0
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)
コード例 #18
0
def my_module_gen():
    libName = 'libPy' + sys.argv[2]
    className = sys.argv[2] + '.hh'
    includeFile = sys.argv[1] + '/' + className
    module_parser = ModuleParser(libName, '::')
    module_parser.parse([includeFile],
                        includes=['"' + includeFile + '"'],
                        pygen_sink=FileCodeSink(sys.stdout))
コード例 #19
0
def my_module_gen():
    if sys.argv[6] == 'castxml':
        from pybindgen.castxmlparser import ModuleParser, PygenClassifier, PygenSection
    else:
        from pybindgen.gccxmlparser import ModuleParser, PygenClassifier, PygenSection

    class MyPygenClassifier(PygenClassifier):
        def classify(self, pygccxml_definition):
            if pygccxml_definition.name and pygccxml_definition.name.lower(
            ) <= 'l':
                return 'foomodulegen_module1'
            else:
                return 'foomodulegen_module2'

    pygen = [
        PygenSection('__main__', FileCodeSink(open(sys.argv[3], "wt"))),
        PygenSection('foomodulegen_module1',
                     FileCodeSink(open(sys.argv[4], "wt")),
                     'foomodulegen_module1_local'),
        PygenSection('foomodulegen_module2',
                     FileCodeSink(open(sys.argv[5], "wt")),
                     'foomodulegen_module2_local'),
    ]
    module_parser = ModuleParser('foo4', '::')
    module_parser.enable_anonymous_containers = True

    gccxml_options = dict(include_paths=eval(sys.argv[2]), )

    module_parser.parse_init([sys.argv[1]],
                             includes=['"foo.h"'],
                             pygen_sink=pygen,
                             pygen_classifier=MyPygenClassifier(),
                             gccxml_options=gccxml_options)
    module = module_parser.module
    foomodulegen_common.customize_module_pre(module)
    module.add_exception('exception',
                         foreign_cpp_namespace='std',
                         message_rvalue='%(EXC)s.what()')
    module_parser.scan_types()
    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    for sect in pygen:
        sect.code_sink.file.close()
コード例 #20
0
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) )
コード例 #21
0
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))
コード例 #22
0
def my_module_gen(out_file):
    mod = Module('f')
    mod.add_include('"f.h"')

    FBase = mod.add_class('FBase', allow_subclassing=True)
    
    FBase.add_constructor([])
    FBase.add_method('DoA', None, [], is_virtual=True, is_pure_virtual=True)
    FBase.add_method('PrivDoB', None, [], is_virtual=True, is_pure_virtual=True, visibility='private')
    FBase.add_method('DoB', None, [])

    mod.generate(FileCodeSink(out_file) )
コード例 #23
0
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=cppclass.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 >> 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()

    ## ---- finally, generate the whole thing ----
    mod.generate(FileCodeSink(out_file))
コード例 #24
0
ファイル: modulegen.py プロジェクト: I201821180/NextgenWifi
def my_module_gen(out_file):

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

    B = mod.add_class('B')
    B.add_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) )
コード例 #25
0
def my_module_gen():
    pygccxml_mode = sys.argv[4]
    if pygccxml_mode == 'castxml':
        from pybindgen.castxmlparser import ModuleParser
    else:
        from pybindgen.gccxmlparser import ModuleParser

    out = FileCodeSink(sys.stdout)
    pygen_file = open(sys.argv[3], "wt")
    module_parser = ModuleParser('foo2', '::')
    module_parser.enable_anonymous_containers = True

    print("PYTHON_INCLUDES:", repr(sys.argv[2]), file=sys.stderr)
    kwargs = {
        "{mode}_options".format(mode=pygccxml_mode):
        dict(include_paths=eval(sys.argv[2]), )
    }
    module_parser.parse_init([sys.argv[1]],
                             includes=['"foo.h"'],
                             pygen_sink=FileCodeSink(pygen_file),
                             **kwargs)
    module = module_parser.module
    foomodulegen_common.customize_module_pre(module)

    module.add_exception('exception',
                         foreign_cpp_namespace='std',
                         message_rvalue='%(EXC)s.what()')
    module_parser.scan_types()
    module_parser.scan_methods()
    module_parser.scan_functions()
    module_parser.parse_finalize()

    pygen_file.close()

    foomodulegen_common.customize_module(module)

    module.generate(out)
コード例 #26
0
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) )
コード例 #27
0
ファイル: modulegen.py プロジェクト: I201821180/NextgenWifi
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))
コード例 #28
0
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))
コード例 #29
0
def my_module_gen():
    out = FileCodeSink(sys.stdout)
    root_module = foomodulegen_generated.module_init()
    root_module.add_exception('exception', foreign_cpp_namespace='std', message_rvalue='%(EXC)s.what()')
    foomodulegen_common.customize_module_pre(root_module)

    ## this is a very special case when we want to change the name of
    ## the python module to allow parallel testing of the same basic
    ## module 'foo' generated by 3 different code paths; normally
    ## users don't need this.
    root_module.name = 'foo3'

    foomodulegen_generated.register_types(root_module)
    foomodulegen_generated.register_methods(root_module)
    foomodulegen_generated.register_functions(root_module)
    foomodulegen_common.customize_module(root_module)

    root_module.generate(out)
コード例 #30
0
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))
コード例 #31
0
ファイル: modulegen.py プロジェクト: I201821180/NextgenWifi
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))
コード例 #32
0
ファイル: modulegen.py プロジェクト: wroldwiedbwe/pybindgen
def my_module_gen(out_file):

    mod = Module('sp')

    mod.add_include('"sp.h"')

    Foo = mod.add_class('Foo', memory_policy=StdSharedPtr('::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('std::shared_ptr<Foo>', 'foo')])

    mod.add_function('function_that_returns_foo',
                     retval('std::shared_ptr<Foo>'), [])

    ## ---- finally, generate the whole thing ----
    mod.generate(FileCodeSink(out_file))
コード例 #33
0
ファイル: modulegen.py プロジェクト: I201821180/NextgenWifi
def my_module_gen(out_file):

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

    mod.header.writeln("""void _wrap_Visit(int value, void *data);""")
    mod.body.writeln("""
void _wrap_Visit(int value, void *data)
{
    PyObject *callback = (PyObject*) data;
    PyObject_CallFunction(callback, (char*) "i", value);
}
""")

    mod.add_function(
        "visit", None, [Parameter.new("Visitor", "visitor")]
        # the 'data' parameter is inserted automatically
        # by the custom callback type handler
    )

    mod.generate(FileCodeSink(out_file))
コード例 #34
0
class TrMultiSectionFactory(MultiSectionFactory):
    _header = (
        "/* ** GENERATED CODE -- DO NOT EDIT **\n"
        " *\n"
        " * Copyright (c) 2012 Dan Eicher\n"
        " *\n"
        " * Permission is hereby granted, free of charge, to any person obtaining a\n"
        ' * copy of this software and associated documentation files (the "Software"),\n'
        " * to deal in the Software without restriction, including without limitation\n"
        " * the rights to use, copy, modify, merge, publish, distribute, sublicense,\n"
        " * and/or sell copies of the Software, and to permit persons to whom the\n"
        " * Software is furnished to do so, subject to the following conditions:\n"
        " *\n"
        " * The above copyright notice and this permission notice shall be included in\n"
        " * all copies or substantial portions of the Software.\n"
        " *\n"
        ' * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n'
        " * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n"
        " * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n"
        " * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n"
        " * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING\n"
        " * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER\n"
        " * DEALINGS IN THE SOFTWARE.\n"
        " *\n"
        " */\n"
    )

    def __init__(self, main_file_name):
        self.main_file_name = main_file_name
        self.main_sink = FileCodeSink(open("src/" + main_file_name, "wt"))
        self.header_name = "tr_module.h"
        header_file_name = os.path.join(os.path.dirname(self.main_file_name), self.header_name)
        self.header_sink = FileCodeSink(open("src/" + header_file_name, "wt"))
        self.section_sinks = {}

        self.main_sink.writeln(self._header)
        self.header_sink.writeln(self._header)

    def get_section_code_sink(self, section_name):
        if section_name == "__main__":
            return self.main_sink
        try:
            return self.section_sinks[section_name]
        except KeyError:
            file_name = os.path.join(os.path.dirname(self.main_file_name), "src/%s.cc" % section_name)
            sink = FileCodeSink(open(file_name, "wt"))
            self.section_sinks[section_name] = sink
            sink.writeln(self._header)
            return sink

    def get_main_code_sink(self):
        return self.main_sink

    def get_common_header_code_sink(self):
        return self.header_sink

    def get_common_header_include(self):
        return '"%s"' % self.header_name

    def close(self):
        self.header_sink.file.close()
        self.main_sink.file.close()
        for sink in self.section_sinks.itervalues():
            sink.file.close()