constructor.py
Go to the documentation of this file.
1 """Class constructor instantiator."""
2 
3 # pylint: disable=unused-argument
4 
5 from typing import Iterable, List
6 
7 import gtwrap.interface_parser as parser
8 
9 
10 class InstantiatedConstructor(parser.Constructor):
11  """
12  Instantiate constructor with template parameters.
13 
14  E.g.
15  class A {
16  template<X, Y>
17  A(X x, Y y);
18  }
19  """
20  def __init__(self,
21  original: parser.Constructor,
22  instantiations: Iterable[parser.Typename] = ()):
23  self.original = original
24  self.instantiations = instantiations
25  self.name = original.name
26  self.args = original.args
27  self.template = original.template
28  self.parent = original.parent
29 
30  super().__init__(self.name,
31  self.args,
32  self.template,
33  parent=self.parent)
34 
35  @classmethod
36  def construct(cls, original: parser.Constructor, typenames: List[str],
37  class_instantiations: List[parser.Typename],
38  method_instantiations: List[parser.Typename],
39  instantiated_args: List[parser.Argument],
40  parent: 'InstantiatedClass'):
41  """Class method to construct object as required by InstantiationHelper."""
42  method = parser.Constructor(
43  name=parent.name,
44  args=parser.ArgumentList(instantiated_args),
45  template=original.template,
46  parent=parent,
47  )
48  return InstantiatedConstructor(method,
49  instantiations=method_instantiations)
50 
51  def to_cpp(self):
52  """Generate the C++ code for wrapping."""
53  if self.original.template:
54  # to_cpp will handle all the namespacing and templating
55  instantiation_list = [x.to_cpp() for x in self.instantiations]
56  # now can simply combine the instantiations, separated by commas
57  ret = "{}<{}>".format(self.original.name,
58  ",".join(instantiation_list))
59  else:
60  ret = self.original.name
61  return ret
62 
63  def __repr__(self):
64  return "Instantiated {}".format(super().__repr__())
std::string format(const std::string &str, const std::vector< std::string > &find, const std::vector< std::string > &replace)


gtsam
Author(s):
autogenerated on Tue Jul 4 2023 02:34:03