Chi-Tech
input_parameters.h
Go to the documentation of this file.
1#ifndef CHITECH_INPUT_PARAMETERS_H
2#define CHITECH_INPUT_PARAMETERS_H
3
4#include "parameter_block.h"
6
7#include <map>
8
9#define MakeInpParamsForObj(x, y) chi::InputParameters::MakeForObject<x>(y)
10
11namespace chi
12{
13
15{
16 NONE = 0,
17 OPTIONAL = 1,
18 REQUIRED = 2
19};
20
21/**Class for handling input parameters.*/
23{
24private:
25 /**String to represent class name. If not provided a default will be
26 * generated.*/
27 std::string class_name_;
28 /**Space separated list of group names.*/
29 std::string doc_group_;
30 std::map<std::string, InputParameterTag> parameter_class_tags_;
31 std::map<std::string, std::string> parameter_doc_string_;
32
33 std::map<std::string, std::string> deprecation_warning_tags_;
34 std::map<std::string, std::string> deprecation_error_tags_;
35 std::map<std::string, std::string> renamed_error_tags_;
36 std::map<std::string, bool> type_mismatch_allowed_tags_;
37 std::map<std::string, std::string> parameter_link_;
38
39 typedef std::unique_ptr<chi_data_types::AllowableRange> AllowableRangePtr;
40 std::map<std::string, AllowableRangePtr> constraint_tags_;
41
43
44 /**Parameter names to ignore when trying to assign. For now this
45 * "chi_obj_type"*/
46 static const std::vector<std::string> system_ignored_param_names_;
47
49
50public:
51 InputParameters() = default;
53 template <typename T>
55 {
56 auto input_param = T::GetInputParameters();
57
58 input_param.AssignParameters(params);
59 return input_param;
60 }
61
62public:
63 void SetObjectType(const std::string& obj_type);
64 std::string ObjectType() const;
65
66 /**Sets the class name to be applied to this object. If not used a
67 * default will be generated.*/
68 void SetClassName(const std::string& class_name) { class_name_ = class_name; }
69
70 /**Sets a general description of the object that should be included with
71 * the object's documentation.*/
72 void SetGeneralDescription(const std::string& description)
73 {
74 general_description_ = description;
75 }
76 std::string GetGeneralDescription() const { return general_description_; }
77
78 /**Space separated list of doxygen group names to which this documentation
79 * should belong.*/
80 void SetDocGroup(const std::string& doc_group) { doc_group_ = doc_group; }
81
82 /**Sets a link to the documentation of a different object.*/
83 void LinkParameterToBlock(const std::string& param_name,
84 const std::string& block_name);
85 /**Gets any linkage information of a parameter.*/
86 std::string
87 GetParameterDocumentationLink(const std::string& param_name) const;
88
89 std::string GetParameterDocString(const std::string& param_name);
90
91private:
93 static bool IsParameterIgnored(const std::string& param_name);
94
95public:
96 template <typename T>
97 void AddOptionalParameter(const std::string& name,
98 T value,
99 const std::string& doc_string)
100 {
101 AddParameter(name, value);
103 parameter_doc_string_[name] = doc_string;
104 }
105
106 void AddOptionalParameterBlock(const std::string& name,
107 const ParameterBlock& block,
108 const std::string& doc_string);
109
110 template <typename T>
111 void AddOptionalParameterArray(const std::string& name,
112 const std::vector<T>& array,
113 const std::string& doc_string)
114 {
115 AddParameter(name, array);
117 parameter_doc_string_[name] = doc_string;
118 }
119
120 void AddOptionalParameterArray(const std::string& name,
121 const std::vector<ParameterBlock>& array,
122 const std::string& doc_string);
123
124 template <typename T>
125 void AddRequiredParameter(const std::string& name,
126 const std::string& doc_string)
127 {
128 AddParameter(name, chi_data_types::Varying::DefaultValue<T>());
130 parameter_doc_string_[name] = doc_string;
131 }
132
133 void AddRequiredParameterBlock(const std::string& name,
134 const std::string& doc_string);
135
136 void AddRequiredParameterArray(const std::string& name,
137 const std::string& doc_string);
138
139 template <typename T>
140 void ChangeExistingParamToOptional(const std::string& name,
141 T value,
142 const std::string& doc_string = "")
143 {
144 auto& param = GetParam(name);
145 param = ParameterBlock(name, value);
147 if (not doc_string.empty()) parameter_doc_string_[name] = doc_string;
148 }
149
150 template <typename T>
151 void ChangeExistingParamToRequired(const std::string& name,
152 const std::string& doc_string = "")
153 {
154 auto& param = GetParam(name);
155 param = ParameterBlock(name, chi_data_types::Varying::DefaultValue<T>());
157 if (not doc_string.empty()) parameter_doc_string_[name] = doc_string;
158 }
159
160public:
161 /**\brief Assigns parameters with thorough type checks, deprecation checks,
162 * unused parameter checks.*/
163 void AssignParameters(const ParameterBlock& params);
164
165 /**Returns the raw parameter block used at assignment. This can be used
166 * to see if a user supplied an optional parameter or not.*/
168 {
170 }
171
172 void
173 MarkParamaterDeprecatedWarning(const std::string& param_name,
174 const std::string& deprecation_message = "");
175 void
176 MarkParamaterDeprecatedError(const std::string& param_name,
177 const std::string& deprecation_message = "");
178 void MarkParamaterRenamed(const std::string& param_name,
179 const std::string& renaming_description);
180 void ConstrainParameterRange(const std::string& param_name,
181 AllowableRangePtr allowable_range);
182 /**\brief Sets a tag for the given parameter that will allow its type to be
183 * mismatched upon assignment.*/
184 void SetParameterTypeMismatchAllowed(const std::string& param_name);
185
186 /**Dumps the input parameters to stdout.*/
187 void DumpParameters() const;
188};
189
190} // namespace chi
191
192#endif // CHITECH_INPUT_PARAMETERS_H
std::string GetParameterDocString(const std::string &param_name)
void AssignParameters(const ParameterBlock &params)
Assigns parameters with thorough type checks, deprecation checks, unused parameter checks.
void SetDocGroup(const std::string &doc_group)
void AddRequiredParameter(const std::string &name, const std::string &doc_string)
ParameterBlock param_block_at_assignment_
std::string general_description_
std::map< std::string, InputParameterTag > parameter_class_tags_
std::map< std::string, std::string > deprecation_error_tags_
void SetParameterTypeMismatchAllowed(const std::string &param_name)
Sets a tag for the given parameter that will allow its type to be mismatched upon assignment.
std::map< std::string, std::string > deprecation_warning_tags_
void AddRequiredParameterArray(const std::string &name, const std::string &doc_string)
const ParameterBlock & ParametersAtAssignment() const
std::map< std::string, std::string > parameter_doc_string_
void AddParameter(ParameterBlock block)
void SetObjectType(const std::string &obj_type)
void MarkParamaterRenamed(const std::string &param_name, const std::string &renaming_description)
std::string GetParameterDocumentationLink(const std::string &param_name) const
void AddRequiredParameterBlock(const std::string &name, const std::string &doc_string)
InputParameters & operator+=(InputParameters other)
void ConstrainParameterRange(const std::string &param_name, AllowableRangePtr allowable_range)
std::map< std::string, AllowableRangePtr > constraint_tags_
InputParameters()=default
static bool IsParameterIgnored(const std::string &param_name)
std::string ObjectType() const
std::map< std::string, std::string > renamed_error_tags_
std::map< std::string, bool > type_mismatch_allowed_tags_
void AddOptionalParameter(const std::string &name, T value, const std::string &doc_string)
static InputParameters MakeForObject(const ParameterBlock &params)
void AddOptionalParameterBlock(const std::string &name, const ParameterBlock &block, const std::string &doc_string)
std::map< std::string, std::string > parameter_link_
std::unique_ptr< chi_data_types::AllowableRange > AllowableRangePtr
void ChangeExistingParamToRequired(const std::string &name, const std::string &doc_string="")
std::string GetGeneralDescription() const
void SetGeneralDescription(const std::string &description)
void LinkParameterToBlock(const std::string &param_name, const std::string &block_name)
void SetClassName(const std::string &class_name)
static const std::vector< std::string > system_ignored_param_names_
void AddOptionalParameterArray(const std::string &name, const std::vector< T > &array, const std::string &doc_string)
void MarkParamaterDeprecatedError(const std::string &param_name, const std::string &deprecation_message="")
void MarkParamaterDeprecatedWarning(const std::string &param_name, const std::string &deprecation_message="")
void ChangeExistingParamToOptional(const std::string &name, T value, const std::string &doc_string="")
void AddParameter(ParameterBlock block)
ParameterBlock(const std::string &name="")
ParameterBlock & GetParam(const std::string &param_name)
InputParameterTag