// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
-// vim: ts=8 sw=2 smarttab
+// vim: ts=8 sw=2 smarttab ft=cpp
#ifndef CEPH_RGW_XML_H
#define CEPH_RGW_XML_H
#include <map>
+#include <stdexcept>
#include <string>
#include <iosfwd>
#include <include/types.h>
};
namespace RGWXMLDecoder {
- struct err {
- std::string message;
-
- explicit err(const std::string& m) : message(m) {}
+ struct err : std::runtime_error {
+ using runtime_error::runtime_error;
};
typedef RGWXMLParser XMLParser;
static inline ostream& operator<<(ostream &out, RGWXMLDecoder::err& err)
{
- return out << err.message;
+ return out << err.what();
}
template<class T>
class utime_t;
void decode_xml_obj(utime_t& val, XMLObj *obj);
+template<class T>
+void decode_xml_obj(std::optional<T>& val, XMLObj *obj)
+{
+ val.emplace();
+ decode_xml_obj(*val, obj);
+}
+
template<class T>
void do_decode_xml_obj(list<T>& l, const string& name, XMLObj *obj)
{
try {
decode_xml_obj(val, o);
- } catch (err& e) {
+ } catch (const err& e) {
string s = string(name) + ": ";
- s.append(e.message);
+ s.append(e.what());
throw err(s);
}
T val;
try {
decode_xml_obj(val, o);
- } catch (err& e) {
+ } catch (const err& e) {
string s = string(name) + ": ";
- s.append(e.message);
+ s.append(e.what());
throw err(s);
}
v.push_back(val);
try {
decode_xml_obj(container, cb, o);
- } catch (err& e) {
+ } catch (const err& e) {
string s = string(name) + ": ";
- s.append(e.message);
+ s.append(e.what());
throw err(s);
}
try {
decode_xml_obj(val, o);
- } catch (err& e) {
+ } catch (const err& e) {
val = default_val;
string s = string(name) + ": ";
- s.append(e.message);
+ s.append(e.what());
throw err(s);
}
}
f->close_section();
}
+template<class T>
+static void encode_xml(const char *name, const std::vector<T>& l, ceph::Formatter *f)
+{
+ for (typename std::vector<T>::const_iterator iter = l.begin(); iter != l.end(); ++iter) {
+ encode_xml(name, *iter, f);
+ }
+}
+
+template<class T>
+static void encode_xml(const char *name, const std::optional<T>& o, ceph::Formatter *f)
+{
+ if (!o) {
+ return;
+ }
+
+ encode_xml(name, *o, f);
+}
#endif