pybind.py (11988:665cd5f8b52b) | pybind.py (12803:a08f441d4d4c) |
---|---|
1# Copyright (c) 2017 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 49 unchanged lines hidden (view full) --- 58 def __init__(self, name, cxx_name=None, args=None): 59 self.name = name 60 self.cxx_name = cxx_name if cxx_name else name 61 self.args = args 62 63 def _conv_arg(self, value): 64 if isinstance(value, bool): 65 return "true" if value else "false" | 1# Copyright (c) 2017 ARM Limited 2# All rights reserved. 3# 4# The license below extends only to copyright in the software and shall 5# not be construed as granting a license to any other intellectual 6# property including but not limited to intellectual property relating 7# to a hardware implementation of the functionality of the software 8# licensed hereunder. You may use the software subject to the license --- 49 unchanged lines hidden (view full) --- 58 def __init__(self, name, cxx_name=None, args=None): 59 self.name = name 60 self.cxx_name = cxx_name if cxx_name else name 61 self.args = args 62 63 def _conv_arg(self, value): 64 if isinstance(value, bool): 65 return "true" if value else "false" |
66 elif isinstance(value, float, int): | 66 elif isinstance(value, (float, int)): |
67 return repr(value) 68 else: 69 raise TypeError("Unsupported PyBind default value type") 70 71 def export(self, code, cname): 72 if self.args: 73 def get_arg_decl(arg): 74 if isinstance(arg, tuple): 75 name, default = arg 76 return 'py::arg("%s") = %s' % ( 77 name, self._conv_arg(default)) 78 else: 79 return 'py::arg("%s")' % arg 80 81 code('.def("${{self.name}}", &${cname}::${{self.name}}, ') 82 code(' ' + \ 83 ', '.join([ get_arg_decl(a) for a in self.args ]) + ')') 84 else: 85 code('.def("${{self.name}}", &${cname}::${{self.cxx_name}})') | 67 return repr(value) 68 else: 69 raise TypeError("Unsupported PyBind default value type") 70 71 def export(self, code, cname): 72 if self.args: 73 def get_arg_decl(arg): 74 if isinstance(arg, tuple): 75 name, default = arg 76 return 'py::arg("%s") = %s' % ( 77 name, self._conv_arg(default)) 78 else: 79 return 'py::arg("%s")' % arg 80 81 code('.def("${{self.name}}", &${cname}::${{self.name}}, ') 82 code(' ' + \ 83 ', '.join([ get_arg_decl(a) for a in self.args ]) + ')') 84 else: 85 code('.def("${{self.name}}", &${cname}::${{self.cxx_name}})') |