Browse Source
Removed OptionsAccumulator.h and merged it into Settings.h
Removed OptionsAccumulator.h and merged it into Settings.h
Implemented some helper functions and convenience accessors
Former-commit-id: b2d91343af
main
7 changed files with 225 additions and 214 deletions
-
1src/settings/Argument.h
-
4src/settings/Option.h
-
48src/settings/OptionsAccumulator.cpp
-
120src/settings/OptionsAccumulator.h
-
105src/settings/Settings.cpp
-
143src/settings/Settings.h
-
18src/storm.cpp
@ -1,48 +0,0 @@ |
|||||
#include "src/settings/OptionsAccumulator.h"
|
|
||||
|
|
||||
/*!
|
|
||||
* The map holding the information regarding registered options and their types |
|
||||
*/ |
|
||||
//std::unordered_map<std::string, std::shared_ptr<Option>> options;
|
|
||||
|
|
||||
/*!
|
|
||||
* The map holding the information regarding registered options and their short names |
|
||||
*/ |
|
||||
//std::unordered_map<std::string, std::string> shortNames;
|
|
||||
|
|
||||
storm::settings::OptionsAccumulator& storm::settings::OptionsAccumulator::addOption(Option* option) { |
|
||||
// For automatic management of option's lifetime
|
|
||||
std::shared_ptr<Option> optionPtr(option); |
|
||||
|
|
||||
std::string lowerLongName = storm::utility::StringHelper::stringToLower(option->getLongName()); |
|
||||
std::string lowerShortName = storm::utility::StringHelper::stringToLower(option->getShortName()); |
|
||||
|
|
||||
auto longNameIterator = this->options.find(lowerLongName); |
|
||||
auto shortNameIterator = this->shortNames.find(lowerShortName); |
|
||||
|
|
||||
if (longNameIterator == this->options.end()) { |
|
||||
// Not found
|
|
||||
if (!(shortNameIterator == this->shortNames.end())) { |
|
||||
// There exists an option which uses the same shortname
|
|
||||
// LOG
|
|
||||
throw storm::exceptions::OptionUnificationException() << "Error: The Option \"" << shortNameIterator->second << "\" from Module \"" << this->options.find(shortNameIterator->second)->second.get()->getModuleName() << "\" uses the same ShortName as the Option \"" << option->getLongName() << "\" from Module \"" << option->getModuleName() << "\"!"; |
|
||||
} |
|
||||
|
|
||||
// Copy Shared_ptr
|
|
||||
this->options.insert(std::make_pair(lowerLongName, std::shared_ptr<Option>(optionPtr))); |
|
||||
this->optionPointers.push_back(std::shared_ptr<Option>(optionPtr)); |
|
||||
this->shortNames.insert(std::make_pair(lowerShortName, lowerLongName)); |
|
||||
} else { |
|
||||
// This will fail if the shortNames are not identical, so no additional checks here.
|
|
||||
longNameIterator->second.get()->unify(*option); |
|
||||
} |
|
||||
|
|
||||
return *this; |
|
||||
} |
|
||||
|
|
||||
void storm::settings::OptionsAccumulator::join(storm::settings::OptionsAccumulator const& rhs) { |
|
||||
for (auto it = rhs.options.begin(); it != rhs.options.end(); ++it) { |
|
||||
// Clone all Options
|
|
||||
this->addOption(it->second.get()->clone()); |
|
||||
} |
|
||||
} |
|
@ -1,120 +0,0 @@ |
|||||
/* |
|
||||
* OptionsAccumulator.h |
|
||||
* |
|
||||
* Created on: 22.08.2013 |
|
||||
* Author: Philipp Berger |
|
||||
*/ |
|
||||
|
|
||||
#ifndef STORM_SETTINGS_OPTIONSACCUMULATOR_H_ |
|
||||
#define STORM_SETTINGS_OPTIONSACCUMULATOR_H_ |
|
||||
|
|
||||
#include <iostream> |
|
||||
#include <string> |
|
||||
#include <functional> |
|
||||
#include <unordered_map> |
|
||||
#include <algorithm> |
|
||||
#include <cstdint> |
|
||||
#include <vector> |
|
||||
#include <memory> |
|
||||
|
|
||||
#include "src/settings/Option.h" |
|
||||
|
|
||||
namespace storm { |
|
||||
namespace settings { |
|
||||
class Settings; |
|
||||
|
|
||||
|
|
||||
class OptionsAccumulator { |
|
||||
public: |
|
||||
OptionsAccumulator() {} |
|
||||
~OptionsAccumulator() { |
|
||||
//this->shortNames.clear(); |
|
||||
//this->options.clear(); |
|
||||
} |
|
||||
|
|
||||
OptionsAccumulator& addOption(Option* option); |
|
||||
void join(OptionsAccumulator const& rhs); |
|
||||
|
|
||||
friend class storm::settings::Settings; |
|
||||
private: |
|
||||
/*! |
|
||||
* The map holding the information regarding registered options and their types |
|
||||
*/ |
|
||||
std::unordered_map<std::string, std::shared_ptr<Option>> options; |
|
||||
|
|
||||
/*! |
|
||||
* The vector holding a pointer to all options |
|
||||
*/ |
|
||||
std::vector<std::shared_ptr<Option>> optionPointers; |
|
||||
|
|
||||
/*! |
|
||||
* The map holding the information regarding registered options and their short names |
|
||||
*/ |
|
||||
std::unordered_map<std::string, std::string> shortNames; |
|
||||
|
|
||||
/*! |
|
||||
* Returns true IFF this accumulator contains an option with the specified longName. |
|
||||
*/ |
|
||||
bool containsLongName(std::string const& longName) { |
|
||||
return (this->options.find(storm::utility::StringHelper::stringToLower(longName)) != this->options.end()); |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* Returns true IFF this accumulator contains an option with the specified shortName. |
|
||||
*/ |
|
||||
bool containsShortName(std::string const& shortName) { |
|
||||
return (this->shortNames.find(storm::utility::StringHelper::stringToLower(shortName)) != this->shortNames.end()); |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* Returns a reference to the Option with the specified longName. |
|
||||
* Throws an Exception of Type InvalidArgumentException if there is no such Option. |
|
||||
*/ |
|
||||
Option& getByLongName(std::string const& longName) { |
|
||||
auto longNameIterator = this->options.find(storm::utility::StringHelper::stringToLower(longName)); |
|
||||
if (longNameIterator == this->options.end()) { |
|
||||
throw storm::exceptions::IllegalArgumentException() << "This Accumulator does not contain an Option named \"" << longName << "\"!"; |
|
||||
} |
|
||||
return *longNameIterator->second.get(); |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* Returns a pointer to the Option with the specified longName. |
|
||||
* Throws an Exception of Type InvalidArgumentException if there is no such Option. |
|
||||
*/ |
|
||||
Option* getPtrByLongName(std::string const& longName) { |
|
||||
auto longNameIterator = this->options.find(storm::utility::StringHelper::stringToLower(longName)); |
|
||||
if (longNameIterator == this->options.end()) { |
|
||||
throw storm::exceptions::IllegalArgumentException() << "This Accumulator does not contain an Option named \"" << longName << "\"!"; |
|
||||
} |
|
||||
return longNameIterator->second.get(); |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* Returns a reference to the Option with the specified shortName. |
|
||||
* Throws an Exception of Type InvalidArgumentException if there is no such Option. |
|
||||
*/ |
|
||||
Option& getByShortName(std::string const& shortName) { |
|
||||
auto shortNameIterator = this->shortNames.find(storm::utility::StringHelper::stringToLower(shortName)); |
|
||||
if (shortNameIterator == this->shortNames.end()) { |
|
||||
throw storm::exceptions::IllegalArgumentException() << "This Accumulator does not contain an Option with ShortName \"" << shortName << "\"!"; |
|
||||
} |
|
||||
return *(this->options.find(shortNameIterator->second)->second.get()); |
|
||||
} |
|
||||
|
|
||||
/*! |
|
||||
* Returns a pointer to the Option with the specified shortName. |
|
||||
* Throws an Exception of Type InvalidArgumentException if there is no such Option. |
|
||||
*/ |
|
||||
Option* getPtrByShortName(std::string const& shortName) { |
|
||||
auto shortNameIterator = this->shortNames.find(storm::utility::StringHelper::stringToLower(shortName)); |
|
||||
if (shortNameIterator == this->shortNames.end()) { |
|
||||
throw storm::exceptions::IllegalArgumentException() << "This Accumulator does not contain an Option with ShortName \"" << shortName << "\"!"; |
|
||||
} |
|
||||
return this->options.find(shortNameIterator->second)->second.get(); |
|
||||
} |
|
||||
}; |
|
||||
} |
|
||||
} |
|
||||
|
|
||||
#endif // STORM_SETTINGS_OPTIONSACCUMULATOR_H_ |
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue