unsigned-types.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2010 Maciej Sobczak
3 // Distributed under the Boost Software License, Version 1.0.
4 // (See accompanying file LICENSE_1_0.txt or copy at
5 // http://www.boost.org/LICENSE_1_0.txt)
6 //
7 
8 #ifndef SOCI_UNSIGNED_TYPES_H_INCLUDED
9 #define SOCI_UNSIGNED_TYPES_H_INCLUDED
10 
11 #include "type-conversion-traits.h"
12 #include <limits>
13 
14 namespace soci
15 {
16 
17 // simple fall-back for unsigned types
18 
19 template <>
20 struct type_conversion<unsigned char>
21 {
22  typedef long long base_type;
23 
24  static void from_base(base_type const & in, indicator ind,
25  unsigned char & out)
26  {
27  if (ind == i_null)
28  {
29  throw soci_error("Null value not allowed for this type.");
30  }
31 
32  const base_type max = (std::numeric_limits<unsigned char>::max)();
33  const base_type min = (std::numeric_limits<unsigned char>::min)();
34  if (in < min || in > max)
35  {
36  throw soci_error("Value outside of allowed range.");
37  }
38 
39  out = static_cast<unsigned char>(in);
40  }
41 
42  static void to_base(unsigned char const & in,
43  base_type & out, indicator & ind)
44  {
45  out = static_cast<base_type>(in);
46  ind = i_ok;
47  }
48 };
49 
50 template <>
51 struct type_conversion<unsigned short>
52 {
53  typedef long long base_type;
54 
55  static void from_base(base_type const & in, indicator ind,
56  unsigned short & out)
57  {
58  if (ind == i_null)
59  {
60  throw soci_error("Null value not allowed for this type.");
61  }
62 
63  const long long max = (std::numeric_limits<unsigned short>::max)();
64  const long long min = (std::numeric_limits<unsigned short>::min)();
65  if (in < min || in > max)
66  {
67  throw soci_error("Value outside of allowed range.");
68  }
69 
70  out = static_cast<unsigned short>(in);
71  }
72 
73  static void to_base(unsigned short const & in,
74  base_type & out, indicator & ind)
75  {
76  out = static_cast<base_type>(in);
77  ind = i_ok;
78  }
79 };
80 
81 template <>
82 struct type_conversion<unsigned int>
83 {
84  typedef long long base_type;
85 
86  static void from_base(base_type const & in, indicator ind,
87  unsigned int & out)
88  {
89  if (ind == i_null)
90  {
91  throw soci_error("Null value not allowed for this type.");
92  }
93 
94  const long long max = (std::numeric_limits<unsigned int>::max)();
95  const long long min = (std::numeric_limits<unsigned int>::min)();
96  if (in < min || in > max)
97  {
98  throw soci_error("Value outside of allowed range.");
99  }
100 
101  out = static_cast<unsigned int>(in);
102  }
103 
104  static void to_base(unsigned int const & in,
105  base_type & out, indicator & ind)
106  {
107  out = static_cast<base_type>(in);
108  ind = i_ok;
109  }
110 };
111 
112 } // namespace soci
113 
114 #endif // SOCI_UNSIGNED_TYPES_H_INCLUDED
static void from_base(base_type const &in, indicator ind, unsigned char &out)
static void from_base(base_type const &in, indicator ind, unsigned short &out)
static void to_base(unsigned char const &in, base_type &out, indicator &ind)
static void to_base(unsigned int const &in, base_type &out, indicator &ind)
static void to_base(unsigned short const &in, base_type &out, indicator &ind)
static void from_base(base_type const &in, indicator ind, unsigned int &out)


asr_lib_ism
Author(s): Hanselmann Fabian, Heller Florian, Heizmann Heinrich, Kübler Marcel, Mehlhaus Jonas, Meißner Pascal, Qattan Mohamad, Reckling Reno, Stroh Daniel
autogenerated on Wed Jan 8 2020 04:02:41