8 #ifndef UFO_UTILS_PARAMETERS_PARAMETERTRAITSVARIABLE_H_
9 #define UFO_UTILS_PARAMETERS_PARAMETERTRAITSVARIABLE_H_
14 #include "eckit/exception/Exceptions.h"
15 #include "oops/util/CompositePath.h"
16 #include "oops/util/parameters/ParameterTraits.h"
17 #include "oops/util/stringFunctions.h"
27 struct ParameterTraits<
ufo::Variable> {
28 static boost::optional<ufo::Variable>
get(util::CompositePath &path,
29 const eckit::Configuration &config,
30 const std::string& name) {
31 if (config.has(name)) {
32 eckit::LocalConfiguration varConf(config, name);
33 if (!varConf.has(
"name")) {
36 throw eckit::BadParameter(path.path() +
": No variable name specified", Here());
44 static void set(eckit::LocalConfiguration &config,
45 const std::string &name,
47 eckit::LocalConfiguration subConfig;
48 subConfig.set(
"name", value.
variable() +
"@" + value.
group());
49 const std::vector<int> &channels = value.
channels();
50 if (!channels.empty()) {
51 const std::string channelsAsString = util::stringfunctions::join(
52 ",", channels.begin(), channels.end(), [](
int n) { return std::to_string(n); });
53 subConfig.set(
"channels", channelsAsString);
55 if (!value.
options().keys().empty())
56 subConfig.set(
"options", value.
options());
57 config.set(name, subConfig);
60 static ObjectJsonSchema
jsonSchema(
const std::string &name) {
61 ObjectJsonSchema nestedSchema({{
"name", {{
"type",
"\"string\""}}},
62 {
"options", {{
"type",
"\"object\""}}},
63 {
"channels", {{
"type",
"[\"string\", \"integer\"]"}}}});
64 return ObjectJsonSchema({{name, nestedSchema.toPropertyJsonSchema()}});
70 #endif // UFO_UTILS_PARAMETERS_PARAMETERTRAITSVARIABLE_H_