aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-05-28 18:27:30 -0400
committerDavid Robillard <d@drobilla.net>2021-05-28 18:27:30 -0400
commit6c7955c0961d907cd660ff55cde65a537904b7f5 (patch)
treebf3d6b0fd8360e805f68ff97985f6abbb51111d7
parentbaa57db5117e6ba847ae79cdbfeb6366143a37de (diff)
downloadpugl-6c7955c0961d907cd660ff55cde65a537904b7f5.tar.gz
pugl-6c7955c0961d907cd660ff55cde65a537904b7f5.tar.bz2
pugl-6c7955c0961d907cd660ff55cde65a537904b7f5.zip
Remove static downcasts in C++ bindings
-rw-r--r--bindings/cpp/include/.clang-tidy1
-rw-r--r--bindings/cpp/include/pugl/pugl.hpp58
-rw-r--r--examples/.clang-tidy3
-rw-r--r--test/.clang-tidy1
4 files changed, 29 insertions, 34 deletions
diff --git a/bindings/cpp/include/.clang-tidy b/bindings/cpp/include/.clang-tidy
index 1c986fe..15651d3 100644
--- a/bindings/cpp/include/.clang-tidy
+++ b/bindings/cpp/include/.clang-tidy
@@ -4,7 +4,6 @@ Checks: >
-clang-diagnostic-unused-macros,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
- -cppcoreguidelines-pro-type-static-cast-downcast,
-google-runtime-references,
-hicpp-named-parameter,
-llvmlibc-*,
diff --git a/bindings/cpp/include/pugl/pugl.hpp b/bindings/cpp/include/pugl/pugl.hpp
index 69ea0eb..85643ad 100644
--- a/bindings/cpp/include/pugl/pugl.hpp
+++ b/bindings/cpp/include/pugl/pugl.hpp
@@ -88,8 +88,7 @@ using Rect = PuglRect; ///< @copydoc PuglRect
/**
A strongly-typed analogue of PuglEvent.
- This is bit-for-bit identical to the corresponding PuglEvent, so events are
- simply cast to this type to avoid any copying overhead.
+ This is bit-for-bit identical to the corresponding PuglEvent.
@tparam t The `type` field of the corresponding PuglEvent.
@@ -103,6 +102,10 @@ struct Event final : Base {
/// The `type` field of the corresponding C event structure
static constexpr const PuglEventType type = t;
+ explicit Event(Base base)
+ : Base{base}
+ {}
+
template<class... Args>
explicit Event(const PuglEventFlags f, Args... args)
: Base{t, f, args...}
@@ -652,56 +655,51 @@ private:
case PUGL_NOTHING:
return Status::success;
case PUGL_CREATE:
- return target.onEvent(static_cast<const CreateEvent&>(event->any));
+ return target.onEvent(CreateEvent{event->any});
case PUGL_DESTROY:
- return target.onEvent(static_cast<const DestroyEvent&>(event->any));
+ return target.onEvent(DestroyEvent{event->any});
case PUGL_CONFIGURE:
- return target.onEvent(
- static_cast<const ConfigureEvent&>(event->configure));
+ return target.onEvent(ConfigureEvent{event->configure});
case PUGL_MAP:
- return target.onEvent(static_cast<const MapEvent&>(event->any));
+ return target.onEvent(MapEvent{event->any});
case PUGL_UNMAP:
- return target.onEvent(static_cast<const UnmapEvent&>(event->any));
+ return target.onEvent(UnmapEvent{event->any});
case PUGL_UPDATE:
- return target.onEvent(static_cast<const UpdateEvent&>(event->any));
+ return target.onEvent(UpdateEvent{event->any});
case PUGL_EXPOSE:
- return target.onEvent(static_cast<const ExposeEvent&>(event->expose));
+ return target.onEvent(ExposeEvent{event->expose});
case PUGL_CLOSE:
- return target.onEvent(static_cast<const CloseEvent&>(event->any));
+ return target.onEvent(CloseEvent{event->any});
case PUGL_FOCUS_IN:
- return target.onEvent(static_cast<const FocusInEvent&>(event->focus));
+ return target.onEvent(FocusInEvent{event->focus});
case PUGL_FOCUS_OUT:
- return target.onEvent(static_cast<const FocusOutEvent&>(event->focus));
+ return target.onEvent(FocusOutEvent{event->focus});
case PUGL_KEY_PRESS:
- return target.onEvent(static_cast<const KeyPressEvent&>(event->key));
+ return target.onEvent(KeyPressEvent{event->key});
case PUGL_KEY_RELEASE:
- return target.onEvent(static_cast<const KeyReleaseEvent&>(event->key));
+ return target.onEvent(KeyReleaseEvent{event->key});
case PUGL_TEXT:
- return target.onEvent(static_cast<const TextEvent&>(event->text));
+ return target.onEvent(TextEvent{event->text});
case PUGL_POINTER_IN:
- return target.onEvent(
- static_cast<const PointerInEvent&>(event->crossing));
+ return target.onEvent(PointerInEvent{event->crossing});
case PUGL_POINTER_OUT:
- return target.onEvent(
- static_cast<const PointerOutEvent&>(event->crossing));
+ return target.onEvent(PointerOutEvent{event->crossing});
case PUGL_BUTTON_PRESS:
- return target.onEvent(
- static_cast<const ButtonPressEvent&>(event->button));
+ return target.onEvent(ButtonPressEvent{event->button});
case PUGL_BUTTON_RELEASE:
- return target.onEvent(
- static_cast<const ButtonReleaseEvent&>(event->button));
+ return target.onEvent(ButtonReleaseEvent{event->button});
case PUGL_MOTION:
- return target.onEvent(static_cast<const MotionEvent&>(event->motion));
+ return target.onEvent(MotionEvent{event->motion});
case PUGL_SCROLL:
- return target.onEvent(static_cast<const ScrollEvent&>(event->scroll));
+ return target.onEvent(ScrollEvent{event->scroll});
case PUGL_CLIENT:
- return target.onEvent(static_cast<const ClientEvent&>(event->client));
+ return target.onEvent(ClientEvent{event->client});
case PUGL_TIMER:
- return target.onEvent(static_cast<const TimerEvent&>(event->timer));
+ return target.onEvent(TimerEvent{event->timer});
case PUGL_LOOP_ENTER:
- return target.onEvent(static_cast<const LoopEnterEvent&>(event->any));
+ return target.onEvent(LoopEnterEvent{event->any});
case PUGL_LOOP_LEAVE:
- return target.onEvent(static_cast<const LoopLeaveEvent&>(event->any));
+ return target.onEvent(LoopLeaveEvent{event->any});
}
return Status::failure;
diff --git a/examples/.clang-tidy b/examples/.clang-tidy
index fdfa4ea..e7e83a6 100644
--- a/examples/.clang-tidy
+++ b/examples/.clang-tidy
@@ -19,7 +19,6 @@ Checks: >
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-reinterpret-cast,
- -cppcoreguidelines-pro-type-static-cast-downcast,
-cppcoreguidelines-pro-type-vararg,
-fuchsia-default-arguments,
-fuchsia-default-arguments-calls,
@@ -37,4 +36,4 @@ Checks: >
-readability-implicit-bool-conversion,
-readability-named-parameter,
FormatStyle: file
-HeaderFilterRegex: 'pugl/.*|test/.*|examples/.*' \ No newline at end of file
+HeaderFilterRegex: 'pugl/.*|test/.*|examples/.*'
diff --git a/test/.clang-tidy b/test/.clang-tidy
index 8014e6a..30893c7 100644
--- a/test/.clang-tidy
+++ b/test/.clang-tidy
@@ -5,7 +5,6 @@ Checks: >
-bugprone-reserved-identifier,
-cert-dcl37-c,
-cert-dcl51-cpp,
- -cppcoreguidelines-pro-type-static-cast-downcast,
-google-runtime-references,
-hicpp-multiway-paths-covered,
-hicpp-signed-bitwise,