From d1216b5891dd8771d2db118523a111c02bffd83a Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Sat, 30 Mar 2024 00:21:41 +0100 Subject: [PATCH] WIP --- src/edt/edt/edtEditorHooks.cc | 2 + src/edt/edt/edtEditorHooks.h | 82 +++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) diff --git a/src/edt/edt/edtEditorHooks.cc b/src/edt/edt/edtEditorHooks.cc index f9bacc137..5641ddd20 100644 --- a/src/edt/edt/edtEditorHooks.cc +++ b/src/edt/edt/edtEditorHooks.cc @@ -31,6 +31,8 @@ namespace edt // --------------------------------------------------------------- // EditorHooksManager definition and implementation +class EditorHooksManager; + static EditorHooksManager *sp_instance = 0; static bool sp_instance_initialized = false; diff --git a/src/edt/edt/edtEditorHooks.h b/src/edt/edt/edtEditorHooks.h index a442dbf00..5a557a4b3 100644 --- a/src/edt/edt/edtEditorHooks.h +++ b/src/edt/edt/edtEditorHooks.h @@ -28,6 +28,7 @@ #include "edtCommon.h" #include "dbTrans.h" #include "gsiObject.h" +#include "tlExceptions.h" #include #include @@ -161,6 +162,87 @@ private: EditorHooks (const EditorHooks &); }; +/** + * @brief A helper function to call editor hooks in the right sequence and with error handling + */ + +inline +void call_editor_hooks (const std::vector &hooks, void (EditorHooks::*meth) ()) +{ + for (auto h = hooks.begin (); h != hooks.end (); ++h) { +BEGIN_PROTECTED + try { + ((*h)->*meth) (); + } catch (tl::CancelException &) { + return; + } +END_PROTECTED + } +} + +/** + * @brief A helper function to call editor hooks in the right sequence and with error handling + * + * This version provides one argument + */ + +template +inline +void call_editor_hooks (const std::vector &hooks, void (EditorHooks::*meth) (A1), A1 a1) +{ + for (auto h = hooks.begin (); h != hooks.end (); ++h) { +BEGIN_PROTECTED + try { + ((*h)->*meth) (a1); + } catch (tl::CancelException &) { + return; + } +END_PROTECTED + } +} + +/** + * @brief A helper function to call editor hooks in the right sequence and with error handling + * + * This version provides two arguments + */ + +template +inline +void call_editor_hooks (const std::vector &hooks, void (EditorHooks::*meth) (A1, A2), A1 a1, A2 a2) +{ + for (auto h = hooks.begin (); h != hooks.end (); ++h) { +BEGIN_PROTECTED + try { + ((*h)->*meth) (a1, a2); + } catch (tl::CancelException &) { + return; + } +END_PROTECTED + } +} + +/** + * @brief A helper function to call editor hooks in the right sequence and with error handling + * + * This version provides three arguments + */ + +template +inline +void call_editor_hooks (const std::vector &hooks, void (EditorHooks::*meth) (A1, A2), A1 a1, A2 a2, A3 a3) +{ + for (auto h = hooks.begin (); h != hooks.end (); ++h) { +BEGIN_PROTECTED + try { + ((*h)->*meth) (a1, a2, a3); + } catch (tl::CancelException &) { + return; + } +END_PROTECTED + } +} + } #endif