Skip to content

Commit

Permalink
#13 Cosmetic changes to templated wrapper names
Browse files Browse the repository at this point in the history
  • Loading branch information
kwabenantim committed Sep 23, 2024
1 parent c8adb4e commit 5fec6f7
Show file tree
Hide file tree
Showing 37 changed files with 269 additions and 269 deletions.
8 changes: 4 additions & 4 deletions cppwg/input/class_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CppClassInfo(CppTypeInfo):
cpp_names : List[str]
The C++ names of the class e.g. ["Foo<2,2>", "Foo<3,3>"]
py_names : List[str]
The Python names of the class e.g. ["Foo2_2", "Foo3_3"]
The Python names of the class e.g. ["Foo_2_2", "Foo_3_3"]
decls : pygccxml.declarations.declaration_t
Declarations for this type's base class, one per template instantiation
"""
Expand Down Expand Up @@ -252,7 +252,7 @@ def update_py_names(self) -> None:
special characters. The return type is a list, as a class can have
multiple names if it is templated. For example, a class "Foo" with
template arguments [[2, 2], [3, 3]] will have a python name list
["Foo2_2", "Foo3_3"].
["Foo_2_2", "Foo_3_3"].
"""
# Handles untemplated classes
if self.template_arg_lists is None:
Expand Down Expand Up @@ -308,7 +308,7 @@ def update_py_names(self) -> None:
if idx < len(template_arg_list) - 1:
template_string += "_"

self.py_names.append(type_name + template_string)
self.py_names.append(type_name + "_" + template_string)

