8 #ifndef INCLUDE_INFINISPAN_HOTROD_QUERYUTILS_H_
9 #define INCLUDE_INFINISPAN_HOTROD_QUERYUTILS_H_
13 using namespace org::infinispan::protostream;
15 template <
class T>
bool unwrapResults(QueryResponse resp, std::vector<T> &res)
17 if (resp.projectionsize()>0)
21 for (
int i=0; i<resp.results_size(); i++)
23 const WrappedMessage &wm =resp.results(i);
24 if ( wm.has_wrappedbytes() )
27 wmn.ParseFromString(wm.wrappedbytes());
28 if (wmn.has_wrappedmessagebytes()) {
30 u1.ParseFromString(wmn.wrappedmessagebytes());
40 template <> std::string unwrapSingleValue<std::string>(
const WrappedMessage& wm)
42 if (wm.has_wrappedstring())
44 return wm.wrappedstring();
48 throw "std::string not found in response";
54 if (wm.has_wrappedint32())
56 return wm.wrappedint32();
58 else if (wm.has_wrappedint64())
60 return wm.wrappedint64();
64 throw "std::string not found in response";
70 return unwrapSingleValue<T>(qr.results(0));
74 #if !defined (_MSC_VER) || (_MSC_VER>=1800)
75 template <
typename H,
typename... Params> std::tuple<H, Params...>
popTuple(QueryResponse &resp,
int &k)
77 H s = unwrapSingleValue<H>(resp.results(k++));
78 std::tuple<Params...> p=
popTuple<Params... >(resp,k);
79 return std::tuple_cat(std::tie(s),p);
83 std::tuple<std::string> popTuple<std::string>(QueryResponse & resp,
int &k)
85 std::string s(unwrapSingleValue<std::string>(resp.results(k++)));
86 return std::make_tuple<std::string>(std::move(s));
93 return std::make_tuple<int>(std::move(s));
97 template<
typename... Params>
bool unwrapProjection(QueryResponse &resp, std::vector<std::tuple<Params...> > &prjRes)
99 if (resp.projectionsize() == 0) {
102 int numTuple = resp.results_size() / resp.projectionsize();
104 for (
int i = 0; i < numTuple; i++) {
105 std::tuple<Params...> tp=
popTuple<Params...>(resp, k) ;
106 prjRes.push_back(tp);
bool unwrapProjection(QueryResponse &resp, std::vector< std::tuple< Params...> > &prjRes)
Definition: QueryUtils.h:97
T unwrapSingleValue(const WrappedMessage &wm)
int unwrapSingleValue< int >(const WrappedMessage &wm)
Definition: QueryUtils.h:52
bool unwrapResults(QueryResponse resp, std::vector< T > &res)
Definition: QueryUtils.h:15
std::tuple< int > popTuple< int >(QueryResponse &resp, int &k)
Definition: QueryUtils.h:90
T unwrapSingleResult(const QueryResponse &qr)
Definition: QueryUtils.h:68
std::tuple< H, Params...> popTuple(QueryResponse &resp, int &k)
Definition: QueryUtils.h:75