Remove AutoRegister util template
This commit is contained in:
parent
b494b873b1
commit
abfc016321
|
@ -217,9 +217,15 @@ InsertCompletion complete_line(const Buffer& buffer, ByteCoord cursor_pos)
|
||||||
}
|
}
|
||||||
|
|
||||||
InsertCompleter::InsertCompleter(const Context& context)
|
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)
|
void InsertCompleter::select(int offset)
|
||||||
{
|
{
|
||||||
|
@ -315,19 +321,19 @@ bool InsertCompleter::setup_ifn()
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
if (not m_completions.is_valid())
|
if (not m_completions.is_valid())
|
||||||
{
|
{
|
||||||
auto& completers = options()["completers"].get<InsertCompleterDescList>();
|
auto& completers = m_context.options()["completers"].get<InsertCompleterDescList>();
|
||||||
for (auto& completer : completers)
|
for (auto& completer : completers)
|
||||||
{
|
{
|
||||||
if (completer.mode == InsertCompleterDesc::Filename and
|
if (completer.mode == InsertCompleterDesc::Filename and
|
||||||
try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) {
|
try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) {
|
||||||
return complete_filename<true>(buffer, cursor_pos,
|
return complete_filename<true>(buffer, cursor_pos,
|
||||||
options());
|
m_context.options());
|
||||||
}))
|
}))
|
||||||
return true;
|
return true;
|
||||||
if (completer.mode == InsertCompleterDesc::Option and
|
if (completer.mode == InsertCompleterDesc::Option and
|
||||||
try_complete([&,this](const Buffer& buffer, ByteCoord cursor_pos) {
|
try_complete([&,this](const Buffer& buffer, ByteCoord cursor_pos) {
|
||||||
return complete_option(buffer, cursor_pos,
|
return complete_option(buffer, cursor_pos,
|
||||||
options(), *completer.param);
|
m_context.options(), *completer.param);
|
||||||
}))
|
}))
|
||||||
return true;
|
return true;
|
||||||
if (completer.mode == InsertCompleterDesc::Word and
|
if (completer.mode == InsertCompleterDesc::Word and
|
||||||
|
@ -368,7 +374,7 @@ void InsertCompleter::menu_show()
|
||||||
|
|
||||||
void InsertCompleter::on_option_changed(const Option& opt)
|
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;
|
std::vector<StringView> option_names;
|
||||||
for (auto& completer : completers)
|
for (auto& completer : completers)
|
||||||
{
|
{
|
||||||
|
@ -410,7 +416,7 @@ bool InsertCompleter::try_complete(CompleteFunc complete_func)
|
||||||
void InsertCompleter::explicit_file_complete()
|
void InsertCompleter::explicit_file_complete()
|
||||||
{
|
{
|
||||||
try_complete([this](const Buffer& buffer, ByteCoord cursor_pos) {
|
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());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,12 +49,13 @@ struct InsertCompletion
|
||||||
bool is_valid() const { return not candidates.empty(); }
|
bool is_valid() const { return not candidates.empty(); }
|
||||||
};
|
};
|
||||||
|
|
||||||
class InsertCompleter : public OptionManagerWatcher_AutoRegister
|
class InsertCompleter : public OptionManagerWatcher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InsertCompleter(const Context& context);
|
InsertCompleter(const Context& context);
|
||||||
InsertCompleter(const InsertCompleter&) = delete;
|
InsertCompleter(const InsertCompleter&) = delete;
|
||||||
InsertCompleter& operator=(const InsertCompleter&) = delete;
|
InsertCompleter& operator=(const InsertCompleter&) = delete;
|
||||||
|
~InsertCompleter();
|
||||||
|
|
||||||
void select(int offset);
|
void select(int offset);
|
||||||
void update();
|
void update();
|
||||||
|
|
|
@ -221,31 +221,6 @@ private:
|
||||||
std::vector<std::unique_ptr<OptionDesc>> m_descs;
|
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
|
#endif // option_manager_hh_INCLUDED
|
||||||
|
|
57
src/utils.hh
57
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;
|
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(®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<EffectiveType&>(*this); }
|
|
||||||
Registry* m_registry;
|
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// std::pair hashing
|
// std::pair hashing
|
||||||
|
|
Loading…
Reference in New Issue
Block a user