From 29012699095da64c79019dd47a345c5a0f304b2b Mon Sep 17 00:00:00 2001 From: sjunges Date: Mon, 23 May 2016 16:09:06 +0200 Subject: [PATCH] Model: -Actions -Const correctness -Constructor takes a name Former-commit-id: 0023152caece5d7ccd38008bc0d28f9da4888109 --- src/storage/jani/Model.cpp | 24 ++++++++++++++++++++--- src/storage/jani/Model.h | 40 ++++++++++++++++++++++++++++++++------ 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/src/storage/jani/Model.cpp b/src/storage/jani/Model.cpp index f3ffb108a..615cdd7e2 100644 --- a/src/storage/jani/Model.cpp +++ b/src/storage/jani/Model.cpp @@ -1,17 +1,35 @@ +#include #include "src/storage/jani/Model.h" namespace storm { namespace jani { - Model::Model(ModelType const& modelType, uint64_t version) : modelType(modelType), version(version) { + Model::Model(std::string const& name, ModelType const& modelType, uint64_t version) : name(name), modelType(modelType), version(version) { // Intentionally left empty. } - void Model::checkSupported() { + uint64_t Model::addAction(Action const& act) { + STORM_LOG_THROW(actionToIndex.count(act.getName()) == 0, storm::exceptions::InvalidJaniException, "Action with name " + act.getName() + " already exists"); + actionToIndex.emplace(act.getName(), actions.size()); + actions.push_back(act); + return actions.size() - 1; + } + + bool Model::hasAction(std::string const &name) const { + return actionToIndex.count(name) != 0; + } + + uint64_t Model::getActionIndex(std::string const& name) const { + assert(this->hasAction(name)); + return actionToIndex.at(name); + } + + + void Model::checkSupported() const { //TODO } - bool Model::checkValidity(bool logdbg) { + bool Model::checkValidity(bool logdbg) const { // TODO switch to exception based return value. if (version == 0) { diff --git a/src/storage/jani/Model.h b/src/storage/jani/Model.h index ab2ac4ed4..3c20f08c1 100644 --- a/src/storage/jani/Model.h +++ b/src/storage/jani/Model.h @@ -2,6 +2,7 @@ #include "src/utility/macros.h" +#include "src/storage/jani/Action.h" #include "src/storage/jani/ModelType.h" #include "src/storage/jani/Automaton.h" @@ -13,8 +14,29 @@ namespace storm { /*! * Creates an empty model with the given type. */ - Model(ModelType const& modelType, uint64_t version = 1); + Model(std::string const& name, ModelType const& modelType, uint64_t version = 1); + + /** + * Checks whether the model has an action with the given name. + * + * @param name The name to look for. + */ + bool hasAction(std::string const& name) const; + + /** + * Get the index of the action + * @param the name of the model + * @return the index of the (unique) action with the given name, undefined if no such action is present. + */ + uint64_t getActionIndex(std::string const& name) const; + /** + * Adds an action to the model. + * + * @return the index for this action. + */ + uint64_t addAction(Action const& act); + /*! * Does some simple checks to determine whether the model is supported by Prism. * Mainly checks abscence of features the parser supports. @@ -22,23 +44,29 @@ namespace storm { * Throws UnsupportedModelException if something is wrong */ // TODO add engine as argument to check this for several engines. - void checkSupported(); + void checkSupported() const; /*! * Checks if the model is valid JANI, which should be verified before any further operations are applied to a model. */ - bool checkValidity(bool logdbg = true); + bool checkValidity(bool logdbg = true) const; private: + /// The model name + std::string name; /// The list of automata std::vector automata; /// A mapping from names to automata indices - std::map automatonIndex; + std::unordered_map automatonToIndex; + /// The list with actions + std::vector actions; + /// A mapping from names to action indices + std::unordered_map actionToIndex; + /// The type of the model. ModelType modelType; /// The JANI-version used to specify the model. uint64_t version; - /// The model name - std::string name; + }; }