Browse Source

Added an Option for the Constants of the ExplicitModelAdapter

Implemented very basic validation of the input


Former-commit-id: f5f2340129
main
PBerger 12 years ago
parent
commit
fad8371d7a
  1. 38
      src/adapters/ExplicitModelAdapter.cpp

38
src/adapters/ExplicitModelAdapter.cpp

@ -15,6 +15,8 @@
#include "src/models/Mdp.h"
#include "src/models/Ctmdp.h"
#include <algorithm>
#include <functional>
#include <boost/algorithm/string.hpp>
#include <sstream>
@ -23,6 +25,42 @@
#include "log4cplus/loggingmacros.h"
extern log4cplus::Logger logger;
bool ExplicitModelAdapterOptionsRegistered = storm::settings::Settings::registerNewModule([] (storm::settings::Settings* instance) -> bool {
instance->addOption(storm::settings::OptionBuilder("ExplicitModelAdapter", "constants", "", "Specifies the constant replacements to use in Explicit Models").addArgument(storm::settings::ArgumentBuilder::createStringArgument("constantString", "A comma separated list of constants and their value, e.g. a=1,b=2,c=3").addValidationFunctionString(
[] (std::string const& s) -> bool {
// since regex is not yet implemented in gccs C++11, we have to check by hand
std::vector<std::string> constants;
// split for single assignment expressions
boost::split(constants, s, boost::is_any_of(","));
for (auto it = constants.cbegin(); it != constants.cend(); ++it) {
std::vector<std::string> constant;
boost::split(constant, *it, boost::is_any_of("="));
if (constant.size() != 2) {
return false;
}
// Constant Name check
bool error = false;
std::for_each(constant.at(0).cbegin(), constant.at(0).cend(), [&error] (const std::string::value_type value) -> void {
if (!(('a' <= value && value <= 'z') || ('A' <= value && value <= 'Z') || ('0' <= value && value <= '9'))) {
error = true;
}
});
// Value Check
std::for_each(constant.at(1).cbegin(), constant.at(1).cend(), [&error] (const std::string::value_type value) -> void {
if (!(('a' <= value && value <= 'z') || ('A' <= value && value <= 'Z') || ('0' <= value && value <= '9'))) {
error = true;
}
});
if (error) {
return false;
}
}
return true;
}).setDefaultValueString("").build()).build());
return true;
});
namespace storm {
namespace adapters {

Loading…
Cancel
Save