2011-12-02 15:28:27 +01:00
|
|
|
#include "filter_registry.hh"
|
|
|
|
|
|
|
|
#include "exception.hh"
|
2012-06-12 20:24:29 +02:00
|
|
|
#include "filter_group.hh"
|
2011-12-02 15:28:27 +01:00
|
|
|
|
|
|
|
namespace Kakoune
|
|
|
|
{
|
|
|
|
|
|
|
|
struct factory_not_found : public runtime_error
|
|
|
|
{
|
2012-04-14 03:17:09 +02:00
|
|
|
factory_not_found(const String& name)
|
2011-12-02 20:00:01 +01:00
|
|
|
: runtime_error("filter factory not found '" + name + "'") {}
|
2011-12-02 15:28:27 +01:00
|
|
|
};
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
void FilterRegistry::register_factory(const String& name,
|
2011-12-02 15:28:27 +01:00
|
|
|
const FilterFactory& factory)
|
|
|
|
{
|
|
|
|
assert(not m_factories.contains(name));
|
|
|
|
m_factories.append(std::make_pair(name, factory));
|
|
|
|
}
|
|
|
|
|
2012-06-12 20:24:29 +02:00
|
|
|
void FilterRegistry::add_filter_to_group(FilterGroup& group,
|
|
|
|
const String& name,
|
|
|
|
const FilterParameters& parameters)
|
2011-12-02 15:28:27 +01:00
|
|
|
{
|
|
|
|
auto it = m_factories.find(name);
|
|
|
|
if (it == m_factories.end())
|
2011-12-02 20:00:01 +01:00
|
|
|
throw factory_not_found(name);
|
2011-12-02 15:28:27 +01:00
|
|
|
|
2012-06-12 20:24:29 +02:00
|
|
|
group.append(it->second(parameters));
|
2011-12-02 15:28:27 +01:00
|
|
|
}
|
|
|
|
|
2012-04-14 03:17:09 +02:00
|
|
|
CandidateList FilterRegistry::complete_filter(const String& prefix,
|
2011-12-02 15:28:27 +01:00
|
|
|
size_t cursor_pos)
|
|
|
|
{
|
|
|
|
return m_factories.complete_id<str_to_str>(prefix, cursor_pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|