8 #ifndef INCLUDE_INFINISPAN_HOTROD_QUERYUTILS_H_ 9 #define INCLUDE_INFINISPAN_HOTROD_QUERYUTILS_H_ 19 template <
class T>
bool unwrapResults(QueryResponse resp, std::vector<T> &res)
21 if (resp.projectionsize()>0)
25 for (
int i=0; i<resp.results_size(); i++)
27 const WrappedMessage &wm =resp.results(i);
28 if ( wm.has_wrappedbytes() )
31 wmn.ParseFromString(wm.wrappedbytes());
32 if (wmn.has_wrappedmessagebytes()) {
34 u1.ParseFromString(wmn.wrappedmessagebytes());
45 template <>
inline std::string unwrapSingleValue<std::string>(
const WrappedMessage& wm)
47 if (wm.has_wrappedstring())
49 return wm.wrappedstring();
53 throw "std::string type not found in response";
57 template <>
inline int unwrapSingleValue<int>(
const WrappedMessage& wm)
59 if (wm.has_wrappedint32())
61 return wm.wrappedint32();
63 else if (wm.has_wrappedint64())
65 return wm.wrappedint64();
69 throw "int type not found in response";
73 template <>
inline double unwrapSingleValue<double>(
const WrappedMessage& wm)
75 if (wm.has_wrappeddouble())
77 return wm.wrappeddouble();
81 throw "double type not found in response";
87 return unwrapSingleValue<T>(qr.results(0));
91 #if !defined (_MSC_VER) || (_MSC_VER>=1800) 94 template <
typename H,
typename... Params> std::tuple<H, Params...>
popTuple(
const RepeatedPtrField<WrappedMessage >& wMsgs,
int &k)
96 H s = unwrapSingleValue<H>(wMsgs.Get(k++));
97 std::tuple<Params...> p =
popTuple<Params... >(wMsgs,k);
98 return std::tuple_cat(std::tie(s),p);
102 inline std::tuple<int> popTuple<int>(
const RepeatedPtrField<WrappedMessage >& wMsgs,
int &k)
104 int s(unwrapSingleValue<int>(wMsgs.Get(k++)));
105 return std::make_tuple<int>(std::move(s));
109 inline std::tuple<std::string> popTuple<std::string>(
const RepeatedPtrField<WrappedMessage >& wMsgs,
int &k)
111 std::string s(unwrapSingleValue<std::string>(wMsgs.Get(k++)));
112 return std::make_tuple<std::string>(std::move(s));
116 template <
typename H,
typename... Params> std::tuple<H, Params...>
popTuple(QueryResponse &resp,
int &k)
118 H s = unwrapSingleValue<H>(resp.results(k++));
119 std::tuple<Params...> p=
popTuple<Params... >(resp,k);
120 return std::tuple_cat(std::tie(s),p);
124 inline std::tuple<std::string> popTuple<std::string>(QueryResponse& resp,
int &k)
126 std::string s(unwrapSingleValue<std::string>(resp.results(k++)));
127 return std::make_tuple<std::string>(std::move(s));
131 inline std::tuple<int> popTuple<int>(QueryResponse & resp,
int &k)
133 int s(unwrapSingleValue<int>(resp.results(k++)));
134 return std::make_tuple<int>(std::move(s));
138 inline std::tuple<double> popTuple<double>(QueryResponse & resp,
int &k)
140 int s(unwrapSingleValue<double>(resp.results(k++)));
141 return std::make_tuple<double>(std::move(s));
145 template<
typename... Params>
bool unwrapProjection(QueryResponse &resp, std::vector<std::tuple<Params...> > &prjRes)
147 if (resp.projectionsize() == 0) {
150 int numTuple = resp.results_size() / resp.projectionsize();
152 for (
int i = 0; i < numTuple; i++) {
153 std::tuple<Params...> tp=
popTuple<Params...>(resp, k) ;
154 prjRes.push_back(tp);
T unwrapSingleValue(const WrappedMessage &wm)
bool unwrapProjection(QueryResponse &resp, std::vector< std::tuple< Params... > > &prjRes)
Definition: QueryUtils.h:145
bool unwrapResults(QueryResponse resp, std::vector< T > &res)
Definition: QueryUtils.h:19
std::tuple< H, Params... > popTuple(const RepeatedPtrField< WrappedMessage > &wMsgs, int &k)
Definition: QueryUtils.h:94
T unwrapSingleResult(const QueryResponse &qr)
Definition: QueryUtils.h:85