Add method Actions::has( action_name )

This commit is contained in:
Joakim Hove 2022-01-20 16:12:17 +01:00
parent 5e5dd48cee
commit 45a6e4fb15
2 changed files with 7 additions and 0 deletions

View File

@ -57,6 +57,7 @@ public:
std::vector<const ActionX *> pending(const State& state, std::time_t sim_time) const;
std::vector<const PyAction *> pending_python() const;
bool has(const std::string& name) const;
std::vector<ActionX>::const_iterator begin() const;
std::vector<ActionX>::const_iterator end() const;

View File

@ -82,6 +82,12 @@ const ActionX& Actions::operator[](const std::string& name) const {
return *iter;
}
bool Actions::has(const std::string& name) const {
const auto iter = std::find_if( this->actions.begin(), this->actions.end(), [&name](const ActionX& action) { return action.name() == name; });
return (iter != this->actions.end());
}
const ActionX& Actions::operator[](std::size_t index) const {
return this->actions[index];
}