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
|
|
|
|
2019-04-23 17:44:30 +02:00
|
|
|
struct FaceSpec
|
2018-04-10 12:35:23 +02:00
|
|
|
{
|
|
|
|
Face face = {};
|
2019-04-23 17:44:30 +02:00
|
|
|
String base = {};
|
2018-04-10 12:35:23 +02:00
|
|
|
};
|
2019-04-23 17:44:30 +02:00
|
|
|
using FaceMap = HashMap<String, FaceSpec, MemoryDomain::Faces>;
|
2018-04-10 12:35:23 +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
|
|
|
|
|
|
|
private:
|
2019-04-23 17:44:30 +02:00
|
|
|
Face resolve_spec(const FaceSpec& spec) const;
|
|
|
|
|
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;
|
|
|
|
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
|