summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMaxime Coste <frrrwww@gmail.com>2015-01-16 13:58:21 +0000
committerMaxime Coste <frrrwww@gmail.com>2015-01-16 13:58:21 +0000
commit32319aca45265453baad756bf406e34a4568d169 (patch)
treea967f5b8e95abf9f50148e97495cc9d677307546
parentc79cd59314792c2d64ab069017c6cfb86270e075 (diff)
Add support for per type default memory domain
-rw-r--r--src/memory.hh11
-rw-r--r--src/selection.hh4
-rw-r--r--src/unordered_map.hh2
-rw-r--r--src/vector.hh2
4 files changed, 17 insertions, 2 deletions
diff --git a/src/memory.hh b/src/memory.hh
index 26b506a6..7aaff5fe 100644
--- a/src/memory.hh
+++ b/src/memory.hh
@@ -30,6 +30,7 @@ enum class MemoryDomain
Registers,
Client,
WordDB,
+ Selections,
Count
};
@@ -54,6 +55,7 @@ inline const char* domain_name(MemoryDomain domain)
case MemoryDomain::Values: return "Values";
case MemoryDomain::Registers: return "Registers";
case MemoryDomain::Client: return "Client";
+ case MemoryDomain::Selections: return "Selections";
case MemoryDomain::Count: break;
}
kak_assert(false);
@@ -118,6 +120,15 @@ bool operator!=(const Allocator<T1, d1>& lhs, const Allocator<T2, d2>& rhs)
return d1 != d2;
}
+template<typename T>
+struct TypeDomain
+{
+ static constexpr MemoryDomain domain = TypeDomain::helper((T*)nullptr);
+private:
+ template<typename U> static decltype(U::Domain) constexpr helper(U*) { return U::Domain; }
+ static constexpr MemoryDomain helper(...) { return MemoryDomain::Undefined; }
+};
+
}
#endif // memory_hh_INCLUDED
diff --git a/src/selection.hh b/src/selection.hh
index 8370df1f..cc435aed 100644
--- a/src/selection.hh
+++ b/src/selection.hh
@@ -11,6 +11,8 @@ using CaptureList = Vector<String>;
// A selection is a Selection, associated with a CaptureList
struct Selection
{
+ static constexpr MemoryDomain Domain = MemoryDomain::Selections;
+
Selection() = default;
Selection(ByteCoord pos) : Selection(pos,pos) {}
Selection(ByteCoord anchor, ByteCoord cursor,
@@ -68,6 +70,8 @@ enum class InsertMode : unsigned
struct SelectionList
{
+ static constexpr MemoryDomain Domain = MemoryDomain::Selections;
+
SelectionList(Buffer& buffer, Selection s);
SelectionList(Buffer& buffer, Selection s, size_t timestamp);
SelectionList(Buffer& buffer, Vector<Selection> s);
diff --git a/src/unordered_map.hh b/src/unordered_map.hh
index b114df69..2c54a0da 100644
--- a/src/unordered_map.hh
+++ b/src/unordered_map.hh
@@ -9,7 +9,7 @@
namespace Kakoune
{
-template<typename Key, typename Value, MemoryDomain domain = MemoryDomain::Undefined>
+template<typename Key, typename Value, MemoryDomain domain = TypeDomain<Key>::domain>
using UnorderedMap = std::unordered_map<Key, Value, Hash<Key>, std::equal_to<Key>,
Allocator<std::pair<const Key, Value>, domain>>;
diff --git a/src/vector.hh b/src/vector.hh
index 987b80f9..db137b24 100644
--- a/src/vector.hh
+++ b/src/vector.hh
@@ -8,7 +8,7 @@
namespace Kakoune
{
-template<typename T, MemoryDomain domain = MemoryDomain::Undefined>
+template<typename T, MemoryDomain domain = TypeDomain<T>::domain>
using Vector = std::vector<T, Allocator<T, domain>>;
}