SQLiteXX  0.1.0
 All Classes Namespaces Files Functions Enumerations Enumerator
Value.h
Go to the documentation of this file.
1 
3 #ifndef __SQLITEXX_SQLITE_VALUE_H__
4 #define __SQLITEXX_SQLITE_VALUE_H__
5 
6 #include "SQLiteEnums.h"
7 #include "Blob.h"
8 
9 #include <sqlite3.h>
10 
11 #include <cassert>
12 #include <cstring>
13 #include <string>
14 
15 namespace sqlite
16 {
27  class value
28  {
29  public:
30 
34  explicit value(const sqlite3_value* const value);
35 
40  value(const value& other);
41 
46  value(value&& other);
47 
53  value& operator=(const value& other);
54 
60  value& operator=(value&& other);
61 
64  sqlite3_value* handle() const noexcept;
65 
69  int as_int() const noexcept;
70 
74  int64_t as_int64() const noexcept;
75 
79  unsigned int as_uint() const noexcept;
80 
84  double as_double() const noexcept;
85 
89  const blob as_blob() const noexcept;
90 
94  const std::string as_string() const noexcept;
95 
99  const std::u16string as_u16string() const noexcept;
100 
104  int bytes() const noexcept;
105 
115  datatype type() const noexcept;
116 
117  operator int() const;
118  operator unsigned int() const;
119 #if (LONG_MAX == INT_MAX) // sizeof(long)==4 means long is equivalent to int
120  operator unsigned long() const;
121 #endif
122  operator long() const;
123  operator long long() const;
124  operator double() const;
125  operator const blob() const;
126  operator const std::string() const;
127  operator const std::u16string() const;
128 
129  private:
130 
131  using value_handle = std::unique_ptr<sqlite3_value, decltype(&sqlite3_value_free)>;
132  value_handle m_handle;
133 
134  const char* as_text() const noexcept;
135 
141  const char16_t* as_text16() const noexcept;
142  int text_length() const noexcept;
143  int text16_length() const noexcept;
144  };
145 
146  inline value::operator int() const
147  {
148  return as_int();
149  }
150 
151  inline value::operator unsigned int() const
152  {
153  return as_uint();
154  }
155 
156 #if (LONG_MAX == INT_MAX) // sizeof(long)==4 means long is equivalent to int
157  inline value::operator long() const
158  {
159  return as_int();
160  }
161 
162  inline value::operator unsigned long() const
163  {
164  return as_uint();
165  }
166 #else
167  inline value::operator long() const
168  {
169  return as_int64();
170  }
171 #endif
172 
173  inline value::operator long long() const
174  {
175  return as_int64();
176  }
177 
178  inline value::operator double() const
179  {
180  return as_double();
181  }
182 
183  inline value::operator const blob() const
184  {
185  return as_blob();
186  }
187 
188  inline value::operator const std::string() const
189  {
190  return as_string();
191  }
192 
193  inline value::operator const std::u16string() const
194  {
195  return as_u16string();
196  }
197 }
198 
199 #endif
200 
datatype type() const noexcept
Returns the datatype for the initial datatype of the value.
Definition: Value.cpp:79
A SQLite dynamically typed value object, aka "sqlite3_value".
Definition: Value.h:27
int64_t as_int64() const noexcept
Represents the value as a 64-bit integer.
Definition: Value.cpp:41
value & operator=(const value &other)
Copy assignment operator.
Definition: Value.cpp:22
a group and bits
const blob as_blob() const noexcept
Represents the value as a blob object.
Definition: Value.cpp:56
const std::string as_string() const noexcept
Represents the value as a string.
Definition: Value.cpp:62
const std::u16string as_u16string() const noexcept
Represents the value as a UTF-16 string.
Definition: Value.cpp:68
unsigned int as_uint() const noexcept
Represents the value as an unsigned integer.
Definition: Value.cpp:46
datatype
Every value in SQLite has one of the following fundamental datatypes.
Definition: SQLiteEnums.h:13
double as_double() const noexcept
Represents the value as a double.
Definition: Value.cpp:51
int bytes() const noexcept
Returns the size in bytes of the value.
Definition: Value.cpp:74
sqlite3_value * handle() const noexcept
Returns pointer to the underlying "sqlite3_value" object.
Definition: Value.cpp:18
value(const sqlite3_value *const value)
Constructs a value object from a sqlite3_value object.
Definition: Value.cpp:6
int as_int() const noexcept
Represents the value as an integer.
Definition: Value.cpp:36
A "Binary Large OBject".
Definition: Blob.h:20