From f60ea09cf460e4fb03341513ff186c6f302a9a95 Mon Sep 17 00:00:00 2001 From: dehnert Date: Fri, 9 May 2014 19:37:27 +0200 Subject: [PATCH] Valuations now have methods to check whether they contain a given identifier. Former-commit-id: 541c27d543866ac4c3f419a9514945a018022673 --- src/storage/expressions/SimpleValuation.cpp | 30 +++++++++++++++++++++ src/storage/expressions/SimpleValuation.h | 10 +++++++ src/storage/expressions/Valuation.h | 25 +++++++++++++++++ 3 files changed, 65 insertions(+) diff --git a/src/storage/expressions/SimpleValuation.cpp b/src/storage/expressions/SimpleValuation.cpp index f930f7e10..e8fb27611 100644 --- a/src/storage/expressions/SimpleValuation.cpp +++ b/src/storage/expressions/SimpleValuation.cpp @@ -37,6 +37,36 @@ namespace storm { this->identifierToValueMap[name] = value; } + void SimpleValuation::removeIdentifier(std::string const& name) { + auto nameValuePair = this->identifierToValueMap.find(name); + LOG_THROW(nameValuePair != this->identifierToValueMap.end(), storm::exceptions::InvalidArgumentException, "Deleting unknown identifier '" << name << "'."); + this->identifierToValueMap.erase(nameValuePair); + } + + bool SimpleValuation::containsBooleanIdentifier(std::string const& name) const { + auto nameValuePair = this->identifierToValueMap.find(name); + if (nameValuePair == this->identifierToValueMap.end()) { + return false; + } + return nameValuePair->second.type() == typeid(bool); + } + + bool SimpleValuation::containsIntegerIdentifier(std::string const& name) const { + auto nameValuePair = this->identifierToValueMap.find(name); + if (nameValuePair == this->identifierToValueMap.end()) { + return false; + } + return nameValuePair->second.type() == typeid(int_fast64_t); + } + + bool SimpleValuation::containsDoubleIdentifier(std::string const& name) const { + auto nameValuePair = this->identifierToValueMap.find(name); + if (nameValuePair == this->identifierToValueMap.end()) { + return false; + } + return nameValuePair->second.type() == typeid(double); + } + bool SimpleValuation::getBooleanValue(std::string const& name) const { auto nameValuePair = this->identifierToValueMap.find(name); LOG_THROW(nameValuePair != this->identifierToValueMap.end(), storm::exceptions::InvalidAccessException, "Access to unkown identifier '" << name << "'."); diff --git a/src/storage/expressions/SimpleValuation.h b/src/storage/expressions/SimpleValuation.h index 55caab46b..0ea05a511 100644 --- a/src/storage/expressions/SimpleValuation.h +++ b/src/storage/expressions/SimpleValuation.h @@ -78,7 +78,17 @@ namespace storm { */ void setDoubleValue(std::string const& name, double value); + /*! + * Removes the given identifier from this valuation. + * + * @param name The name of the identifier that is to be removed. + */ + void removeIdentifier(std::string const& name); + // Override base class methods. + virtual bool containsBooleanIdentifier(std::string const& name) const override; + virtual bool containsIntegerIdentifier(std::string const& name) const override; + virtual bool containsDoubleIdentifier(std::string const& name) const override; virtual bool getBooleanValue(std::string const& name) const override; virtual int_fast64_t getIntegerValue(std::string const& name) const override; virtual double getDoubleValue(std::string const& name) const override; diff --git a/src/storage/expressions/Valuation.h b/src/storage/expressions/Valuation.h index 7aa32a859..19792b720 100644 --- a/src/storage/expressions/Valuation.h +++ b/src/storage/expressions/Valuation.h @@ -34,6 +34,31 @@ namespace storm { * @return The value of the double identifier. */ virtual double getDoubleValue(std::string const& name) const = 0; + + /*! + * Retrieves whether there exists a boolean identifier with the given name in the valuation. + * + * @param name The name of the boolean identifier to query. + * @return True iff the identifier exists and is of boolean type. + */ + virtual bool containsBooleanIdentifier(std::string const& name) const = 0; + + /*! + * Retrieves whether there exists a integer identifier with the given name in the valuation. + * + * @param name The name of the integer identifier to query. + * @return True iff the identifier exists and is of boolean type. + */ + virtual bool containsIntegerIdentifier(std::string const& name) const = 0; + + /*! + * Retrieves whether there exists a double identifier with the given name in the valuation. + * + * @param name The name of the double identifier to query. + * @return True iff the identifier exists and is of boolean type. + */ + virtual bool containsDoubleIdentifier(std::string const& name) const = 0; + }; } }