Construct code for auto config file for one param value. Parameters ---------- name : string Name of the parameter. param_type : string Type of the parameter. checks : list Constraints of the parameter. Returns ------- ret : string Li
(name, param_type, checks)
| 121 | |
| 122 | |
| 123 | def set_one_var_from_string(name, param_type, checks): |
| 124 | """Construct code for auto config file for one param value. |
| 125 | |
| 126 | Parameters |
| 127 | ---------- |
| 128 | name : string |
| 129 | Name of the parameter. |
| 130 | param_type : string |
| 131 | Type of the parameter. |
| 132 | checks : list |
| 133 | Constraints of the parameter. |
| 134 | |
| 135 | Returns |
| 136 | ------- |
| 137 | ret : string |
| 138 | Lines of auto config file with getting and checks of one parameter value. |
| 139 | """ |
| 140 | ret = "" |
| 141 | univar_mapper = {"int": "GetInt", "double": "GetDouble", "bool": "GetBool", "std::string": "GetString"} |
| 142 | if "vector" not in param_type: |
| 143 | ret += " %s(params, \"%s\", &%s);\n" % (univar_mapper[param_type], name, name) |
| 144 | if len(checks) > 0: |
| 145 | for check in checks: |
| 146 | ret += " CHECK(%s %s);\n" % (name, check) |
| 147 | ret += "\n" |
| 148 | else: |
| 149 | ret += " if (GetString(params, \"%s\", &tmp_str)) {\n" % (name) |
| 150 | type2 = param_type.split("<")[1][:-1] |
| 151 | if type2 == "std::string": |
| 152 | ret += " %s = Common::Split(tmp_str.c_str(), ',');\n" % (name) |
| 153 | else: |
| 154 | ret += " %s = Common::StringToArray<%s>(tmp_str, ',');\n" % (name, type2) |
| 155 | ret += " }\n\n" |
| 156 | return ret |
| 157 | |
| 158 | |
| 159 | def gen_parameter_description(sections, descriptions, params_rst): |
no outgoing calls
no test coverage detected