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__())
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.constructor.InstantiatedConstructor.template
template
Definition: constructor.py:25
gtwrap.template_instantiator.constructor.InstantiatedConstructor.args
args
Definition: constructor.py:24
gtwrap.template_instantiator.constructor.InstantiatedConstructor.name
name
Definition: constructor.py:23
gtwrap.template_instantiator.constructor.InstantiatedConstructor.construct
def construct(cls, parser.Constructor original, List[str] typenames, List[parser.Typename] class_instantiations, List[parser.Typename] method_instantiations, List[parser.Argument] instantiated_args, 'InstantiatedClass' parent)
Definition: constructor.py:36
gtwrap.template_instantiator.constructor.InstantiatedConstructor.original
original
Definition: constructor.py:21
gtwrap.template_instantiator.constructor.InstantiatedConstructor.instantiations
instantiations
Definition: constructor.py:22
gtwrap.template_instantiator.constructor.InstantiatedConstructor.to_cpp
def to_cpp(self)
Definition: constructor.py:51
gtwrap.template_instantiator.constructor.InstantiatedConstructor.__init__
def __init__(self, parser.Constructor original, Iterable[parser.Typename] instantiations=())
Definition: constructor.py:20
gtwrap.template_instantiator.constructor.InstantiatedConstructor.__repr__
def __repr__(self)
Definition: constructor.py:63
gtwrap.interface_parser
Definition: wrap/gtwrap/interface_parser/__init__.py:1
gtwrap.template_instantiator.constructor.InstantiatedConstructor
Definition: constructor.py:10
gtwrap.template_instantiator.constructor.InstantiatedConstructor.parent
parent
Definition: constructor.py:26


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:02:02