home/src/filter_registry.cc
Maxime Coste 0ce6bd9bf5 use ByteCount instead of CharCount when we are really counting bytes
(that is most of the time when we are not concerned with displaying)
2012-10-11 00:41:48 +02:00

40 lines
1.0 KiB
C++

#include "filter_registry.hh"
#include "exception.hh"
#include "filter_group.hh"
namespace Kakoune
{
struct factory_not_found : public runtime_error
{
factory_not_found(const String& name)
: runtime_error("filter factory not found '" + name + "'") {}
};
void FilterRegistry::register_factory(const String& name,
const FilterFactory& factory)
{
assert(not m_factories.contains(name));
m_factories.append(std::make_pair(name, factory));
}
void FilterRegistry::add_filter_to_group(FilterGroup& group,
const String& name,
const FilterParameters& parameters)
{
auto it = m_factories.find(name);
if (it == m_factories.end())
throw factory_not_found(name);
group.append(it->second(parameters));
}
CandidateList FilterRegistry::complete_filter(const String& prefix,
ByteCount cursor_pos)
{
return m_factories.complete_id(prefix, cursor_pos);
}
}