ThinSQLite++
A thin, safe and convenient modern C++ wrapper for 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/main/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
36 {
37 public:
39 explicit constexpr sqlite_version(int val): _value(val) {}
40
42 static constexpr sqlite_version from_parts(unsigned major, unsigned minor, unsigned release)
43 {
44 if (release > 1000)
45 throw std::runtime_error("invalid release value");
46 int val = release;
47 if (minor > 1000000)
48 throw std::runtime_error("invalid minor value");
49 val += minor*1000;
50 if (major > unsigned((std::numeric_limits<int>::max() - val) / 1000000))
51 throw std::runtime_error("invalid major value");
52 val += major*1000000;
53 return sqlite_version(val);
54 }
55
65 {
66 unsigned val = _value;
67 unsigned major = val / 1000000;
68 val -= (major * 1000000);
69 unsigned minor = val / 1000;
70 val -= (minor * 1000);
71 unsigned release = val;
72 return {major, minor, release};
73 }
74
76 constexpr int value() const noexcept
77 { return _value; }
78
84 static constexpr sqlite_version compile_time() noexcept
86
94
100 static constexpr const char * compile_time_str() noexcept
101 { return SQLITE_VERSION; }
107 static const char * runtime_str() noexcept
108 { return sqlite3_libversion(); }
109
110
116 static constexpr const char * compile_time_sourceid() noexcept
117 { return SQLITE_SOURCE_ID; }
118
124 static const char * runtime_sourceid() noexcept
125 { return sqlite3_sourceid(); }
126
127 friend constexpr bool operator==(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
128 { return lhs._value == rhs._value; }
129 friend constexpr bool operator!=(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
130 { return lhs._value != rhs._value; }
131
132 #if defined(DOXYGEN) || __cpp_impl_three_way_comparison >= 201907
133 friend constexpr std::strong_ordering operator<=>(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
134 { return lhs._value <=> rhs._value; }
135 #endif
136 friend constexpr bool operator<(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
137 { return lhs._value < rhs._value; }
138 friend constexpr bool operator<=(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
139 { return lhs._value <= rhs._value; }
140 friend constexpr bool operator>(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
141 { return lhs._value > rhs._value; }
142 friend constexpr bool operator>=(const sqlite_version & lhs, const sqlite_version & rhs) noexcept
143 { return lhs._value >= rhs._value; }
144
145 private:
146 int _value;
147 };
148
150}
151
152#endif
#define SQLITE_VERSION_NUMBER
Representation of SQLite version.
Definition version_iface.hpp:36
constexpr sqlite_version(int val)
Construct an instance from an int encoded in SQLite format.
Definition version_iface.hpp:39
static sqlite_version runtime() noexcept
Returns the runtime SQLite version.
Definition version_iface.hpp:92
constexpr int value() const noexcept
Get the stored SQLite version value.
Definition version_iface.hpp:76
static constexpr const char * compile_time_sourceid() noexcept
Returns the compile time SQLite source identifier.
Definition version_iface.hpp:116
static constexpr sqlite_version compile_time() noexcept
Returns the compile time SQLite version.
Definition version_iface.hpp:84
static constexpr const char * compile_time_str() noexcept
Returns the compile time SQLite version as a string.
Definition version_iface.hpp:100
constexpr std::tuple< unsigned, unsigned, unsigned > parts() const noexcept
Break an instance into constituent parts.
Definition version_iface.hpp:64
static constexpr sqlite_version from_parts(unsigned major, unsigned minor, unsigned release)
Construct an instance from major, minor, release parts.
Definition version_iface.hpp:42
static const char * runtime_sourceid() noexcept
Returns the runtime SQLite source identifier.
Definition version_iface.hpp:124
static const char * runtime_str() noexcept
Returns the runtime SQLite version as a string.
Definition version_iface.hpp:107
sqlite3_libversion_number
ThinSQLite++ namespace.
Definition backup_iface.hpp:17