From 7fcf598e86701827658cecfa5e02d72d3a3c247b Mon Sep 17 00:00:00 2001 From: sjunges Date: Mon, 23 May 2016 14:27:35 +0200 Subject: [PATCH] Automaton: Retrieve location id by name Former-commit-id: d8aa9c1ba399ea70e6ce16a15de4d7ae2c75100f --- src/storage/jani/Automaton.cpp | 10 ++++++++-- src/storage/jani/Automaton.h | 10 +++++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/src/storage/jani/Automaton.cpp b/src/storage/jani/Automaton.cpp index d3958b6d8..dd8548c96 100644 --- a/src/storage/jani/Automaton.cpp +++ b/src/storage/jani/Automaton.cpp @@ -39,12 +39,18 @@ namespace storm { return locations; } - void Automaton::addLocation(Location const& location) { + uint64_t Automaton::addLocation(Location const& location) { STORM_LOG_THROW(!this->hasLocation(location.getName()), storm::exceptions::WrongFormatException, "Cannot add location with name '" << location.getName() << "', because a location with this name already exists."); locationToIndex.emplace(location.getName(), locations.size()); locations.push_back(location); + return locations.size() - 1; } - + + uint64_t Automaton::getLocationId(std::string const& name) const { + assert(hasLocation(name)); + return locationToIndex.at(name); + } + void Automaton::setInitialLocation(std::string const& name) { auto it = locationToIndex.find(name); STORM_LOG_THROW(it != locationToIndex.end(), storm::exceptions::InvalidArgumentException, "Cannot make unknown location '" << name << "' the initial location."); diff --git a/src/storage/jani/Automaton.h b/src/storage/jani/Automaton.h index 270f0921c..d065a6dc9 100644 --- a/src/storage/jani/Automaton.h +++ b/src/storage/jani/Automaton.h @@ -47,6 +47,14 @@ namespace storm { * Retrieves whether the automaton has a location with the given name. */ bool hasLocation(std::string const& name) const; + + /*! + * Get location id for a location with a given name. + * Yields undefined behaviour if no such location exists; + * + * @name the name of the location + */ + uint64_t getLocationId(std::string const& name) const; /*! * Retrieves the locations of the automaton. @@ -56,7 +64,7 @@ namespace storm { /*! * Adds the given location to the automaton. */ - void addLocation(Location const& location); + uint64_t addLocation(Location const& location); /*! * Uses the location with the given name as the initial location.