summaryrefslogtreecommitdiff
path: root/src/option_types.hh
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2013-05-06 13:52:20 +0200
committerMaxime Coste <frrrwww@gmail.com>2013-05-06 13:52:20 +0200
commitc1615b5c15d64b746ff7d4080da43a8d659576ca (patch)
tree29a81c565c8474c0975ff9509013a35bb453c506 /src/option_types.hh
parent2342e7686fb9de142b0f331852bb5294c55c6440 (diff)
add unordered_set option support, use it for completers
Diffstat (limited to 'src/option_types.hh')
-rw-r--r--src/option_types.hh37
1 files changed, 36 insertions, 1 deletions
diff --git a/src/option_types.hh b/src/option_types.hh
index e44b3f0d..121b8f56 100644
--- a/src/option_types.hh
+++ b/src/option_types.hh
@@ -7,6 +7,7 @@
#include <tuple>
#include <vector>
+#include <unordered_set>
namespace Kakoune
{
@@ -64,6 +65,39 @@ bool option_add(std::vector<T>& opt, const std::vector<T>& vec)
return not vec.empty();
}
+template<typename T>
+String option_to_string(const std::unordered_set<T>& opt)
+{
+ String res;
+ for (auto it = begin(opt); it != end(opt); ++it)
+ {
+ if (it != begin(opt))
+ res += list_separator;
+ res += option_to_string(*it);
+ }
+ return res;
+}
+
+template<typename T>
+void option_from_string(const String& str, std::unordered_set<T>& opt)
+{
+ opt.clear();
+ std::vector<String> elems = split(str, list_separator);
+ for (auto& elem: elems)
+ {
+ T opt_elem;
+ option_from_string(elem, opt_elem);
+ opt.insert(opt_elem);
+ }
+}
+
+template<typename T>
+bool option_add(std::unordered_set<T>& opt, const std::unordered_set<T>& set)
+{
+ std::copy(set.begin(), set.end(), std::inserter(opt, opt.begin()));
+ return not set.empty();
+}
+
constexpr Codepoint tuple_separator = '|';
template<size_t I, typename... Types>
@@ -124,7 +158,8 @@ template<typename RealType, typename ValueType = int>
inline bool option_add(StronglyTypedNumber<RealType, ValueType>& opt,
StronglyTypedNumber<RealType, ValueType> val)
{
- opt += val; return val != 0;
+ opt += val;
+ return val != 0;
}
template<typename T>