def update_cpp_names(self) -> None:
"""
Expand All @@ -318,7 +318,7 @@ def update_cpp_names(self) -> None:
The return type is a list, as a class can have multiple names
if it is templated. For example, a class "Foo" with
template arguments [[2, 2], [3, 3]] will have a C++ name list
["Foo<2,2 >", "Foo<3,3 >"].
["Foo<2, 2>", "Foo<3, 3>"].
"""
# Handles untemplated classes
if self.template_arg_lists is None:
Expand Down
8 changes: 4 additions & 4 deletions cppwg/writers/class_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def add_hpp(self, class_py_name: str) -> None:
Parameters
----------
class_py_name: str
The Python name of the class e.g. Foo2_2
The Python name of the class e.g. Foo_2_2
"""
# Add the top prefix text
self.hpp_string += self.class_info.module_info.package_info.prefix_text + "\n"
Expand All @@ -88,7 +88,7 @@ def add_cpp_header(self, class_cpp_name: str, class_py_name: str) -> None:
class_cpp_name : str
The C++ name of the class e.g. Foo<2,2>
class_py_name : str
The Python name of the class e.g. Foo2_2
The Python name of the class e.g. Foo_2_2
"""
# Add the top prefix text
self.cpp_string += self.class_info.module_info.package_info.prefix_text + "\n"
Expand Down Expand Up @@ -214,7 +214,7 @@ def add_virtual_overrides(
# void bar(double d) const override {
# PYBIND11_OVERRIDE_PURE(
# bar,
# Foo2_2,
# Foo_2_2,
# bar,
# d);
# }
Expand Down Expand Up @@ -378,7 +378,7 @@ def write_files(self, work_dir: str, class_py_name: str) -> None:
work_dir : str
The directory to write the files to
class_py_name : str
The Python name of the class e.g. Foo2_2
The Python name of the class e.g. Foo_2_2
"""
hpp_filepath = os.path.join(work_dir, f"{class_py_name}.{CPPWG_EXT}.hpp")
cpp_filepath = os.path.join(work_dir, f"{class_py_name}.{CPPWG_EXT}.cpp")
Expand Down
2 changes: 1 addition & 1 deletion cppwg/writers/constructor_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CppConstructorWrapperWriter(CppBaseWrapperWriter):
wrapper_templates : Dict[str, str]
String templates with placeholders for generating wrapper code
class_py_name : Optional[str]
The Python name of the class e.g. 'Foo2_2'
The Python name of the class e.g. 'Foo_2_2'
template_params: Optional[List[str]]
The template params for the class e.g. ['DIM_A', 'DIM_B']
template_args: Optional[List[str]]
Expand Down
6 changes: 3 additions & 3 deletions cppwg/writers/header_collection_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CppHeaderCollectionWriter:
The header collection file includes all the headers to be parsed by CastXML.
It also contains explicit template instantiations and their corresponding
typedefs (e.g. typedef Foo<2,2> Foo2_2) for all classes that are to be
typedefs (e.g. typedef Foo<2,2> Foo_2_2) for all classes that are to be
automatically wrapped.
Attributes
Expand Down Expand Up @@ -126,7 +126,7 @@ def write(self) -> None:
included_files.add(hpp_filename)

# Add the template instantiations e.g. `template class Foo<2,2>;`
# and typdefs e.g. `typedef Foo<2,2> Foo2_2;`
# and typdefs e.g. `typedef Foo<2,2> Foo_2_2;`
template_instantiations = ""
template_typedefs = ""

Expand All @@ -143,7 +143,7 @@ def write(self) -> None:
# C++ class names eg. ["Foo<2,2>", "Foo<3,3>"]
cpp_names = [name.replace(" ", "") for name in class_info.cpp_names]

# Python class names eg. ["Foo2_2", "Foo3_3"]
# Python class names eg. ["Foo_2_2", "Foo_3_3"]
py_names = [name.replace(" ", "") for name in class_info.py_names]

for cpp_name, py_name in zip(cpp_names, py_names):
Expand Down
6 changes: 3 additions & 3 deletions cppwg/writers/method_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class CppMethodWrapperWriter(CppBaseWrapperWriter):
wrapper_templates : Dict[str, str]
String templates with placeholders for generating wrapper code
class_py_name : Optional[str]
The Python name of the class e.g. 'Foo2_2'
The Python name of the class e.g. 'Foo_2_2'
template_params: Optional[List[str]]
The template params for the class e.g. ['DIM_A', 'DIM_B']
template_args: Optional[List[str]]
Expand Down Expand Up @@ -135,7 +135,7 @@ def generate_wrapper(self) -> str:
if self.method_decl.has_static:
self_ptr = "*"
else:
# e.g. Foo2_2::*
# e.g. Foo_2_2::*
self_ptr = self.class_py_name + "::*"

# Const-ness
Expand Down Expand Up @@ -214,7 +214,7 @@ def generate_virtual_override_wrapper(self) -> str:
void bar(double d) const override {
PYBIND11_OVERRIDE_PURE(
bar,
Foo2_2,
Foo_2_2,
bar,
d);
}
Expand Down
4 changes: 2 additions & 2 deletions cppwg/writers/module_writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def write_module_wrapper(self) -> None:
continue

for py_name in class_info.py_names:
# Example: #include "Foo2_2.cppwg.hpp"
# Example: #include "Foo_2_2.cppwg.hpp"
cpp_string += f'#include "{py_name}.{CPPWG_EXT}.hpp"\n'

# Format module name as _packagename_modulename
Expand All @@ -118,7 +118,7 @@ def write_module_wrapper(self) -> None:
continue

for py_name in class_info.py_names:
# Example: register_Foo2_2_class(m);"
# Example: register_Foo_2_2_class(m);"
cpp_string += f" register_{py_name}_class(m);\n"

# Add code from the module's custom generator
Expand Down
12 changes: 6 additions & 6 deletions examples/shapes/src/python/test/test_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,21 @@ class TestClasses(unittest.TestCase):

def testGeometry(self):

p0 = pyshapes.geometry.Point2()
p0 = pyshapes.geometry.Point_2()
self.assertTrue(p0.GetLocation() == [0.0, 0.0])

p1 = pyshapes.geometry.Point2(5.0, 0.0)
p1 = pyshapes.geometry.Point_2(5.0, 0.0)
self.assertTrue(p1.GetLocation() == [5.0, 0.0])

p2 = pyshapes.geometry.Point2(5.0, 5.0)
p2 = pyshapes.geometry.Point_2(5.0, 5.0)
self.assertTrue(p2.GetLocation() == [5.0, 5.0])

p3 = pyshapes.geometry.Point2(0.0, 5.0)
p3 = pyshapes.geometry.Point_2(0.0, 5.0)
self.assertTrue(p3.GetLocation() == [0.0, 5.0])

points = [p1, p2, p3]

triangle = pyshapes.primitives.Shape2()
triangle = pyshapes.primitives.Shape_2()
triangle.SetVertices(points)
self.assertTrue(len(triangle.rGetVertices()) == 3)

Expand All @@ -38,7 +38,7 @@ def testGeometry(self):

def testMesh(self):

cmesh = pyshapes.mesh.ConcreteMesh2()
cmesh = pyshapes.mesh.ConcreteMesh_2()
self.assertTrue(cmesh.GetIndex() == 0)

cmesh.SetIndex(1)
Expand Down
10 changes: 0 additions & 10 deletions examples/shapes/wrapper/geometry/Point2.cppwg.hpp

This file was deleted.

10 changes: 0 additions & 10 deletions examples/shapes/wrapper/geometry/Point3.cppwg.hpp

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
#include <pybind11/stl.h>
#include "wrapper_header_collection.hpp"

#include "Point2.cppwg.hpp"
#include "Point_2.cppwg.hpp"

namespace py = pybind11;
typedef Point<2> Point2;
typedef Point<2> Point_2;
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);

void register_Point2_class(py::module &m)
void register_Point_2_class(py::module &m)
{
py::class_<Point2, std::shared_ptr<Point2>>(m, "Point2")
py::class_<Point_2, std::shared_ptr<Point_2>>(m, "Point_2")
.def(py::init<>())
.def(py::init<double, double, double>(), py::arg("x"), py::arg("y"), py::arg("z") = (2 - 2))
.def("GetLocation",
(::std::array<double, 2>(Point2::*)() const) &Point2::GetLocation,
(::std::array<double, 2>(Point_2::*)() const) &Point_2::GetLocation,
" ")
.def("rGetLocation",
(::std::array<double, 2> const &(Point2::*)() const) &Point2::rGetLocation,
(::std::array<double, 2> const &(Point_2::*)() const) &Point_2::rGetLocation,
" ", py::return_value_policy::reference_internal)
.def("GetIndex",
(unsigned int(Point2::*)() const) &Point2::GetIndex,
(unsigned int(Point_2::*)() const) &Point_2::GetIndex,
" ")
.def("SetIndex",
(void(Point2::*)(unsigned int)) &Point2::SetIndex,
(void(Point_2::*)(unsigned int)) &Point_2::SetIndex,
" ", py::arg("index"))
.def("SetLocation",
(void(Point2::*)(::std::array<double, 2> const &)) &Point2::SetLocation,
(void(Point_2::*)(::std::array<double, 2> const &)) &Point_2::SetLocation,
" ", py::arg("rLocation"))
;
}
10 changes: 10 additions & 0 deletions examples/shapes/wrapper/geometry/Point_2.cppwg.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is automatically generated by cppwg.
// Do not modify this file directly.

#ifndef Point_2_hpp__cppwg_wrapper
#define Point_2_hpp__cppwg_wrapper

#include <pybind11/pybind11.h>

void register_Point_2_class(pybind11::module &m);
#endif // Point_2_hpp__cppwg_wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -5,31 +5,31 @@
#include <pybind11/stl.h>
#include "wrapper_header_collection.hpp"

#include "Point3.cppwg.hpp"
#include "Point_3.cppwg.hpp"

namespace py = pybind11;
typedef Point<3> Point3;
typedef Point<3> Point_3;
PYBIND11_DECLARE_HOLDER_TYPE(T, std::shared_ptr<T>);

void register_Point3_class(py::module &m)
void register_Point_3_class(py::module &m)
{
py::class_<Point3, std::shared_ptr<Point3>>(m, "Point3")
py::class_<Point_3, std::shared_ptr<Point_3>>(m, "Point_3")
.def(py::init<>())
.def(py::init<double, double, double>(), py::arg("x"), py::arg("y"), py::arg("z") = (3 - 3))
.def("GetLocation",
(::std::array<double, 3>(Point3::*)() const) &Point3::GetLocation,
(::std::array<double, 3>(Point_3::*)() const) &Point_3::GetLocation,
" ")
.def("rGetLocation",
(::std::array<double, 3> const &(Point3::*)() const) &Point3::rGetLocation,
(::std::array<double, 3> const &(Point_3::*)() const) &Point_3::rGetLocation,
" ", py::return_value_policy::reference_internal)
.def("GetIndex",
(unsigned int(Point3::*)() const) &Point3::GetIndex,
(unsigned int(Point_3::*)() const) &Point_3::GetIndex,
" ")
.def("SetIndex",
(void(Point3::*)(unsigned int)) &Point3::SetIndex,
(void(Point_3::*)(unsigned int)) &Point_3::SetIndex,
" ", py::arg("index"))
.def("SetLocation",
(void(Point3::*)(::std::array<double, 3> const &)) &Point3::SetLocation,
(void(Point_3::*)(::std::array<double, 3> const &)) &Point_3::SetLocation,
" ", py::arg("rLocation"))
;
}
10 changes: 10 additions & 0 deletions examples/shapes/wrapper/geometry/Point_3.cppwg.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// This file is automatically generated by cppwg.
// Do not modify this file directly.

#ifndef Point_3_hpp__cppwg_wrapper
#define Point_3_hpp__cppwg_wrapper

#include <pybind11/pybind11.h>

void register_Point_3_class(pybind11::module &m);
#endif // Point_3_hpp__cppwg_wrapper
8 changes: 4 additions & 4 deletions examples/shapes/wrapper/geometry/geometry.main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

#include <pybind11/pybind11.h>
#include "wrapper_header_collection.hpp"
#include "Point2.cppwg.hpp"
#include "Point3.cppwg.hpp"
#include "Point_2.cppwg.hpp"
#include "Point_3.cppwg.hpp"

namespace py = pybind11;

PYBIND11_MODULE(_pyshapes_geometry, m)
{
register_Point2_class(m);
register_Point3_class(m);
register_Point_2_class(m);
register_Point_3_class(m);
}
45 changes: 0 additions & 45 deletions examples/shapes/wrapper/mesh/AbstractMesh2_2.cppwg.cpp

This file was deleted.

10 changes: 0 additions & 10 deletions examples/shapes/wrapper/mesh/AbstractMesh2_2.cppwg.hpp

This file was deleted.

Loading

0 comments on commit 5fec6f7

Please sign in to comment.