MCPcopy Create free account
hub / github.com/ceph/ceph / validate

Method validate

src/common/options.cc:100–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98}
99
100int Option::validate(const Option::value_t &new_value, std::string *err) const
101{
102 // Generic validation: min
103 if (min != value_t{}) {
104 if (new_value < min) {
105 std::ostringstream oss;
106 oss << "Value '" << new_value << "' is below minimum " << min;
107 *err = oss.str();
108 return -EINVAL;
109 }
110 }
111
112 // Generic validation: max
113 if (max != value_t{}) {
114 if (new_value > max) {
115 std::ostringstream oss;
116 oss << "Value '" << new_value << "' exceeds maximum " << max;
117 *err = oss.str();
118 return -EINVAL;
119 }
120 }
121
122 // Generic validation: enum
123 if (!enum_allowed.empty() && type == Option::TYPE_STR) {
124 auto found = std::find(enum_allowed.begin(), enum_allowed.end(),
125 std::get<std::string>(new_value));
126 if (found == enum_allowed.end()) {
127 std::ostringstream oss;
128 oss << "'" << new_value << "' is not one of the permitted "
129 "values: " << joinify(enum_allowed.begin(),
130 enum_allowed.end(),
131 std::string(", "));
132 *err = oss.str();
133 return -EINVAL;
134 }
135 }
136
137 return 0;
138}
139
140int Option::parse_value(
141 const std::string& raw_val,

Callers

nothing calls this directly

Calls 6

findFunction · 0.85
joinifyFunction · 0.85
strMethod · 0.45
emptyMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected