Skip to content

Commit 055fee3

Browse files
committed
get_typename helper method
1 parent 2a81d92 commit 055fee3

1 file changed

Lines changed: 20 additions & 12 deletions

File tree

gtwrap/interface_parser/type.py

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,13 @@ def __repr__(self) -> str:
212212
is_const="const " if self.is_const else "",
213213
is_ptr_or_ref=" " + is_ptr_or_ref if is_ptr_or_ref else "")
214214

215+
def get_typename(self):
216+
"""
217+
Get the typename of this type without any qualifiers.
218+
E.g. for `const gtsam::Pose3& pose` this will return `gtsam::Pose3`.
219+
"""
220+
return self.typename.to_cpp()
221+
215222
def to_cpp(self) -> str:
216223
"""
217224
Generate the C++ code for wrapping.
@@ -221,22 +228,18 @@ def to_cpp(self) -> str:
221228

222229
if self.is_shared_ptr:
223230
typename = "std::shared_ptr<{typename}>".format(
224-
typename=self.typename.to_cpp())
231+
typename=self.get_typename())
225232
elif self.is_ptr:
226233
typename = "{typename}*".format(typename=self.typename.to_cpp())
227234
elif self.is_ref:
228235
typename = typename = "{typename}&".format(
229-
typename=self.typename.to_cpp())
236+
typename=self.get_typename())
230237
else:
231-
typename = self.typename.to_cpp()
238+
typename = self.get_typename()
232239

233240
return ("{const}{typename}".format(
234241
const="const " if self.is_const else "", typename=typename))
235242

236-
def get_typename(self):
237-
"""Convenience method to get the typename of this type."""
238-
return self.typename.name
239-
240243

241244
class TemplatedType:
242245
"""
@@ -283,16 +286,21 @@ def __repr__(self):
283286
return "TemplatedType({typename.namespaces}::{typename.name})".format(
284287
typename=self.typename)
285288

286-
def to_cpp(self):
289+
def get_typename(self):
287290
"""
288-
Generate the C++ code for wrapping.
291+
Get the typename of this type without any qualifiers.
292+
E.g. for `const std::vector<double>& indices` this will return `std::vector<double>`.
289293
"""
290294
# Use Type.to_cpp to do the heavy lifting for the template parameters.
291295
template_args = ", ".join([t.to_cpp() for t in self.template_params])
292296

293-
typename = "{typename}<{template_args}>".format(
294-
typename=self.typename.qualified_name(),
295-
template_args=template_args)
297+
return f"{self.typename.qualified_name()}<{template_args}>"
298+
299+
def to_cpp(self):
300+
"""
301+
Generate the C++ code for wrapping.
302+
"""
303+
typename = self.get_typename()
296304

297305
if self.is_shared_ptr:
298306
typename = f"std::shared_ptr<{typename}>"

0 commit comments

Comments
 (0)