#include "filter_registry.hh" #include "exception.hh" #include "buffer.hh" namespace Kakoune { struct factory_not_found : public runtime_error { factory_not_found() : runtime_error("filter factory not found") {} }; void FilterRegistry::register_factory(const std::string& name, const FilterFactory& factory) { assert(not m_factories.contains(name)); m_factories.append(std::make_pair(name, factory)); } void FilterRegistry::add_filter_to_buffer(Buffer& buffer, const std::string& name, const FilterParameters& parameters) { auto it = m_factories.find(name); if (it == m_factories.end()) throw factory_not_found(); buffer.add_filter(it->second(buffer, parameters)); } CandidateList FilterRegistry::complete_filter(const std::string& prefix, size_t cursor_pos) { return m_factories.complete_id(prefix, cursor_pos); } }