get_result.h
Go to the documentation of this file.
1 #ifndef cetlib_sqlite_detail_get_result_h
2 #define cetlib_sqlite_detail_get_result_h
3 
6 
7 #include <cassert>
8 #include <tuple>
9 
10 namespace cet {
11  namespace sqlite {
12  namespace detail {
13 
14  template <std::size_t I, typename Tuple>
16  fillData(Tuple&,
17  int const ncols [[gnu::unused]],
18  int const currentcol [[gnu::unused]],
19  char**)
20  {
21  assert(currentcol == ncols);
22  }
23 
24  template <std::size_t I, typename Tuple>
26  fillData(Tuple& data, int const ncols, int currentcol, char** results)
27  {
28  assert(currentcol != ncols);
29  using ET = std::tuple_element_t<I, Tuple>;
30  std::get<I>(data) = detail::convertTo<ET>(results[currentcol]);
31  fillData<I + 1>(data, ncols, ++currentcol, results);
32  }
33 
34  template <typename... Args>
35  int
36  get_result(void* data, int ncols, char** results, char** cnames)
37  {
38  assert(ncols >= 1);
39  auto j = static_cast<cet::sqlite::query_result<Args...>*>(data);
40  if (j->columns.empty()) {
41  for (int i{}; i < ncols; ++i)
42  j->columns.push_back(cnames[i]);
43  }
44 
45  assert(sizeof...(Args) == ncols);
46  std::tuple<Args...> rowdata;
47  int currentCol{};
48  fillData<0u>(rowdata, ncols, currentCol, results);
49  j->data.emplace_back(rowdata);
50  return 0;
51  }
52 
53  } // detail
54  } // sqlite
55 } // cet
56 
57 #endif /* cetlib_sqlite_detail_get_result_h */
58 
59 // Local variables:
60 // mode: c++
61 // End:
std::enable_if_t<(I==std::tuple_size< Tuple >::value)> fillData(Tuple &, int const ncols[[gnu::unused]], int const currentcol[[gnu::unused]], char **)
Definition: get_result.h:16
const XML_Char const XML_Char * data
Definition: expat.h:268
const XML_Char int const XML_Char * value
Definition: expat.h:331
const double j
Definition: BetheBloch.cxx:29
int get_result(void *data, int ncols, char **results, char **cnames)
Definition: get_result.h:36
assert(nhit_max >=nhit_nbins)
Int_t ncols
Definition: plot.C:53