42 #define FILTER_CLASS(FilterName) \
43 explicit FilterName(const std::string& parameters = "") : \
44 ::ai::IFilter(#FilterName, parameters) { \
47 virtual ~FilterName() { \
50 #define FILTER_FACTORY(FilterName) \
52 class Factory: public ::ai::IFilterFactory { \
54 ::ai::FilterPtr create (const ::ai::FilterFactoryContext *ctx) const override { \
55 return std::make_shared<FilterName>(ctx->parameters); \
58 static const Factory& getFactory() { \
59 static Factory FACTORY; \
63 #define FILTER_ACTION_CLASS(FilterName) \
64 FilterName(const std::string& parameters, const ::ai::Filters& filters) : \
65 ::ai::IFilter(#FilterName, parameters), _filters(filters) { \
66 ai_assert(_filters.size() > 1, #FilterName " must contain at least two sub filters"); \
69 const ::ai::Filters _filters; \
71 virtual ~FilterName() { \
74 #define FILTER_ACTION_FACTORY(FilterName) \
76 class Factory: public ::ai::IFilterFactory { \
78 ::ai::FilterPtr create (const ::ai::FilterFactoryContext *ctx) const override { \
79 return std::make_shared<FilterName>(ctx->parameters, ctx->filters); \
82 static const Factory& getFactory() { \
83 static Factory FACTORY; \
87 #define FILTER_FACTORY_SINGLETON \
89 class Factory: public ::ai::IFilterFactory { \
90 ::ai::FilterPtr create (const ::ai::FilterFactoryContext *) const override { \
94 static const Factory& getFactory() { \
95 static Factory FACTORY; \
102 #define FILTER_CLASS_SINGLETON(FilterName) \
104 FILTER_CLASS(FilterName) \
106 static ::ai::FilterPtr& get() { \
107 AI_THREAD_LOCAL FilterName* c = nullptr; \
108 if (c == nullptr) { c = new FilterName; } \
109 AI_THREAD_LOCAL ::ai::FilterPtr _instance(c); \
112 FILTER_FACTORY_SINGLETON
130 class IFilter :
public MemObject {
132 const std::string _name;
133 const std::string _parameters;
141 inline FilteredEntities& getFilteredEntities(
const AIPtr& ai) {
142 return ai->_filteredEntities;
145 IFilter (
const std::string& name,
const std::string& parameters) :
146 _name(name), _parameters(parameters) {
149 virtual ~IFilter () {
152 inline const std::string& getName()
const {
156 inline const std::string& getParameters()
const {
160 virtual void filter (
const AIPtr& entity) = 0;