File: modulegen.py

package info (click to toggle)
pybindgen 0.20.0%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,932 kB
  • sloc: python: 15,981; cpp: 1,889; ansic: 617; makefile: 86; sh: 4
file content (47 lines) | stat: -rwxr-xr-x 1,387 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#! /usr/bin/env python

import sys, os
sys.path.insert(0, os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                '..', '..'))

#import pybindgen
#import pybindgen.utils
#from pybindgen.typehandlers import base as typehandlers
from pybindgen import Module, FileCodeSink, param, retval
#from pybindgen import CppMethod, CppConstructor, CppClass, Enum
#from pybindgen.function import CustomFunctionWrapper
#from pybindgen.cppmethod import CustomCppMethodWrapper
from pybindgen import cppclass

#from pybindgen import param, retval

import pybindgen.settings
pybindgen.settings.deprecated_virtuals = False


def my_module_gen(out_file):

    mod = Module('sp')

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

    Foo = mod.add_class('Foo', memory_policy=cppclass.SharedPtr('::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))


if __name__ == '__main__':
    my_module_gen(sys.stdout)