diff options
| author | Maxime Coste <frrrwww@gmail.com> | 2014-06-10 19:58:02 +0100 |
|---|---|---|
| committer | Maxime Coste <frrrwww@gmail.com> | 2014-06-10 19:58:02 +0100 |
| commit | 479c31b571513b068aaa5881eec3624d3ac8cd1b (patch) | |
| tree | 1ad6038aeda8daa04db24e638984327f86a140ef /src/function_group.hh | |
| parent | 3791e74743c65f384893207d91f693a5c33343cd (diff) | |
Replace FunctionGroup template with HighlighterGroup class
Diffstat (limited to 'src/function_group.hh')
| -rw-r--r-- | src/function_group.hh | 76 |
1 files changed, 0 insertions, 76 deletions
diff --git a/src/function_group.hh b/src/function_group.hh deleted file mode 100644 index 025a8f92..00000000 --- a/src/function_group.hh +++ /dev/null @@ -1,76 +0,0 @@ -#ifndef function_group_hh_INCLUDED -#define function_group_hh_INCLUDED - -#include "exception.hh" -#include "id_map.hh" -#include "string.hh" - -namespace Kakoune -{ - -struct group_not_found : public runtime_error -{ - using runtime_error::runtime_error; -}; - -template<typename... Args> -class FunctionGroup -{ -public: - using Function = std::function<void (Args...)>; - using FunctionAndId = std::pair<String, std::function<void (Args...)>>; - - void operator()(Args... args) - { - for (auto& func : m_functions) - func.second(std::forward<Args>(args)...); - } - - void append(FunctionAndId&& function) - { - if (m_functions.contains(function.first)) - throw runtime_error("duplicate id: " + function.first); - - m_functions.append(std::forward<FunctionAndId>(function)); - } - void remove(StringView id) - { - m_functions.remove(id); - } - - FunctionGroup& get_group(StringView path, Codepoint path_separator = 0) - { - auto sep_it = std::find(path.begin(), path.end(), path_separator); - StringView id(path.begin(), sep_it); - auto it = m_functions.find(id); - if (it == m_functions.end()) - throw group_not_found("no such id: "_str + id); - FunctionGroup* group = it->second.template target<FunctionGroup>(); - if (not group) - throw group_not_found("not a group: "_str + id); - if (sep_it != path.end()) - return group->get_group(StringView(sep_it+1, path.end()), path_separator); - else - return *group; - } - - CandidateList complete_id(StringView prefix, ByteCount cursor_pos) const - { - return m_functions.complete_id(prefix, cursor_pos); - } - - CandidateList complete_group_id(StringView prefix, ByteCount cursor_pos) const - { - return m_functions.complete_id_if( - prefix, cursor_pos, [](const FunctionAndId& func) { - return func.second.template target<FunctionGroup>() != nullptr; - }); - } - -private: - id_map<Function> m_functions; -}; - -} - -#endif // function_group_hh_INCLUDED |
