23 #ifndef _LIBS_WEBVIEW_REST_ARRAY_H_
24 #define _LIBS_WEBVIEW_REST_ARRAY_H_
26 #include <boost/property_tree/json_parser.hpp>
27 #include <boost/property_tree/ptree.hpp>
63 std::string rv =
"[\n";
64 for (
size_t i = 0; i < items_.size(); ++i) {
65 rv += items_[i].to_json(pretty);
66 if (i < items_.size() - 1) {
82 std::stringstream ss(json);
83 boost::property_tree::ptree pt;
84 boost::property_tree::read_json(ss, pt);
85 for (
auto &c : pt.get_child(
"")) {
87 boost::property_tree::write_json(os, c.second);
89 m.from_json(os.str());
90 items_.push_back(std::move(m));
105 for (
const auto &i : items_) {
134 items_.push_back(std::move(m));
138 std::vector<M> items_;
Container to return array via REST.
void from_json(const std::string &json)
Retrieve data from JSON string.
void push_back(M &m)
Add item at the back of the container.
void validate(bool subcall=false)
Validate if all required fields have been set.
WebviewRestArray(std::vector< M > &items)
Constructor.
WebviewRestArray(std::vector< M > &&items)
Constructor.
WebviewRestArray()
Empty array constructor.
void push_back(M &&m)
Add item at the back of the container.
std::string to_json(bool pretty=false) const
Render object to JSON.
std::vector< M > & items()
Accessor for items.