if (i == obj.end()) {
return false;
}
- *val = i->second;
+ *val = i->second.val();
return true;
}
-string JSONFormattable::get(const string& name, const string& def_val) const
-{
- string s;
- if (find(name, &s)) {
- return s;
+int JSONFormattable::val_int() const {
+ return atoi(str.c_str());
+}
+
+bool JSONFormattable::val_bool() const {
+ return (boost::iequals(str, "true") ||
+ boost::iequals(str, "on") ||
+ boost::iequals(str, "yes") ||
+ boost::iequals(str, "1"));
+}
+
+string JSONFormattable::def(const string& def_val) const {
+ if (type == FMT_NONE) {
+ return def_val;
}
+ return val();
+}
- return def_val;
+int JSONFormattable::def(int def_val) const {
+ if (type == FMT_NONE) {
+ return def_val;
+ }
+ return val_int();
}
-int JSONFormattable::get_int(const string& name, int def_val) const
-{
- string s;
- if (find(name, &s)) {
- return atoi(s.c_str());
+bool JSONFormattable::def(bool def_val) const {
+ if (type == FMT_NONE) {
+ return def_val;
}
+ return val_bool();
+}
- return def_val;
+string JSONFormattable::get(const string& name, const string& def_val) const
+{
+ return (*this)[name].def(def_val);
}
-bool JSONFormattable::get_bool(const string& name, bool def_val) const
+int JSONFormattable::get_int(const string& name, int def_val) const
{
- string s;
- if (find(name, &s)) {
- return (boost::iequals(s, "true") ||
- boost::iequals(s, "on") ||
- boost::iequals(s, "yes") ||
- boost::iequals(s, "1"));
- }
+ return (*this)[name].def(def_val);
+}
- return def_val;
+bool JSONFormattable::get_bool(const string& name, bool def_val) const
+{
+ return (*this)[name].def(def_val);
}
void encode_json(const char *name, const JSONFormattable& v, Formatter *f)
FMT_ARRAY,
FMT_OBJ,
} type{FMT_NONE};
- string str;
+ std::string str;
vector<JSONFormattable> arr;
- map<string, JSONFormattable> obj;
+ map<std::string, JSONFormattable> obj;
void decode_json(JSONObj *jo) {
if (jo->is_array()) {
decode(obj, bl);
DECODE_FINISH(bl);
}
- const string& val() const {
+ const std::string& val() const {
return str;
}
+ int val_int() const;
+ bool val_bool() const;
+
const vector<JSONFormattable>& array() const {
return arr;
}
- const JSONFormattable& operator[](const string& name) const;
+ const JSONFormattable& operator[](const std::string& name) const;
+ const JSONFormattable& operator[](const char * name) const {
+ return this->operator[](std::string(name));
+ }
- operator string() const {
- return val();
+ string operator ()(const char *def_val) const {
+ return def(string(def_val));
}
- bool find(const string& name, string *val) const;
+ string operator ()(const string& def_val) const {
+ return def(def_val);
+ }
+
+ int operator()(int def_val) const {
+ return def(def_val);
+ }
+
+ bool operator()(bool def_val) const {
+ return def(def_val);
+ }
+
+ std::string def(const std::string& def_val) const;
+ int def(int def_val) const;
+ bool def(bool def_val) const;
+
+ bool find(const std::string& name, std::string *val) const;
- string get(const string& name, const string& def_val) const;
- int get_int(const string& name, int def_val) const;
- bool get_bool(const string& name, bool def_val) const;
+ std::string get(const std::string& name, const std::string& def_val) const;
+ int get_int(const std::string& name, int def_val) const;
+ bool get_bool(const std::string& name, bool def_val) const;
};
WRITE_CLASS_ENCODER(JSONFormattable)
int RGWAWSSyncModule::create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance){
AWSSyncConfig conf;
- conf.s3_endpoint = config["s3_endpoint"];
+ conf.s3_endpoint = config["s3_endpoint"]("");
- string access_key = config["access_key"];
- string secret = config["secret"];
+ string access_key = config["access_key"]("");
+ string secret = config["secret"]("");
conf.key = RGWAccessKey(access_key, secret);
}
int RGWElasticSyncModule::create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) {
- string endpoint = config["endpoint"];
+ string endpoint = config["endpoint"]("");
instance->reset(new RGWElasticSyncModuleInstance(cct, config));
return 0;
}
};
int RGWLogSyncModule::create_instance(CephContext *cct, const JSONFormattable& config, RGWSyncModuleInstanceRef *instance) {
- string prefix = config["prefix"];
+ string prefix = config["prefix"]("");
instance->reset(new RGWLogSyncModuleInstance(prefix));
return 0;
}