From 66736c36264d53e6e53bfa980db6d7a1572012ae Mon Sep 17 00:00:00 2001 From: sjunges Date: Thu, 8 Oct 2015 14:38:55 +0200 Subject: [PATCH] More to string methods for simplevaluation Former-commit-id: 487ed4a8d6bf62034f32a3a19191bfe04e699be0 --- src/storage/expressions/SimpleValuation.cpp | 68 +++++++++++++++------ src/storage/expressions/SimpleValuation.h | 4 +- 2 files changed, 51 insertions(+), 21 deletions(-) diff --git a/src/storage/expressions/SimpleValuation.cpp b/src/storage/expressions/SimpleValuation.cpp index 57035b397..3a7a995dc 100644 --- a/src/storage/expressions/SimpleValuation.cpp +++ b/src/storage/expressions/SimpleValuation.cpp @@ -109,30 +109,58 @@ namespace storm { } return "[" + boost::join(assignments, ", ") + "]"; } - - std::ostream& operator<<(std::ostream& out, SimpleValuation const& valuation) { - out << "valuation {" << std::endl; - out << valuation.getManager() << std::endl; - if (!valuation.booleanValues.empty()) { - for (auto const& element : valuation.booleanValues) { - out << element << " "; + + + std::string SimpleValuation::toString(bool pretty) const { + + + std::stringstream sstr; + if(pretty) { + sstr << "valuation {" << std::endl; + for(auto const& e : getManager()) { + sstr << e.first.getName() << "="; + if (e.first.hasBooleanType()) { + sstr << std::boolalpha << this->getBooleanValue(e.first) << std::noboolalpha; + } else if (e.first.hasIntegerType()) { + sstr << this->getIntegerValue(e.first); + } else if (e.first.hasRationalType()) { + sstr << this->getRationalValue(e.first); + } else { + STORM_LOG_THROW(false, storm::exceptions::InvalidTypeException, "Unexpected variable type."); + } + sstr << std::endl; } - out << std::endl; - } - if (!valuation.integerValues.empty()) { - for (auto const& element : valuation.integerValues) { - out << element << " "; + sstr << "}"; + } else { + sstr << "valuation {" << std::endl; + sstr << getManager() << std::endl; + if (!booleanValues.empty()) { + for (auto const& element : booleanValues) { + sstr << element << " "; + } + sstr << std::endl; } - out << std::endl; - } - if (!valuation.rationalValues.empty()) { - for (auto const& element : valuation.rationalValues) { - out << element << " "; + if (!integerValues.empty()) { + for (auto const& element : integerValues) { + sstr << element << " "; + } + sstr << std::endl; + } + if (!rationalValues.empty()) { + for (auto const& element : rationalValues) { + sstr << element << " "; + } + sstr << std::endl; } - out << std::endl; + sstr << "}"; } - out << "}" << std::endl; - + + + return sstr.str(); + } + + std::ostream& operator<<(std::ostream& out, SimpleValuation const& valuation) { + out << valuation.toString(false) << std::endl; return out; } diff --git a/src/storage/expressions/SimpleValuation.h b/src/storage/expressions/SimpleValuation.h index 47278e1ee..d9477b41e 100644 --- a/src/storage/expressions/SimpleValuation.h +++ b/src/storage/expressions/SimpleValuation.h @@ -61,7 +61,9 @@ namespace storm { * @return The string representation. */ virtual std::string toPrettyString(std::set const& selectedVariables) const; - + + virtual std::string toString(bool pretty = true) const; + friend std::ostream& operator<<(std::ostream& out, SimpleValuation const& valuation); private: