1 """Mixins for reducing the amount of boilerplate in the main wrapper class.""" 
    3 from typing 
import Any, Tuple, Union
 
   10     """Mixin to provide various checks.""" 
   12     not_ptr_type: Tuple = (
'int', 
'double', 
'bool', 
'char', 
'unsigned char',
 
   15     ignore_namespace: Tuple = (
'Matrix', 
'Vector', 
'Point2', 
'Point3')
 
   17     ignore_methods: Tuple = (
'pickle', )
 
   19     whitelist: Tuple = (
'serializable', 
'serialize')
 
   21     not_check_type: list = []
 
   25             if m.name 
in self.whitelist:
 
   31         Determine if the `arg_type` can have a pointer to it. 
   33         E.g. `Pose3` can have `Pose3*` but  
   34         `Matrix` should not have `Matrix*`. 
   36         return (arg_type.typename.name 
not in self.not_ptr_type
 
   37                 and arg_type.typename.name 
not in self.ignore_namespace
 
   38                 and arg_type.typename.name != 
'string')
 
   42         Determine if the `interface_parser.Type` should be treated as a 
   43         shared pointer in the wrapper. 
   45         return arg_type.is_shared_ptr
 
   47     def is_ptr(self, arg_type: parser.Type):
 
   49         Determine if the `interface_parser.Type` should be treated as a 
   50         raw pointer in the wrapper. 
   52         return arg_type.is_ptr
 
   54     def is_ref(self, arg_type: parser.Type):
 
   56         Determine if the `interface_parser.Type` should be treated as a 
   57         reference in the wrapper. 
   59         return arg_type.typename.name 
not in self.ignore_namespace 
and \
 
   60                arg_type.typename.name 
not in self.not_ptr_type 
and \
 
   64         """Check if arg_type is an enum in the class `class_`.""" 
   66             class_enums = [enum.name 
for enum 
in class_.enums]
 
   67             return arg_type.typename.name 
in class_enums
 
   72         """Check if arg_type is a global enum.""" 
   76                 member.name 
for member 
in class_.parent.content
 
   79             return arg_type.typename.name 
in global_enums
 
   83     def is_enum(self, arg_type: parser.Type, class_: parser.Class):
 
   84         """Check if `arg_type` is an enum.""" 
   90     """Mixin to provide formatting utilities.""" 
   92     ignore_namespace: tuple
 
   98                           instantiated_class: instantiator.InstantiatedClass):
 
   99         """Reformatted the C++ class name to fit Matlab defined naming 
  102         if len(instantiated_class.ctors) != 0:
 
  103             return instantiated_class.ctors[0].name
 
  105         return instantiated_class.name
 
  108                           type_name: parser.Typename,
 
  109                           separator: str = 
'::',
 
  110                           include_namespace: bool = 
True,
 
  111                           is_constructor: bool = 
False,
 
  112                           is_method: bool = 
False):
 
  115             type_name: an interface_parser.Typename to reformat 
  116             separator: the statement to add between namespaces and typename 
  117             include_namespace: whether to include namespaces when reformatting 
  118             is_constructor: if the typename will be in a constructor 
  119             is_method: if the typename will be in a method 
  122             constructor and method cannot both be true 
  124         if is_constructor 
and is_method:
 
  126                 'Constructor and method parameters cannot both be True')
 
  128         formatted_type_name = 
'' 
  129         name = type_name.name
 
  131         if include_namespace:
 
  132             for namespace 
in type_name.namespaces:
 
  133                 if name 
not in self.ignore_namespace 
and namespace != 
'':
 
  134                     formatted_type_name += namespace + separator
 
  137             formatted_type_name += self.data_type.
get(name) 
or name
 
  139             formatted_type_name += self.data_type_param.
get(name) 
or name
 
  141             formatted_type_name += 
str(name)
 
  143         if separator == 
"::":  
 
  145             for idx, _ 
in enumerate(type_name.instantiations):
 
  148                                            include_namespace=include_namespace,
 
  149                                            is_constructor=is_constructor,
 
  150                                            is_method=is_method))
 
  151                 templates.append(template)
 
  153             if len(templates) > 0:  
 
  154                 formatted_type_name += 
'<{}>'.
format(
','.join(templates))
 
  157             for idx, _ 
in enumerate(type_name.instantiations):
 
  158                 formatted_type_name += 
'{}'.
format(
 
  161                                            include_namespace=
False,
 
  162                                            is_constructor=is_constructor,
 
  163                                            is_method=is_method))
 
  165         return formatted_type_name
 
  168                             return_type: parser.function.ReturnType,
 
  169                             include_namespace: bool = 
False,
 
  170                             separator: str = 
"::"):
 
  171         """Format return_type. 
  174             return_type: an interface_parser.ReturnType to reformat 
  175             include_namespace: whether to include namespaces when reformatting 
  179         if self._return_count(return_type) == 1:
 
  181                 return_type.type1.typename,
 
  183                 include_namespace=include_namespace)
 
  185             return_wrap = 
'pair< {type1}, {type2} >'.
format(
 
  187                     return_type.type1.typename,
 
  189                     include_namespace=include_namespace),
 
  191                     return_type.type2.typename,
 
  193                     include_namespace=include_namespace))
 
  198                            instantiated_class: instantiator.InstantiatedClass,
 
  199                            separator: str = 
''):
 
  200         """Format a template_instantiator.InstantiatedClass name.""" 
  201         if instantiated_class.parent == 
'':
 
  202             parent_full_ns = [
'']
 
  204             parent_full_ns = instantiated_class.parent.full_namespaces()
 
  206         parentname = 
"".join([separator + x
 
  207                               for x 
in parent_full_ns]) + separator
 
  209         class_name = parentname[2 * 
len(separator):]
 
  211         class_name += instantiated_class.name
 
  216                               static_method: parser.StaticMethod,
 
  217                               separator: str = 
''):
 
  220                 gtsam.Point3.staticFunction() 
  224         if isinstance(static_method, parser.StaticMethod):
 
  225             method += static_method.parent.to_cpp() + separator
 
  230                                 function: Union[parser.GlobalFunction, Any],
 
  231                                 separator: str = 
''):
 
  234                 gtsamPoint3.staticFunction 
  238         if isinstance(function, parser.GlobalFunction):
 
  239             method += 
"".join([separator + x 
for x 
in function.parent.full_namespaces()]) + \
 
  242         return method[2 * 
len(separator):]