2 #include <boost/foreach.hpp>
3 #include <boost/property_tree/ptree.hpp>
4 #include <glog/logging.h>
5 #include <hpda/processor/processor_base.h>
11 template <
typename OutputObjType>
15 typedef std::function<
const boost::property_tree::ptree &(
16 const boost::property_tree::ptree &)>
18 typedef std::function<OutputObjType(
const std::string &item)>
23 const data_item_picker_t &data_item_picker,
24 const item_transformer_t &item_transformer)
26 m_func(data_item_picker), m_item_transformer(item_transformer),
27 m_next_data_index(0) {}
32 virtual bool process() {
34 if (m_next_data_index >= m_all_data.size()) {
36 base::consume_input_value();
43 virtual OutputObjType output_value() {
return m_all_data[m_next_data_index]; }
47 m_next_data_index = 0;
49 if (!base::has_input_value()) {
53 std::string v = base::input_value();
56 boost::property_tree::ptree tree;
57 boost::property_tree::read_json(ss, tree);
58 auto child = m_func(tree);
59 BOOST_FOREACH (boost::property_tree::ptree::value_type &v, child) {
60 assert(v.first.empty());
62 m_all_data.push_back(m_item_transformer(v.second.data()));
63 }
catch (std::exception &e) {
70 }
catch (std::exception &e) {
71 LOG(INFO) <<
"parse_data got exception: " << e.what();
77 std::vector<OutputObjType> m_all_data;
78 int m_next_data_index;
79 data_item_picker_t m_func;
80 item_transformer_t m_item_transformer;
83 template <
typename... ARGS>