votca 2024-dev
Loading...
Searching...
No Matches
optionshandler.h
Go to the documentation of this file.
1/*
2 * Copyright 2009-2020 The VOTCA Development Team (http://www.votca.org)
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18#ifndef VOTCA_TOOLS_OPTIONSHANDLER_H
19#define VOTCA_TOOLS_OPTIONSHANDLER_H
20
21// Local VOTCA includes
22#include "property.h"
23
24namespace votca {
25namespace tools {
26
28 public:
29 OptionsHandler(std::string defaults_path) : defaults_path_(defaults_path) {}
30
36 Property ProcessUserInput(const Property &user_input,
37 const std::string &calcname) const;
38
43 Property CalculatorOptions(const std::string &calcname) const;
44
49 void setAdditionalChoices(std::vector<std::string> choices) {
50 additional_choices_ = choices;
51 }
52
53 private:
58 void ResolveLinks(tools::Property &prop) const;
59
63 Property LoadDefaults(const std::string &calculatorname) const;
64
69 void CheckUserInput(const Property &user_input,
70 const Property &defaults) const;
71
75 void CheckRequired(const Property &options) const;
76
80 void RemoveOptional(Property &options) const;
81
82 void InjectDefaultsAsValues(Property &options) const;
83
84 void CheckChoices(const Property &options) const;
85
86 void CleanAttributes(Property &options,
87 const std::vector<std::string> &attributes) const;
88
90 Property &defaults) const;
91 // Copy the defaults into the value
92 void RecursivelyCheckOptions(const Property &p) const;
93 bool IsValidOption(const Property &prop,
94 const std::vector<std::string> &choices) const;
95 static std::vector<std::string> GetPropertyChoices(const Property &p);
96
97 std::string defaults_path_;
98
99 std::vector<std::string> additional_choices_{};
100 std::vector<std::string> reserved_keywords_{"OPTIONAL", "REQUIRED"};
101};
102
103} // namespace tools
104} // namespace votca
105
106#endif // VOTCA_TOOLS_OPTIONSHANDLER_H
void InjectDefaultsAsValues(Property &options) const
bool IsValidOption(const Property &prop, const std::vector< std::string > &choices) const
std::vector< std::string > additional_choices_
void OverwriteDefaultsWithUserInput(const Property &p, Property &defaults) const
void RemoveOptional(Property &options) const
Removes tags which have no value and default="OPTIONAL".
Property ProcessUserInput(const Property &user_input, const std::string &calcname) const
Load the default options and merge them with the user input.
static std::vector< std::string > GetPropertyChoices(const Property &p)
void CheckChoices(const Property &options) const
Property CalculatorOptions(const std::string &calcname) const
Resolve links and return all the options of a calculator.
void setAdditionalChoices(std::vector< std::string > choices)
Allows to bypass the choice evaluation for a specific calculator.
Property LoadDefaults(const std::string &calculatorname) const
Loads default options stored in defaults_path_.
OptionsHandler(std::string defaults_path)
void CheckUserInput(const Property &user_input, const Property &defaults) const
Checks if all keywords in user_input (apart from sections named "unchecked") have corresponding keys ...
void CheckRequired(const Property &options) const
Checks that all options with default="REQUIRED" are filled in.
void CleanAttributes(Property &options, const std::vector< std::string > &attributes) const
std::vector< std::string > reserved_keywords_
void ResolveLinks(tools::Property &prop) const
Resolves "link" attribute in the Property by filling in defaults. Already existing tags are not overw...
void RecursivelyCheckOptions(const Property &p) const
class to manage program options with xml serialization functionality
Definition property.h:55
base class for all analysis tools
Definition basebead.h:33