home/src/face_registry.hh
Maxime Coste ebecd60eb8 Rework hashing, use a more extensible framework similar to n3876 proposal
std::hash specialization is a pain to work with, stop using that, and
just specialize a 'size_t hash_value(const T&)' free function.
2014-12-16 18:57:19 +00:00

46 lines
947 B
C++

#ifndef face_registry_hh_INCLUDED
#define face_registry_hh_INCLUDED
#include "face.hh"
#include "utils.hh"
#include "completion.hh"
#include "unordered_map.hh"
namespace Kakoune
{
class FaceRegistry : public Singleton<FaceRegistry>
{
public:
FaceRegistry();
Face operator[](const String& facedesc);
void register_alias(const String& name, const String& facedesc,
bool override = false);
CandidateList complete_alias_name(StringView prefix,
ByteCount cursor_pos) const;
private:
struct FaceOrAlias
{
Face face;
String alias;
FaceOrAlias(Face face = Face{}) : face(face) {}
};
UnorderedMap<String, FaceOrAlias> m_aliases;
};
inline Face get_face(const String& facedesc)
{
if (FaceRegistry::has_instance())
return FaceRegistry::instance()[facedesc];
return Face{};
}
}
#endif // face_registry_hh_INCLUDED