From 9a6712e56b95a9acbae40a6d3e9e1f1e2f3e6f19 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Mon, 18 Nov 2013 22:24:31 +0000 Subject: rename idvaluemap to id_map, remove Id template param, use String --- src/function_group.hh | 4 +- src/function_registry.hh | 4 +- src/hook_manager.hh | 4 +- src/id_map.hh | 105 +++++++++++++++++++++++++++++++++++++++++++++++ src/idvaluemap.hh | 105 ----------------------------------------------- src/keymap_manager.hh | 1 - 6 files changed, 111 insertions(+), 112 deletions(-) create mode 100644 src/id_map.hh delete mode 100644 src/idvaluemap.hh (limited to 'src') diff --git a/src/function_group.hh b/src/function_group.hh index 739b7ffb..491debf9 100644 --- a/src/function_group.hh +++ b/src/function_group.hh @@ -2,7 +2,7 @@ #define function_group_hh_INCLUDED #include "exception.hh" -#include "idvaluemap.hh" +#include "id_map.hh" #include "string.hh" namespace Kakoune @@ -58,7 +58,7 @@ public: } private: - idvaluemap m_functions; + id_map m_functions; }; } diff --git a/src/function_registry.hh b/src/function_registry.hh index 2197efcc..d62f9ae8 100644 --- a/src/function_registry.hh +++ b/src/function_registry.hh @@ -2,7 +2,7 @@ #define function_registry_h_INCLUDED #include "completion.hh" -#include "idvaluemap.hh" +#include "id_map.hh" #include "string.hh" namespace Kakoune @@ -38,7 +38,7 @@ public: } private: - idvaluemap m_functions; + id_map m_functions; }; } diff --git a/src/hook_manager.hh b/src/hook_manager.hh index ac2ce8f5..8b0d7e2d 100644 --- a/src/hook_manager.hh +++ b/src/hook_manager.hh @@ -1,7 +1,7 @@ #ifndef hook_manager_hh_INCLUDED #define hook_manager_hh_INCLUDED -#include "idvaluemap.hh" +#include "id_map.hh" #include "utils.hh" #include @@ -29,7 +29,7 @@ private: friend class GlobalHooks; HookManager* m_parent; - std::unordered_map> m_hook; + std::unordered_map> m_hook; }; class GlobalHooks : public HookManager, diff --git a/src/id_map.hh b/src/id_map.hh new file mode 100644 index 00000000..9c80d776 --- /dev/null +++ b/src/id_map.hh @@ -0,0 +1,105 @@ +#ifndef id_map_hh_INCLUDED +#define id_map_hh_INCLUDED + +#include "completion.hh" +#include "string.hh" + +#include + +namespace Kakoune +{ + +template +class id_map +{ +public: + typedef std::pair value_type; + typedef std::vector container_type; + typedef typename container_type::iterator iterator; + typedef typename container_type::const_iterator const_iterator; + + void append(const value_type& value) + { + m_content.push_back(value); + } + + void append(value_type&& value) + { + m_content.push_back(std::move(value)); + } + + iterator find(const String& id) + { + for (auto it = begin(); it != end(); ++it) + { + if (it->first == id) + return it; + } + return end(); + } + + const_iterator find(const String& id) const + { + for (auto it = begin(); it != end(); ++it) + { + if (it->first == id) + return it; + } + return end(); + } + + bool contains(const String& id) const + { + return find(id) != end(); + } + + void remove(const String& id) + { + auto it = find(id); + if (it != end()) + m_content.erase(it); + } + + void remove_all(const String& id) + { + for (auto it = find(id); it != end(); it = find(id)) + m_content.erase(it); + } + + template + CandidateList complete_id_if(const String& prefix, + ByteCount cursor_pos, + Condition condition) const + { + String real_prefix = prefix.substr(0, cursor_pos); + CandidateList result; + for (auto& value : m_content) + { + if (not condition(value)) + continue; + + if (prefix_match(value.first, real_prefix)) + result.push_back(value.first); + } + return result; + } + + CandidateList complete_id(const String& prefix, + ByteCount cursor_pos) const + { + return complete_id_if( + prefix, cursor_pos, [](const value_type&) { return true; }); + } + + iterator begin() { return m_content.begin(); } + iterator end() { return m_content.end(); } + const_iterator begin() const { return m_content.begin(); } + const_iterator end() const { return m_content.end(); } + +private: + container_type m_content; +}; + +} + +#endif // id_map_hh_INCLUDED diff --git a/src/idvaluemap.hh b/src/idvaluemap.hh deleted file mode 100644 index 9efbdd68..00000000 --- a/src/idvaluemap.hh +++ /dev/null @@ -1,105 +0,0 @@ -#ifndef idvaluemap_hh_INCLUDED -#define idvaluemap_hh_INCLUDED - -#include "completion.hh" - -#include - -namespace Kakoune -{ - -template -class idvaluemap -{ -public: - typedef std::pair value_type; - typedef std::vector container_type; - typedef typename container_type::iterator iterator; - typedef typename container_type::const_iterator const_iterator; - - void append(const value_type& value) - { - m_content.push_back(value); - } - - void append(value_type&& value) - { - m_content.push_back(std::move(value)); - } - - iterator find(const Id& id) - { - for (auto it = begin(); it != end(); ++it) - { - if (it->first == id) - return it; - } - return end(); - } - - const_iterator find(const Id& id) const - { - for (auto it = begin(); it != end(); ++it) - { - if (it->first == id) - return it; - } - return end(); - } - - bool contains(const Id& id) const - { - return find(id) != end(); - } - - void remove(const Id& id) - { - auto it = find(id); - if (it != end()) - m_content.erase(it); - } - - void remove_all(const Id& id) - { - for (auto it = find(id); it != end(); it = find(id)) - m_content.erase(it); - } - - template - CandidateList complete_id_if(const String& prefix, - ByteCount cursor_pos, - Condition condition) const - { - String real_prefix = prefix.substr(0, cursor_pos); - CandidateList result; - for (auto& value : m_content) - { - if (not condition(value)) - continue; - - String id_str = value.first; - if (prefix_match(id_str, real_prefix)) - result.push_back(std::move(id_str)); - } - return result; - } - - CandidateList complete_id(const String& prefix, - ByteCount cursor_pos) const - { - return complete_id_if( - prefix, cursor_pos, [](const value_type&) { return true; }); - } - - iterator begin() { return m_content.begin(); } - iterator end() { return m_content.end(); } - const_iterator begin() const { return m_content.begin(); } - const_iterator end() const { return m_content.end(); } - -private: - container_type m_content; -}; - -} - -#endif // idvaluemap_hh_INCLUDED diff --git a/src/keymap_manager.hh b/src/keymap_manager.hh index c9887a6b..caf4174a 100644 --- a/src/keymap_manager.hh +++ b/src/keymap_manager.hh @@ -1,7 +1,6 @@ #ifndef keymap_manager_hh_INCLUDED #define keymap_manager_hh_INCLUDED -#include "idvaluemap.hh" #include "keys.hh" #include "utils.hh" -- cgit v1.2.3