diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-10-29 01:35:16 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2021-10-29 01:35:16 -0400 |
commit | 12c105623cf236a632d29f41b56c3f1e8df27416 (patch) | |
tree | 8b49ab0baaffbaebcf9046c7f19ac32880311ed7 | |
parent | d950460e149d78962508f221c5e81717798cb228 (diff) | |
download | abaddon-portaudio-12c105623cf236a632d29f41b56c3f1e8df27416.tar.gz abaddon-portaudio-12c105623cf236a632d29f41b56c3f1e8df27416.zip |
templatize some stuff
-rw-r--r-- | discord/store.cpp | 34 | ||||
-rw-r--r-- | discord/store.hpp | 36 |
2 files changed, 21 insertions, 49 deletions
diff --git a/discord/store.cpp b/discord/store.cpp index 159e3dd..c313f4e 100644 --- a/discord/store.cpp +++ b/discord/store.cpp @@ -2161,20 +2161,8 @@ bool Store::Statement::OK() const { return m_stmt != nullptr; } -int Store::Statement::Bind(int index, int32_t num) { - return Bind(index, static_cast<uint32_t>(num)); -} - -int Store::Statement::Bind(int index, uint32_t num) { - return m_db->SetError(sqlite3_bind_int(m_stmt, index, num)); -} - -int Store::Statement::Bind(int index, size_t num) { - return m_db->SetError(sqlite3_bind_int64(m_stmt, index, num)); -} - int Store::Statement::Bind(int index, Snowflake id) { - return m_db->SetError(sqlite3_bind_int64(m_stmt, index, static_cast<sqlite3_int64>(id))); + return Bind(index, static_cast<uint64_t>(id)); } int Store::Statement::Bind(int index, const char *str, size_t len) { @@ -2186,30 +2174,10 @@ int Store::Statement::Bind(int index, const std::string &str) { return m_db->SetError(sqlite3_bind_blob(m_stmt, index, str.c_str(), str.size(), SQLITE_TRANSIENT)); } -int Store::Statement::Bind(int index, bool val) { - return m_db->SetError(sqlite3_bind_int(m_stmt, index, val ? 1L : 0L)); -} - int Store::Statement::Bind(int index) { return m_db->SetError(sqlite3_bind_null(m_stmt, index)); } -void Store::Statement::Get(int index, uint8_t &out) const { - out = sqlite3_column_int(m_stmt, index); -} - -void Store::Statement::Get(int index, int32_t &out) const { - out = sqlite3_column_int(m_stmt, index); -} - -void Store::Statement::Get(int index, size_t &out) const { - out = static_cast<size_t>(sqlite3_column_int64(m_stmt, index)); -} - -void Store::Statement::Get(int index, bool &out) const { - out = sqlite3_column_int(m_stmt, index) != 0; -} - void Store::Statement::Get(int index, Snowflake &out) const { out = static_cast<uint64_t>(sqlite3_column_int64(m_stmt, index)); } diff --git a/discord/store.hpp b/discord/store.hpp index b30d4f4..791c790 100644 --- a/discord/store.hpp +++ b/discord/store.hpp @@ -100,13 +100,9 @@ private: bool OK() const; - int Bind(int index, int32_t num); - int Bind(int index, uint32_t num); - int Bind(int index, size_t num); int Bind(int index, Snowflake id); int Bind(int index, const char *str, size_t len = -1); int Bind(int index, const std::string &str); - int Bind(int index, bool val); int Bind(int index); template<typename T> @@ -135,14 +131,6 @@ private: } template<typename T> - int BindAsJSON(int index, const std::optional<T> &obj) { - if (obj.has_value()) - return Bind(index, nlohmann::json(obj.value()).dump()); - else - return Bind(index); - } - - template<typename T> int BindAsJSON(int index, const T &obj) { return Bind(index, nlohmann::json(obj).dump()); } @@ -153,10 +141,26 @@ private: return Bind(index, static_cast<typename std::underlying_type<T>::type>(val)); } - void Get(int index, uint8_t &out) const; - void Get(int index, int32_t &out) const; - void Get(int index, size_t &out) const; - void Get(int index, bool &out) const; + template<typename T> + typename std::enable_if<std::is_integral<T>::value, int>::type + Bind(int index, T val) { + return m_db->SetError(sqlite3_bind_int64(m_stmt, val, static_cast<sqlite3_int64>(val))); + } + + template<typename T> + int BindAsJSON(int index, const std::optional<T> &obj) { + if (obj.has_value()) + return Bind(index, nlohmann::json(obj.value()).dump()); + else + return Bind(index); + } + + template<typename T> + typename std::enable_if<std::is_integral<T>::value>::type + Get(int index, T &out) const { + out = static_cast<T>(sqlite3_column_int64(m_stmt, index)); + } + void Get(int index, Snowflake &out) const; void Get(int index, std::string &out) const; |