extract.h
Go to the documentation of this file.
1 #ifndef cetlib_sqlite_detail_extract_h
2 #define cetlib_sqlite_detail_extract_h
3 
4 // =================================================================
5 //
6 // For extraction operations, the following conversions are supported:
7 //
8 // .. std::string ==> std::string
9 //
10 // (as specializations)
11 //
12 // .. std::string ==> int
13 // .. std::string ==> long
14 // .. std::string ==> long long
15 // .. std::string ==> unsigned
16 // .. std::string ==> unsigned long
17 // .. std::string ==> unsigned long long
18 // .. std::string ==> float
19 // .. std::string ==> double
20 // .. std::string ==> long double
21 //
22 // =================================================================
23 
24 #include <string>
25 
26 namespace cet::sqlite {
27  namespace detail {
28 
29  template <typename T>
30  inline auto
31  convertTo(std::string const& arg)
32  {
33  return arg;
34  }
35 
36  template <>
37  inline auto
38  convertTo<int>(std::string const& arg)
39  {
40  return std::stoi(arg);
41  }
42  template <>
43  inline auto
44  convertTo<long>(std::string const& arg)
45  {
46  return std::stol(arg);
47  }
48  template <>
49  inline auto
51  {
52  return std::stoll(arg);
53  }
54  template <>
55  inline auto
57  {
58  return std::stoul(arg);
59  }
60  template <>
61  inline auto
63  {
64  return std::stoul(arg);
65  }
66  template <>
67  inline auto
69  {
70  return std::stoull(arg);
71  }
72  template <>
73  inline auto
74  convertTo<float>(std::string const& arg)
75  {
76  return std::stof(arg);
77  }
78  template <>
79  inline auto
80  convertTo<double>(std::string const& arg)
81  {
82  return std::stod(arg);
83  }
84  template <>
85  inline auto
87  {
88  return std::stold(arg);
89  }
90 
91  } // detail
92 } // cet::sqlite
93 
94 #endif /* cetlib_sqlite_detail_extract_h */
95 
96 // Local Variables:
97 // mode: c++
98 // End:
auto convertTo< long double >(std::string const &arg)
Definition: convert.h:85
auto convertTo< int >(std::string const &arg)
Definition: convert.h:37
auto convertTo< unsigned long long >(std::string const &arg)
Definition: convert.h:67
std::string string
Definition: nybbler.cc:12
auto convertTo< unsigned long >(std::string const &arg)
Definition: convert.h:61
auto convertTo(std::string const &arg)
Definition: convert.h:30
auto convertTo< long >(std::string const &arg)
Definition: convert.h:43
auto convertTo< long long >(std::string const &arg)
Definition: convert.h:49
auto convertTo< double >(std::string const &arg)
Definition: convert.h:79
auto convertTo< float >(std::string const &arg)
Definition: convert.h:73
auto convertTo< unsigned >(std::string const &arg)
Definition: convert.h:55