SimpleAI
 All Classes Namespaces Files Functions Variables Typedefs Macros Groups Pages
Last.h
Go to the documentation of this file.
1 
5 #pragma once
6 
7 #include "filter/IFilter.h"
8 
9 namespace ai {
10 
14 class Last: public IFilter {
15 protected:
16  Filters _filters;
17 public:
18  Last(const std::string& parameters, const Filters& filters) :
19  IFilter("Last", parameters), _filters(filters) {
20  ai_assert(filters.size() == 1, "Last must have one child");
21  }
22  FILTER_ACTION_FACTORY(Last)
23 
24  void filter (const AIPtr& entity) override;
25 };
26 
27 inline void Last::filter (const AIPtr& entity) {
28  FilteredEntities& filtered = getFilteredEntities(entity);
29  const FilteredEntities copy = filtered;
30  filtered.clear();
31  _filters.front()->filter(entity);
32  const auto& value = getFilteredEntities(entity).back();
33  filtered.clear();
34  for (auto& e : copy) {
35  filtered.push_back(e);
36  }
37  filtered.push_back(value);
38 }
39 
40 }
#define ai_assert(condition,...)
Provide your own assert - this is only executed in DEBUG mode.
Definition: Types.h:75
This filter will just preserve the last entry of other filters.
Definition: Last.h:14