From abfc016321a97d02915a3bd40ddfa46303e0b0df Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 2 Nov 2014 16:04:24 +0000 Subject: [PATCH] Remove AutoRegister util template --- src/insert_completer.cc | 22 ++++++++++------ src/insert_completer.hh | 3 ++- src/option_manager.hh | 25 ------------------ src/utils.hh | 57 ----------------------------------------- 4 files changed, 16 insertions(+), 91 deletions(-) diff --git a/src/insert_completer.cc b/src/insert_completer.cc index a35578c6..43206008 100644 --- a/src/insert_completer.cc +++ b/src/insert_completer.cc @@ -217,9 +217,15 @@ InsertCompletion complete_line(const Buffer& buffer, ByteCoord cursor_pos) } InsertCompleter::InsertCompleter(const Context& context) - : OptionManagerWatcher_AutoRegister(context.options()), - m_context(context) -{} + : m_context(context) +{ + context.options().register_watcher(*this); +} + +InsertCompleter::~InsertCompleter() +{ + m_context.options().unregister_watcher(*this); +} void InsertCompleter::select(int offset) { @@ -315,19 +321,19 @@ bool InsertCompleter::setup_ifn() using namespace std::placeholders; if (not m_completions.is_valid()) { - auto& completers = options()["completers"].get(); + auto& completers = m_context.options()["completers"].get(); for (auto& completer : completers) { if (completer.mode == InsertCompleterDesc::Filename and try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) { return complete_filename(buffer, cursor_pos, - options()); + m_context.options()); })) return true; if (completer.mode == InsertCompleterDesc::Option and try_complete([&,this](const Buffer& buffer, ByteCoord cursor_pos) { return complete_option(buffer, cursor_pos, - options(), *completer.param); + m_context.options(), *completer.param); })) return true; if (completer.mode == InsertCompleterDesc::Word and @@ -368,7 +374,7 @@ void InsertCompleter::menu_show() void InsertCompleter::on_option_changed(const Option& opt) { - auto& completers = options()["completers"].get(); + auto& completers = m_context.options()["completers"].get(); std::vector option_names; for (auto& completer : completers) { @@ -410,7 +416,7 @@ bool InsertCompleter::try_complete(CompleteFunc complete_func) void InsertCompleter::explicit_file_complete() { try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) { - return complete_filename(buffer, cursor_pos, options()); + return complete_filename(buffer, cursor_pos, m_context.options()); }); } diff --git a/src/insert_completer.hh b/src/insert_completer.hh index 5d2d72ec..ed6d6d05 100644 --- a/src/insert_completer.hh +++ b/src/insert_completer.hh @@ -49,12 +49,13 @@ struct InsertCompletion bool is_valid() const { return not candidates.empty(); } }; -class InsertCompleter : public OptionManagerWatcher_AutoRegister +class InsertCompleter : public OptionManagerWatcher { public: InsertCompleter(const Context& context); InsertCompleter(const InsertCompleter&) = delete; InsertCompleter& operator=(const InsertCompleter&) = delete; + ~InsertCompleter(); void select(int offset); void update(); diff --git a/src/option_manager.hh b/src/option_manager.hh index 058c8ea6..387761fd 100644 --- a/src/option_manager.hh +++ b/src/option_manager.hh @@ -221,31 +221,6 @@ private: std::vector> m_descs; }; -struct OptionManagerRegisterFuncs -{ - static void insert(OptionManager& options, OptionManagerWatcher& watcher) - { - options.register_watcher(watcher); - } - static void remove(OptionManager& options, OptionManagerWatcher& watcher) - { - options.unregister_watcher(watcher); - } -}; - -class OptionManagerWatcher_AutoRegister - : public OptionManagerWatcher, - public AutoRegister -{ -public: - OptionManagerWatcher_AutoRegister(OptionManager& options) - : AutoRegister(options) {} - - OptionManager& options() { return registry(); } -}; - - } #endif // option_manager_hh_INCLUDED diff --git a/src/utils.hh b/src/utils.hh index 354c2fc3..9bb7c007 100644 --- a/src/utils.hh +++ b/src/utils.hh @@ -176,63 +176,6 @@ bool is_in_range(const T& val, const T& min, const T& max) return min <= val and val <= max; } -// *** AutoRegister: RAII handling of value semantics registering classes *** - -template -class AutoRegister -{ -public: - AutoRegister(Registry& registry) - : m_registry(®istry) - { - RegisterFuncs::insert(*m_registry, effective_this()); - } - - AutoRegister(const AutoRegister& other) - : m_registry(other.m_registry) - { - RegisterFuncs::insert(*m_registry, effective_this()); - } - - AutoRegister(AutoRegister&& other) - : m_registry(other.m_registry) - { - RegisterFuncs::insert(*m_registry, effective_this()); - } - - ~AutoRegister() - { - RegisterFuncs::remove(*m_registry, effective_this()); - } - - AutoRegister& operator=(const AutoRegister& other) - { - if (m_registry != other.m_registry) - { - RegisterFuncs::remove(*m_registry, effective_this()); - m_registry = other.m_registry; - RegisterFuncs::insert(*m_registry, effective_this()); - } - return *this; - } - - AutoRegister& operator=(AutoRegister&& other) - { - if (m_registry != other.m_registry) - { - RegisterFuncs::remove(*m_registry, effective_this()); - m_registry = other.m_registry; - RegisterFuncs::insert(*m_registry, effective_this()); - } - return *this; - } - Registry& registry() const { return *m_registry; } - -private: - EffectiveType& effective_this() { return static_cast(*this); } - Registry* m_registry; -}; - } // std::pair hashing