Skip to content

Commit

Permalink
more macro work
Browse files Browse the repository at this point in the history
  • Loading branch information
jll63 committed Sep 23, 2024
1 parent 2f32acb commit b5b1a31
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 21 deletions.
5 changes: 2 additions & 3 deletions examples/containers/arc_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ register_classes(geometries::Arc, geometries::Line);
namespace painter {
namespace paint1d {

define_method_in(
painters, paintObject, (Painter & painter, const geometries::Arc& arc),
void) {
define_method(
paintObject, (Painter & painter, const geometries::Arc& arc), void) {
++painter.counter;
next(painter, arc);
std::cout << " " << "painting arc\n";
Expand Down
2 changes: 1 addition & 1 deletion examples/containers/line_painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace painter {
namespace paint1d {

define_method_inline(
painters, paintObject, (Painter & painter, const geometries::Line& arc),
paintObject, (Painter & painter, const geometries::Line& arc),
void) {
std::cout << "#" << painter.counter;
}
Expand Down
23 changes: 14 additions & 9 deletions examples/containers/painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,29 +15,34 @@

namespace painter {

namespace paint1d {
template<typename...> struct painters;
}
namespace paint2d {
template<typename...> struct painters;
}

class Painter;

// Implements paint
declare_method(
paintObject,
(Painter&, yorel::yomm2::virtual_<const geometries::Geometry&>), void);

namespace paint1d {
template<typename...>
struct YOMM2_OVERRIDERS(paintObject);
}

namespace paint2d {
template<typename...>
struct YOMM2_OVERRIDERS(paintObject);
}

class Painter {
public:
void paint(const geometries::Geometry& geometry);
int painted() const;

private:
int counter = 0;
template<typename...> friend struct paint1d::painters;
friend paint2d::painters<void(Painter&, const geometries::Shape&)>;
template<typename...>
friend struct paint1d::YOMM2_OVERRIDERS(paintObject);
friend struct paint2d::YOMM2_OVERRIDERS(
paintObject)<void(Painter&, const geometries::Shape&)>;
};

inline void Painter::paint(const geometries::Geometry& geometry) {
Expand Down
9 changes: 5 additions & 4 deletions examples/containers/segment_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ register_classes(geometries::Segment, geometries::Line);
namespace painter {
namespace paint1d {

define_method_in(
painters, paintObject,
(Painter & painter, const geometries::Segment& segment), void) {
define_method(
paintObject, (Painter & painter, const geometries::Segment& segment),
void) {
++painter.counter;
painters<void(Painter&, const geometries::Line&)>::fn(painter, segment);
YOMM2_OVERRIDERS(paintObject)<void(Painter&, const geometries::Line&)>::fn(
painter, segment);
std::cout << " " << "painting segment\n";
}

Expand Down
4 changes: 2 additions & 2 deletions examples/containers/shape_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ register_classes(geometries::Shape, geometries::Geometry);
namespace painter {
namespace paint2d {

define_method_in(
painters, paintObject, (Painter & painter, const geometries::Shape& shape),
define_method(
paintObject, (Painter & painter, const geometries::Shape& shape),
void) {
++painter.counter;
static int counter;
Expand Down
4 changes: 2 additions & 2 deletions include/yorel/yomm2/macros.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ struct method_macro_aux<Name(Parameters...), Return, noexcept_, More...> {
YOREL_YOMM2_DETAIL_DEFINE( \
, OVERRIDERS, YOMM2_METHOD_NAME(NAME), ARGS, __VA_ARGS__)

#define YOMM2_OVERRIDE_INLINE(OVERRIDERS, NAME, ARGS, ...) \
#define YOMM2_OVERRIDE_INLINE(NAME, ARGS, ...) \
YOREL_YOMM2_DETAIL_DEFINE( \
inline, OVERRIDERS, YOMM2_METHOD_NAME(NAME), ARGS, __VA_ARGS__)
inline, YOMM2_OVERRIDERS(NAME), YOMM2_METHOD_NAME(NAME), ARGS, __VA_ARGS__)

#define YOMM2_OVERRIDE(NAME, ARGS, ...) \
YOREL_YOMM2_DETAIL_DEFINE( \
Expand Down

0 comments on commit b5b1a31

Please sign in to comment.