20inline namespace options {
25template <
typename actualOption_T>
32 explicit operator bool() =
delete;
39 const auto mapOptionNames = actualOption_T::getOptionNames();
40 std::set<actualOption_T> retSet;
41 std::for_each(mapOptionNames.begin(), mapOptionNames.end(),
42 [&](
auto pairOpStr) { retSet.insert(pairOpStr.first); });
53 const auto discouragedOptions = actualOption_T::getDiscouragedOptions();
54 std::set<actualOption_T> retSet;
55 std::set_difference(allOptions.begin(), allOptions.end(), discouragedOptions.begin(), discouragedOptions.end(),
56 std::inserter(retSet, retSet.begin()));
65 [[nodiscard]] std::string
to_string(
bool fixedLength =
false)
const {
66 const auto &actualThis = *
static_cast<const actualOption_T *
>(
this);
67 const auto mapOptNames = actualOption_T::getOptionNames();
68 const auto match = mapOptNames.find(actualThis);
69 if (match == mapOptNames.end()) {
70 return "Unknown Option (" + std::to_string(actualThis) +
")";
72 std::string result = match->second;
85 static size_t maxLength = 0;
87 for (
const auto &[_, name] : actualOption_T::getOptionNames()) {
88 maxLength = std::max(maxLength, name.size());
110 template <
class OutputContainer = std::set<actualOption_T>>
111 static OutputContainer
parseOptions(
const std::string &optionsString) {
115 if (needles.size() == 1 and needles.front() ==
"all") {
116 if constexpr (std::is_same_v<OutputContainer, std::set<actualOption_T>>) {
117 return actualOption_T::getAllOptions();
119 const auto allOptionsSet = actualOption_T::getAllOptions();
120 OutputContainer allOptionsOut;
121 std::copy(allOptionsSet.begin(), allOptionsSet.end(),
122 std::insert_iterator(allOptionsOut, allOptionsOut.begin()));
123 return allOptionsOut;
128 std::map<std::string, actualOption_T> allOptionNamesLower;
129 std::vector<std::string> haystack;
130 for (
auto &[optionEnum, optionString] : actualOption_T::getOptionNames()) {
131 std::transform(optionString.begin(), optionString.end(), optionString.begin(), ::tolower);
132 allOptionNamesLower.emplace(optionString, optionEnum);
133 haystack.push_back(optionString);
137 OutputContainer foundOptions;
138 std::transform(needles.begin(), needles.end(), std::insert_iterator(foundOptions, foundOptions.begin()),
139 [&](
const auto &needle) {
141 const auto matchingString = autopas::utils::StringUtils::matchStrings(haystack, needle);
143 return allOptionNamesLower[matchingString];
158 template <
bool lowercase = false>
160 for (
auto [optionEnum, optionName] : actualOption_T::getOptionNames()) {
161 if constexpr (lowercase) {
162 std::transform(std::begin(optionName), std::end(optionName), std::begin(optionName), ::tolower);
164 if (optionString == optionName) {
171 return actualOption_T();
191 friend std::istream &
operator>>(std::istream &in, actualOption_T &option) {
195 while (std::iswspace(c)) {
204 }
while (std::isalnum(c) or c ==
'_' or c ==
'-');
220template <
typename actualOption_T>
Base class for autopas options.
Definition: Option.h:26
static std::set< actualOption_T > getAllOptions()
Provides a way to iterate over the possible options.
Definition: Option.h:38
friend std::ostream & operator<<(std::ostream &os, const Option &option)
Stream output operator.
Definition: Option.h:180
static size_t maxStringLength()
Returns the number of characters in the string representation of the longest option.
Definition: Option.h:84
static OutputContainer parseOptions(const std::string &optionsString)
Converts a string of options to a set of enums.
Definition: Option.h:111
static actualOption_T parseOptionExact(const std::string &optionString)
Converts a string to an enum.
Definition: Option.h:159
static std::set< actualOption_T > getMostOptions()
Provides a way to iterate over the possible options minus those that are very unlikely to be on inter...
Definition: Option.h:51
std::string to_string(bool fixedLength=false) const
Converts an Option object to its respective string representation.
Definition: Option.h:65
friend std::istream & operator>>(std::istream &in, actualOption_T &option)
Stream extraction operator.
Definition: Option.h:191
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
std::string format_as(const Option< actualOption_T > &opt)
Function required for modern fmt/spdlog integration (fmt v9+).
Definition: Option.h:221
constexpr char delimiters[]
All accepted delimiters to split input strings.
Definition: StringUtils.h:111
std::vector< std::string > tokenize(const std::string &searchString, const std::string &delimiters)
Splits a string by multiple delimiters.
Definition: StringUtils.h:141
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34