Storm
A Modern Probabilistic Model Checker
Loading...
Searching...
No Matches
ArgumentBase.cpp
Go to the documentation of this file.
2
3#include <boost/algorithm/string.hpp>
4#include <iomanip>
5#include <sstream>
6
7namespace storm {
8namespace settings {
9std::ostream& operator<<(std::ostream& out, ArgumentBase const& argument) {
10 argument.printToStream(out);
11 return out;
12}
13
14template<typename TargetType>
16 std::istringstream stream(valueAsString);
17 TargetType t;
18 conversionSuccessful = (stream >> t) && (stream >> std::ws).eof();
19 return t;
20}
21
22template<>
25 return valueAsString;
26}
27
28template<>
29bool ArgumentBase::convertFromString<bool>(std::string const& s, bool& ok) {
30 static const std::string lowerTrueString = "true";
31 static const std::string lowerFalseString = "false";
32 static const std::string lowerYesString = "yes";
33 static const std::string lowerNoString = "no";
34
35 std::string lowerInput = boost::algorithm::to_lower_copy(s);
36
37 if (s.compare(lowerTrueString) == 0 || s.compare(lowerYesString) == 0) {
38 ok = true;
39 return true;
40 } else if (s.compare(lowerFalseString) == 0 || s.compare(lowerNoString) == 0) {
41 ok = true;
42 return false;
43 }
44
45 std::istringstream stream(s);
46 bool t;
47 ok = (stream >> t) && (stream >> std::ws).eof();
48 return t;
49}
50
51template<typename ValueType>
52std::string ArgumentBase::convertToString(ValueType const& value) {
53 std::ostringstream stream;
54 stream << value;
55 return stream.str();
56}
57
58// Explicitly instantiate the templates.
61template double ArgumentBase::convertFromString(std::string const& valueAsString, bool& conversionSuccessful);
62
63template std::string ArgumentBase::convertToString(std::string const& value);
64template std::string ArgumentBase::convertToString(int_fast64_t const& value);
65template std::string ArgumentBase::convertToString(uint_fast64_t const& value);
66template std::string ArgumentBase::convertToString(double const& value);
67template std::string ArgumentBase::convertToString(bool const& value);
68} // namespace settings
69} // namespace storm
This class serves as the (untemplated) base class of argument classes.
static TargetType convertFromString(std::string const &valueAsString, bool &conversionSuccessful)
Converts the given value represented as a string to the type of the template parameter.
static std::string convertToString(ValueType const &value)
Converts the given value to a string representation.
SettingsType const & getModule()
Get module.
std::ostream & operator<<(std::ostream &out, ArgumentBase const &argument)
LabParser.cpp.
Definition cli.cpp:18