2014-07-11 01:27:04 +02:00
|
|
|
#ifndef face_registry_hh_INCLUDED
|
|
|
|
#define face_registry_hh_INCLUDED
|
|
|
|
|
|
|
|
#include "face.hh"
|
|
|
|
#include "utils.hh"
|
2017-03-07 01:30:54 +01:00
|
|
|
#include "hash_map.hh"
|
2018-04-07 07:36:39 +02:00
|
|
|
#include "ranges.hh"
|
|
|
|
#include "string.hh"
|
|
|
|
#include "safe_ptr.hh"
|
2014-07-11 01:27:04 +02:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
2018-04-07 07:36:39 +02:00
|
|
|
class FaceRegistry : public SafeCountable
|
2014-07-11 01:27:04 +02:00
|
|
|
{
|
|
|
|
public:
|
2018-04-07 07:36:39 +02:00
|
|
|
FaceRegistry(FaceRegistry& parent) : SafeCountable{}, m_parent(&parent) {}
|
2014-07-11 01:27:04 +02:00
|
|
|
|
2018-04-07 07:36:39 +02:00
|
|
|
Face operator[](StringView facedesc) const;
|
|
|
|
void add_face(StringView name, StringView facedesc, bool override = false);
|
|
|
|
void remove_face(StringView name);
|
2014-07-11 01:27:04 +02:00
|
|
|
|
2018-04-07 07:36:39 +02:00
|
|
|
auto flatten_faces() const
|
|
|
|
{
|
|
|
|
auto merge = [](auto&& first, const FaceMap& second) {
|
|
|
|
return concatenated(std::forward<decltype(first)>(first)
|
|
|
|
| filter([&second](auto& i) { return not second.contains(i.key); }),
|
|
|
|
second);
|
|
|
|
};
|
|
|
|
static const FaceMap empty;
|
|
|
|
auto& parent = m_parent ? m_parent->m_faces : empty;
|
|
|
|
auto& grand_parent = (m_parent and m_parent->m_parent) ? m_parent->m_parent->m_faces : empty;
|
|
|
|
return merge(merge(grand_parent, parent), m_faces);
|
|
|
|
}
|
2017-09-09 15:55:35 +02:00
|
|
|
|
2014-08-20 00:10:56 +02:00
|
|
|
struct FaceOrAlias
|
|
|
|
{
|
2017-09-01 12:32:38 +02:00
|
|
|
Face face = {};
|
|
|
|
String alias = {};
|
2014-08-20 00:10:56 +02:00
|
|
|
};
|
2017-09-09 15:55:35 +02:00
|
|
|
|
|
|
|
private:
|
2018-04-07 07:36:39 +02:00
|
|
|
friend class Scope;
|
|
|
|
FaceRegistry();
|
2014-07-11 01:27:04 +02:00
|
|
|
|
2018-04-07 07:36:39 +02:00
|
|
|
SafePtr<FaceRegistry> m_parent;
|
|
|
|
|
|
|
|
using FaceMap = HashMap<String, FaceOrAlias, MemoryDomain::Faces>;
|
|
|
|
FaceMap m_faces;
|
|
|
|
};
|
2014-07-11 01:27:04 +02:00
|
|
|
|
2017-09-09 15:55:35 +02:00
|
|
|
String to_string(Face face);
|
|
|
|
|
2014-07-11 01:27:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif // face_registry_hh_INCLUDED
|