if (boost::get<boost::blank>(&v)) {
return -ENOENT;
}
- if (const bool *flag = boost::get<const bool>(&v)) {
- *out = *flag ? "true" : "false";
- return 0;
- }
- ostringstream oss;
- if (const double *dp = boost::get<const double>(&v)) {
- oss << std::fixed << *dp;
- } else {
- oss << v;
- }
- *out = oss.str();
+ *out = Option::to_str(v);
return 0;
}
if (j != values.end()) {
auto k = j->second.find(CONF_DEFAULT);
if (k != j->second.end()) {
- encode(stringify(k->second), bl);
+ encode(Option::to_str(k->second), bl);
continue;
}
}
encode((uint32_t)i.second.size(), bl);
for (auto& j : i.second) {
encode(j.first, bl);
- encode(stringify(j.second), bl);
+ encode(Option::to_str(j.second), bl);
}
}
// make sure overridden items appear, and include the default value
int Option::parse_value(
const std::string& raw_val,
value_t *out,
- std::string *error_message) const
+ std::string *error_message,
+ std::string *normalized_value) const
{
std::string val = raw_val;
if (!error_message->empty()) {
return -EINVAL;
}
- *out = !!b;
+ *out = (bool)!!b;
}
} else if (type == Option::TYPE_ADDR) {
entity_addr_t addr;
return r;
}
+ if (normalized_value) {
+ *normalized_value = to_str(*out);
+ }
return 0;
}
f->dump_bool("can_update_at_runtime", can_update_at_runtime());
}
-ostream& operator<<(ostream& out, const Option::value_t& v)
+std::string Option::to_str(const Option::value_t& v)
{
if (boost::get<boost::blank>(&v)) {
- return out;
+ return string();
}
if (const bool *flag = boost::get<const bool>(&v)) {
- return out << (*flag ? "true" : "false");
+ return *flag ? "true" : "false";
}
if (const double *dp = boost::get<const double>(&v)) {
ostringstream oss;
oss << std::fixed << *dp;
- return out << oss.str();
- }
- if (const uint64_t *i = boost::get<const uint64_t>(&v)) {
- return out << *i;
- }
- if (const int64_t *i = boost::get<const int64_t>(&v)) {
- return out << *i;
- }
- if (const std::string *i = boost::get<const std::string>(&v)) {
- return out << *i;
- }
- if (const uuid_d *i = boost::get<const uuid_d>(&v)) {
- return out << *i;
- }
- if (const entity_addr_t *i = boost::get<const entity_addr_t>(&v)) {
- return out << *i;
+ return oss.str();
}
- ceph_abort();
+ return stringify(v);
}
void Option::print(ostream *out) const
value_t value;
value_t daemon_value;
- friend ostream& operator<<(ostream&, const value_t& v);
+ static std::string to_str(const value_t& v);
// Items like mon, osd, rgw, rbd, ceph-fuse. This is advisory metadata
// for presentation layers (like web dashboards, or generated docs), so that
int parse_value(
const std::string& raw_val,
value_t *out,
- std::string *error_message) const;
+ std::string *error_message,
+ std::string *normalized_value=nullptr) const;
template<typename T>
Option& set_default(const T& v) {
}
Option::value_t real_value;
- string str;
- err = opt->parse_value(value, &real_value, &str);
+ string errstr;
+ err = opt->parse_value(value, &real_value, &errstr, &value);
if (err < 0) {
- ss << "error parsing value: " << str;
+ ss << "error parsing value: " << errstr;
goto reply;
}
- value = stringify(real_value);
}
string section;