ThinSQLite++
A thin, safe and convenient modern C++ wrapper for the SQLite API.
Loading...
Searching...
No Matches
version_iface.hpp
1/*
2 Copyright 2024 Eugene Gershnik
3
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file or at
6 https://github.com/gershnik/thinsqlitepp/blob/master/LICENSE
7*/
8
9#ifndef HEADER_SQLITEPP_VERSION_IFACE_INCLUDED
10#define HEADER_SQLITEPP_VERSION_IFACE_INCLUDED
11
12#include "config.hpp"
13
14#include <tuple>
15#include <limits>
16#include <stdexcept>
17
18namespace thinsqlitepp
19{
20
25
35 SQLITEPP_EXPORTED
37 {
38 public:
40 explicit constexpr sqlite_version(int val): _value(val) {}
41
43 static constexpr sqlite_version from_parts(unsigned major, unsigned minor, unsigned release)
44 {
45 if (release >= 1000)
46 throw std::runtime_error("invalid release value");
47 auto val = int(release);
48 if (minor >= 1000)
49 throw std::runtime_error("invalid minor value");
50 val += minor*1000;
51 if (major > unsigned((std::numeric_limits<int>::max() - val) / 1000000))
52 throw std::runtime_error("invalid major value");
53 val += major*1000000;
54 return sqlite_version(val);
55 }
56
66 {
67 auto val = unsigned(_value);
68 unsigned major = val / 1000000;
69 val -= (major * 1000000);
70 unsigned minor = val / 1000;
71 val -= (minor * 1000);
72 unsigned release = val;
73 return {major, minor, release};
74 }
75
77 constexpr int value() const noexcept
78 { return _value; }
79
85 static constexpr sqlite_version compile_time() noexcept
87
95
101 static constexpr const char * compile_time_str() noexcept
102 { return SQLITE_VERSION; }
103
108 static const char * runtime_str() noexcept
109 { return sqlite3_libversion(); }
110
111
117 static constexpr const char * compile_time_sourceid() noexcept
118 { return SQLITE_SOURCE_ID; }
119
125 static const char * runtime_sourceid() noexcept
126 { return sqlite3_sourceid(); }
127
128 friend constexpr bool operator==(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
129 { return lhs._value == rhs._value; }
130 friend constexpr bool operator!=(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
131 { return lhs._value != rhs._value; }
132
133 #if defined(DOXYGEN) || __cpp_impl_three_way_comparison >= 201907
134 friend constexpr std::strong_ordering operator<=>(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
135 { return lhs._value <=> rhs._value; }
136 #endif
137 friend constexpr bool operator<(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
138 { return lhs._value < rhs._value; }
139 friend constexpr bool operator<=(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
140 { return lhs._value <= rhs._value; }
141 friend constexpr bool operator>(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
142 { return lhs._value > rhs._value; }
143 friend constexpr bool operator>=(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
144 { return lhs._value >= rhs._value; }
145
146 private:
147 int _value;
148 };
149
151}
152
153#endif
#define SQLITE_VERSION_NUMBER
Representation of SQLite version.
Definition version_iface.hpp:37
constexpr sqlite_version(int val)
Construct an instance from an int encoded in SQLite format.
Definition version_iface.hpp:40
static sqlite_version runtime() noexcept
Returns the runtime SQLite version.
Definition version_iface.hpp:93
constexpr int value() const noexcept
Get the stored SQLite version value.
Definition version_iface.hpp:77
static constexpr const char * compile_time_sourceid() noexcept
Returns the compile time SQLite source identifier.
Definition version_iface.hpp:117
static constexpr sqlite_version compile_time() noexcept
Returns the compile time SQLite version.
Definition version_iface.hpp:85
static constexpr const char * compile_time_str() noexcept
Returns the compile time SQLite version as a string.
Definition version_iface.hpp:101
constexpr std::tuple< unsigned, unsigned, unsigned > parts() const noexcept
Break an instance into constituent parts.
Definition version_iface.hpp:65
static constexpr sqlite_version from_parts(unsigned major, unsigned minor, unsigned release)
Construct an instance from major, minor, release parts.
Definition version_iface.hpp:43
static const char * runtime_sourceid() noexcept
Returns the runtime SQLite source identifier.
Definition version_iface.hpp:125
static const char * runtime_str() noexcept
Returns the runtime SQLite version as a string.
Definition version_iface.hpp:108
sqlite3_libversion_number
T max(T... args)
ThinSQLite++ namespace.
Definition backup_iface.hpp:17