diff --git a/src/ir/Module.cpp b/src/ir/Module.cpp index d800256c8..98e7b1275 100644 --- a/src/ir/Module.cpp +++ b/src/ir/Module.cpp @@ -17,7 +17,7 @@ namespace ir { // Initializes all members with their default constructors. Module::Module() : moduleName(), booleanVariables(), integerVariables(), booleanVariablesToIndexMap(), - integerVariablesToIndexMap(), commands() { + integerVariablesToIndexMap(), commands(), actionsToCommandIndexMap() { // Nothing to do here. } @@ -29,8 +29,14 @@ Module::Module(std::string moduleName, std::vector<storm::ir::BooleanVariable> b std::vector<storm::ir::Command> commands) : moduleName(moduleName), booleanVariables(booleanVariables), integerVariables(integerVariables), booleanVariablesToIndexMap(booleanVariableToIndexMap), - integerVariablesToIndexMap(integerVariableToIndexMap), commands(commands) { - // Nothing to do here. + integerVariablesToIndexMap(integerVariableToIndexMap), commands(commands), actionsToCommandIndexMap() { + // Build actionsToCommandIndexMap + for (unsigned int id = 0; id < this->commands.size(); id++) { + std::string action = this->commands[id].getActionName(); + if (action != "") { + this->actionsToCommandIndexMap[action]->insert(id); + } + } } // Return the number of boolean variables. @@ -100,6 +106,16 @@ std::string Module::toString() const { return result.str(); } +// Return Commands with given action. +std::shared_ptr<std::set<uint_fast64_t>> const Module::getCommandsByAction(std::string const& action) const { + auto res = this->actionsToCommandIndexMap.find(action); + if (res == this->actionsToCommandIndexMap.end()) { + return std::shared_ptr<std::set<uint_fast64_t>>(new std::set<uint_fast64_t>()); + } else { + return res->second; + } +} + } // namespace ir } // namespace storm diff --git a/src/ir/Module.h b/src/ir/Module.h index 2c362da41..d07350b80 100644 --- a/src/ir/Module.h +++ b/src/ir/Module.h @@ -13,8 +13,10 @@ #include "Command.h" #include <map> +#include <set> #include <string> #include <vector> +#include <memory> namespace storm { @@ -98,6 +100,14 @@ public: * @returns a string representation of this variable. */ std::string toString() const; + + /*! + * Retrieves the indices of all Commands within this module that are labelled + * by the given action. + * @param action Name of the action + * @returns Indices of all matching Commands. + */ + std::shared_ptr<std::set<uint_fast64_t>> const getCommandsByAction(std::string const& action) const; private: // The name of the module. @@ -117,6 +127,9 @@ private: // The commands associated with the module. std::vector<storm::ir::Command> commands; + + // A map of actions to the set of commands labelled with this action. + std::map<std::string, std::shared_ptr<std::set<uint_fast64_t>>> actionsToCommandIndexMap; }; } // namespace ir