template_instantiator/function.py
Go to the documentation of this file.
1 """Instantiate global function."""
2 
3 import gtwrap.interface_parser as parser
4 from gtwrap.template_instantiator.helpers import (instantiate_args_list,
5  instantiate_name,
6  instantiate_return_type)
7 
8 
9 class InstantiatedGlobalFunction(parser.GlobalFunction):
10  """
11  Instantiate global functions.
12 
13  E.g.
14  template<T = {double}>
15  T add(const T& x, const T& y);
16  """
17  def __init__(self, original, instantiations=(), new_name=''):
18  self.original = original
19  self.instantiations = instantiations
20  self.template = ''
21  self.parent = original.parent
22 
23  if not original.template:
24  self.name = original.name
25  self.return_type = original.return_type
26  self.args = original.args
27  else:
28  self.name = instantiate_name(
29  original.name, instantiations) if not new_name else new_name
31  original.return_type,
32  self.original.template.typenames,
33  self.instantiations,
34  # Keyword type name `This` should already be replaced in the
35  # previous class template instantiation round.
36  cpp_typename='',
37  )
38  instantiated_args = instantiate_args_list(
39  original.args.list(),
40  self.original.template.typenames,
41  self.instantiations,
42  # Keyword type name `This` should already be replaced in the
43  # previous class template instantiation round.
44  cpp_typename='',
45  )
46  self.args = parser.ArgumentList(instantiated_args)
47 
48  super().__init__(self.name,
49  self.return_type,
50  self.args,
51  self.template,
52  parent=self.parent)
53 
54  def to_cpp(self):
55  """Generate the C++ code for wrapping."""
56  if self.original.template:
57  instantiated_names = [
58  "::".join(inst.namespaces + [inst.instantiated_name()])
59  for inst in self.instantiations
60  ]
61  ret = "{}<{}>".format(self.original.name,
62  ",".join(instantiated_names))
63  else:
64  ret = self.original.name
65  return ret
66 
67  def __repr__(self):
68  return "Instantiated {}".format(
69  super(InstantiatedGlobalFunction, self).__repr__())
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.parent
parent
Definition: template_instantiator/function.py:21
format
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)
Definition: openglsupport.cpp:226
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.args
args
Definition: template_instantiator/function.py:26
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.return_type
return_type
Definition: template_instantiator/function.py:25
gtwrap.template_instantiator.helpers
Definition: helpers.py:1
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.name
name
Definition: template_instantiator/function.py:24
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.template
template
Definition: template_instantiator/function.py:20
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.original
original
Definition: template_instantiator/function.py:18
gtwrap.template_instantiator.helpers.instantiate_return_type
def instantiate_return_type(parser.ReturnType return_type, Sequence[parser.template.Typename] template_typenames, Sequence[parser.Typename] instantiations, parser.Typename cpp_typename, 'InstantiatedClass' instantiated_class=None)
Definition: helpers.py:173
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.instantiations
instantiations
Definition: template_instantiator/function.py:19
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.__repr__
def __repr__(self)
Definition: template_instantiator/function.py:67
gtwrap.template_instantiator.function.InstantiatedGlobalFunction
Definition: template_instantiator/function.py:9
gtwrap.template_instantiator.helpers.instantiate_name
def instantiate_name(str original_name, Sequence[parser.Typename] instantiations)
Definition: helpers.py:196
gtwrap.template_instantiator.helpers.instantiate_args_list
def instantiate_args_list(Sequence[parser.Argument] args_list, Sequence[parser.template.Typename] template_typenames, Sequence instantiations, parser.Typename cpp_typename)
Definition: helpers.py:144
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.to_cpp
def to_cpp(self)
Definition: template_instantiator/function.py:54
gtwrap.template_instantiator.function.InstantiatedGlobalFunction.__init__
def __init__(self, original, instantiations=(), new_name='')
Definition: template_instantiator/function.py:17
gtwrap.interface_parser
Definition: wrap/gtwrap/interface_parser/__init__.py:1


gtsam
Author(s):
autogenerated on Mon Jul 1 2024 03:01:17