taco-db  0.1.0
numbers.h
Go to the documentation of this file.
1 #ifndef UTILS_NUMBERS_H
2 #define UTILS_NUMBERS_H
3 
4 #include <limits>
5 #include <type_traits>
6 #include <cstdint>
7 
8 #include <absl/strings/numbers.h>
9 #include <absl/strings/string_view.h>
10 
11 namespace taco {
12 
13 namespace utils_numbers_impl {
14 
15 template<class IntType, class = void>
17  static inline bool call(absl::string_view str, IntType *out) {
18  return absl::SimpleAtoi(str, out);
19  }
20 };
21 
22 template<class IntType>
23 struct SimpleAtoiWrapperImpl<IntType,
24  typename std::enable_if<sizeof(IntType) <= 2>::type> {
25 
26  // keep in sync with the signed-ness check in absl
27  typedef typename std::conditional<
28  (IntType)(1) - (IntType)(2) < 0,
29  std::int32_t,
30  std::uint32_t>::type int32;
31 
32  static inline bool call(absl::string_view str, IntType *out) {
33  int32 int32_out;
34  if (!absl::SimpleAtoi(str, &int32_out)) {
35  return false;
36  }
37 
38  if (int32_out < std::numeric_limits<IntType>::min())
39  return false;
40  if (int32_out > std::numeric_limits<IntType>::max())
41  return false;
42  *out = (IntType) int32_out;
43  return true;
44  }
45 };
46 
47 } // namespace utils_numbers_impl
48 
52 template<class IntType>
53 inline bool SimpleAtoiWrapper(absl::string_view str, IntType *out) {
55 }
56 
57 
58 } // namespace taco
59 
60 #endif // UTILS_NUMBERS_H
Definition: Record.h:148
Definition: datum.h:28
bool SimpleAtoiWrapper(absl::string_view str, IntType *out)
A wrapper version of absl::SimpleAtoi that supports 1/2/4/8-byte integers.
Definition: numbers.h:53
static bool call(absl::string_view str, IntType *out)
Definition: numbers.h:17