convert.h
Go to the documentation of this file.
1 #ifndef cetlib_sqlite_detail_convert_h
2 #define cetlib_sqlite_detail_convert_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::detail {
27 
28  template <typename T>
29  inline auto
30  convertTo(std::string const& arg)
31  {
32  return arg;
33  }
34 
35  template <>
36  inline auto
38  {
39  return std::stoi(arg);
40  }
41  template <>
42  inline auto
44  {
45  return std::stol(arg);
46  }
47  template <>
48  inline auto
50  {
51  return std::stoll(arg);
52  }
53  template <>
54  inline auto
56  {
57  return std::stoul(arg);
58  }
59  template <>
60  inline auto
62  {
63  return std::stoul(arg);
64  }
65  template <>
66  inline auto
68  {
69  return std::stoull(arg);
70  }
71  template <>
72  inline auto
74  {
75  return std::stof(arg);
76  }
77  template <>
78  inline auto
80  {
81  return std::stod(arg);
82  }
83  template <>
84  inline auto
86  {
87  return std::stold(arg);
88  }
89 
90 } // cet::sqlite::detail
91 
92 #endif /* cetlib_sqlite_detail_convert_h */
93 
94 // Local Variables:
95 // mode: c++
96 // 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