Add support for per type default memory domain

This commit is contained in:
Maxime Coste 2015-01-16 13:58:21 +00:00
parent c79cd59314
commit 32319aca45
4 changed files with 17 additions and 2 deletions

View File

@ -30,6 +30,7 @@ enum class MemoryDomain
Registers, Registers,
Client, Client,
WordDB, WordDB,
Selections,
Count Count
}; };
@ -54,6 +55,7 @@ inline const char* domain_name(MemoryDomain domain)
case MemoryDomain::Values: return "Values"; case MemoryDomain::Values: return "Values";
case MemoryDomain::Registers: return "Registers"; case MemoryDomain::Registers: return "Registers";
case MemoryDomain::Client: return "Client"; case MemoryDomain::Client: return "Client";
case MemoryDomain::Selections: return "Selections";
case MemoryDomain::Count: break; case MemoryDomain::Count: break;
} }
kak_assert(false); kak_assert(false);
@ -118,6 +120,15 @@ bool operator!=(const Allocator<T1, d1>& lhs, const Allocator<T2, d2>& rhs)
return d1 != d2; 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 #endif // memory_hh_INCLUDED

View File

@ -11,6 +11,8 @@ using CaptureList = Vector<String>;
// A selection is a Selection, associated with a CaptureList // A selection is a Selection, associated with a CaptureList
struct Selection struct Selection
{ {
static constexpr MemoryDomain Domain = MemoryDomain::Selections;
Selection() = default; Selection() = default;
Selection(ByteCoord pos) : Selection(pos,pos) {} Selection(ByteCoord pos) : Selection(pos,pos) {}
Selection(ByteCoord anchor, ByteCoord cursor, Selection(ByteCoord anchor, ByteCoord cursor,
@ -68,6 +70,8 @@ enum class InsertMode : unsigned
struct SelectionList struct SelectionList
{ {
static constexpr MemoryDomain Domain = MemoryDomain::Selections;
SelectionList(Buffer& buffer, Selection s); SelectionList(Buffer& buffer, Selection s);
SelectionList(Buffer& buffer, Selection s, size_t timestamp); SelectionList(Buffer& buffer, Selection s, size_t timestamp);
SelectionList(Buffer& buffer, Vector<Selection> s); SelectionList(Buffer& buffer, Vector<Selection> s);

View File

@ -9,7 +9,7 @@
namespace Kakoune 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>, using UnorderedMap = std::unordered_map<Key, Value, Hash<Key>, std::equal_to<Key>,
Allocator<std::pair<const Key, Value>, domain>>; Allocator<std::pair<const Key, Value>, domain>>;

View File

@ -8,7 +8,7 @@
namespace Kakoune 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>>; using Vector = std::vector<T, Allocator<T, domain>>;
} }