|
7 | 7 | import pickle |
8 | 8 | import sys |
9 | 9 |
|
10 | | -from .autowrap.context import HeaderContext |
| 10 | +from .autowrap.context import HeaderContext, ClassContext |
11 | 11 | from .autowrap.render_cls_rpy_include import render_cls_rpy_include_hpp |
12 | 12 | from .util import maybe_write_file |
13 | 13 |
|
14 | 14 |
|
| 15 | +def _get_classes(hctx: HeaderContext): |
| 16 | + def _get_child_classes(c: ClassContext): |
| 17 | + for c in c.child_classes: |
| 18 | + yield c |
| 19 | + _get_child_classes(c) |
| 20 | + |
| 21 | + for cls in hctx.classes: |
| 22 | + yield cls |
| 23 | + yield from _get_child_classes(cls) |
| 24 | + |
| 25 | + |
15 | 26 | def _write_wrapper_cpp( |
16 | | - input_dat: pathlib.Path, class_name: str, output_hpp: pathlib.Path |
| 27 | + input_dat: pathlib.Path, yml_id: str, output_hpp: pathlib.Path |
17 | 28 | ): |
18 | 29 | with open(input_dat, "rb") as fp: |
19 | 30 | hctx = pickle.load(fp) |
20 | 31 |
|
21 | 32 | assert isinstance(hctx, HeaderContext) |
22 | 33 |
|
23 | | - for cls in hctx.classes: |
24 | | - if cls.full_cpp_name == class_name: |
| 34 | + avail = [] |
| 35 | + for cls in _get_classes(hctx): |
| 36 | + avail.append(cls.yml_id) |
| 37 | + if cls.yml_id == yml_id: |
25 | 38 | break |
26 | 39 | else: |
27 | | - raise ValueError(f"internal error: cannot find {class_name}") |
| 40 | + avail = ", ".join(avail) |
| 41 | + raise ValueError(f"internal error: cannot find {yml_id} (found {avail})") |
28 | 42 |
|
29 | 43 | content = render_cls_rpy_include_hpp(hctx, cls) |
30 | 44 | maybe_write_file(output_hpp, content) |
31 | 45 |
|
32 | 46 |
|
33 | 47 | def main(): |
34 | 48 | try: |
35 | | - _, input_dat, class_name, output_hpp = sys.argv |
| 49 | + _, input_dat, yml_id, output_hpp = sys.argv |
36 | 50 | except ValueError: |
37 | 51 | print(inspect.cleandoc(__doc__ or ""), file=sys.stderr) |
38 | 52 | sys.exit(1) |
39 | 53 |
|
40 | | - _write_wrapper_cpp(pathlib.Path(input_dat), class_name, pathlib.Path(output_hpp)) |
| 54 | + _write_wrapper_cpp(pathlib.Path(input_dat), yml_id, pathlib.Path(output_hpp)) |
41 | 55 |
|
42 | 56 |
|
43 | 57 | if __name__ == "__main__": |
|
0 commit comments