summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2014-11-02 16:04:24 +0000
committerMaxime Coste <frrrwww@gmail.com>2014-11-02 16:04:24 +0000
commitabfc016321a97d02915a3bd40ddfa46303e0b0df (patch)
treeba074be4d20aad1e628027210a0af7cf807c8cdf
parentb494b873b159fdf19a44e20cd61795fb7f1afaef (diff)
Remove AutoRegister util template
-rw-r--r--src/insert_completer.cc22
-rw-r--r--src/insert_completer.hh3
-rw-r--r--src/option_manager.hh25
-rw-r--r--src/utils.hh57
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<InsertCompleterDescList>();
+ auto& completers = m_context.options()["completers"].get<InsertCompleterDescList>();
for (auto& completer : completers)
{
if (completer.mode == InsertCompleterDesc::Filename and
try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) {
return complete_filename<true>(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<InsertCompleterDescList>();
+ auto& completers = m_context.options()["completers"].get<InsertCompleterDescList>();
std::vector<StringView> 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<false>(buffer, cursor_pos, options());
+ return complete_filename<false>(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<std::unique_ptr<OptionDesc>> 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<OptionManagerWatcher_AutoRegister,
- OptionManagerRegisterFuncs, OptionManager>
-{
-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<typename EffectiveType, typename RegisterFuncs, typename Registry>
-class AutoRegister
-{
-public:
- AutoRegister(Registry& registry)
- : m_registry(&registry)
- {
- 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<EffectiveType&>(*this); }
- Registry* m_registry;
-};
-
}
// std::pair hashing