matlab_wrap.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 
3 """
4 Helper script to wrap C++ to Matlab.
5 This script is installed via CMake to the user's binary directory
6 and invoked during the wrapping by CMake.
7 """
8 
9 import argparse
10 import os
11 
12 import gtwrap.interface_parser as parser
13 import gtwrap.template_instantiator as instantiator
14 from gtwrap.matlab_wrapper import MatlabWrapper, generate_content
15 
16 if __name__ == "__main__":
17  arg_parser = argparse.ArgumentParser(
18  formatter_class=argparse.ArgumentDefaultsHelpFormatter)
19  arg_parser.add_argument("--src", type=str, required=True,
20  help="Input interface .h file.")
21  arg_parser.add_argument("--module_name", type=str, required=True,
22  help="Name of the C++ class being wrapped.")
23  arg_parser.add_argument("--out", type=str, required=True,
24  help="Name of the output folder.")
25  arg_parser.add_argument(
26  "--top_module_namespaces",
27  type=str,
28  default="",
29  help="C++ namespace for the top module, e.g. `ns1::ns2::ns3`. "
30  "Only the content within this namespace and its sub-namespaces "
31  "will be wrapped. The content of this namespace will be available at "
32  "the top module level, and its sub-namespaces' in the submodules.\n"
33  "For example, `import <module_name>` gives you access to a Python "
34  "`<module_name>.Class` of the corresponding C++ `ns1::ns2::ns3::Class`"
35  ", and `from <module_name> import ns4` gives you access to a Python "
36  "`ns4.Class` of the C++ `ns1::ns2::ns3::ns4::Class`. ")
37  arg_parser.add_argument("--ignore",
38  nargs='*',
39  type=str,
40  help="A space-separated list of classes to ignore. "
41  "Class names must include their full namespaces.")
42  args = arg_parser.parse_args()
43 
44  top_module_namespaces = args.top_module_namespaces.split("::")
45  if top_module_namespaces[0]:
46  top_module_namespaces = [''] + top_module_namespaces
47 
48  with open(args.src, 'r') as f:
49  content = f.read()
50 
51  if not os.path.exists(args.src):
52  os.mkdir(args.src)
53 
54  module = parser.Module.parseString(content)
55 
56  instantiator.instantiate_namespace_inplace(module)
57 
58  import sys
59 
60  print("Ignoring classes: {}".format(args.ignore), file=sys.stderr)
61  wrapper = MatlabWrapper(module=module,
62  module_name=args.module_name,
63  top_module_namespace=top_module_namespaces,
64  ignore_classes=args.ignore)
65 
66  cc_content = wrapper.wrap()
67 
68  generate_content(cc_content, args.out)
void print(const Matrix &A, const string &s, ostream &stream)
Definition: Matrix.cpp:155
def generate_content(cc_content, path, verbose=False)


gtsam
Author(s):
autogenerated on Sat May 8 2021 02:42:46