From 05990afedf52777e35517c8ef3ad555f8d0cbf21 Mon Sep 17 00:00:00 2001 From: Sandu Liviu Catalin Date: Sun, 22 Mar 2020 03:03:05 +0200 Subject: [PATCH] Cleanup SQLite code. --- module/Library/SQLite.cpp | 9 ++++-- module/Library/SQLite.hpp | 64 +++++++++++++++---------------------- squirrel/include/squirrel.h | 6 ++++ 3 files changed, 39 insertions(+), 40 deletions(-) diff --git a/module/Library/SQLite.cpp b/module/Library/SQLite.cpp index de899a98..a9f04b08 100644 --- a/module/Library/SQLite.cpp +++ b/module/Library/SQLite.cpp @@ -21,6 +21,10 @@ SQMODE_DECL_TYPENAME(SQLiteColumnTypename, _SC("SQLiteColumn")) SQMODE_DECL_TYPENAME(SQLiteStatementTypename, _SC("SQLiteStatement")) SQMODE_DECL_TYPENAME(SQLiteTransactionTypename, _SC("SQLiteTransaction")) +// ------------------------------------------------------------------------------------------------ +#pragma clang diagnostic push +#pragma ide diagnostic ignored "hicpp-signed-bitwise" + /* ------------------------------------------------------------------------------------------------ * Helper class that represents an integral enumeration value. Used to reduce compilation times. */ @@ -367,6 +371,7 @@ static const SEnumElement g_MainEnum[] = { {_SC("WARNING"), SQLITE_WARNING}, {_SC("WARNING_AUTOINDEX"), SQLITE_WARNING_AUTOINDEX} }; +#pragma clang diagnostic pop // ------------------------------------------------------------------------------------------------ static inline bool IsDigitsOnly(CSStr str) @@ -2864,9 +2869,9 @@ void Register_SQLite(HSQUIRRELVM vm) { Enumeration e(vm); - for (Uint32 n = 0; n < (sizeof(g_MainEnum) / sizeof(EnumElement)); ++n) + for (auto n : g_MainEnum) { - e.Const(g_MainEnum[n].Name, g_MainEnum[n].Value); + e.Const(n.Name, n.Value); } ConstTable(vm).Enum(_SC("SQLiteOpt"), e); diff --git a/module/Library/SQLite.hpp b/module/Library/SQLite.hpp index 60bb4402..612186d2 100644 --- a/module/Library/SQLite.hpp +++ b/module/Library/SQLite.hpp @@ -12,6 +12,7 @@ #include "Library/Chrono/Timestamp.hpp" // ------------------------------------------------------------------------------------------------ +#include #include #include @@ -86,11 +87,6 @@ Object GetConnectionObj(const ConnRef & conn); */ Object GetStatementObj(const StmtRef & stmt); -/* ------------------------------------------------------------------------------------------------ - * Generate a formatted query. -*/ -CSStr QFmtStr(CSStr str, ...); - /* ------------------------------------------------------------------------------------------------ * Tests if a certain query string is empty. */ @@ -153,11 +149,11 @@ public: // -------------------------------------------------------------------------------------------- typedef Type* Pointer; // Pointer to the managed type. - typedef const Type* ConstPtr; // Constant pointer to the managed type. + typedef const Type* SQ_UNUSED_TYPEDEF(ConstPtr); // Constant pointer to the managed type. // -------------------------------------------------------------------------------------------- typedef Type& Reference; // Reference to the managed type. - typedef const Type& ConstRef; // Constant reference to the managed type. + typedef const Type& SQ_UNUSED_TYPEDEF(ConstRef); // Constant reference to the managed type. // -------------------------------------------------------------------------------------------- typedef std::vector< String > QueryList; // Container used to queue queries. @@ -268,11 +264,11 @@ public: // -------------------------------------------------------------------------------------------- typedef Type* Pointer; // Pointer to the managed type. - typedef const Type* ConstPtr; // Constant pointer to the managed type. + typedef const Type* SQ_UNUSED_TYPEDEF(ConstPtr); // Constant pointer to the managed type. // -------------------------------------------------------------------------------------------- typedef Type& Reference; // Reference to the managed type. - typedef const Type& ConstRef; // Constant reference to the managed type. + typedef const Type& SQ_UNUSED_TYPEDEF(ConstRef); // Constant reference to the managed type. // -------------------------------------------------------------------------------------------- typedef std::map< String, int > Indexes; // Container used to identify column indexes. @@ -303,7 +299,7 @@ public: /* -------------------------------------------------------------------------------------------- * Default constructor. */ - StmtHnd(ConnRef conn); + explicit StmtHnd(ConnRef conn); /* -------------------------------------------------------------------------------------------- * Copy constructor. (disabled) @@ -947,8 +943,8 @@ public: /* -------------------------------------------------------------------------------------------- * No parameter constructor. */ - Parameter(const StmtRef & stmt) - : m_Index(0), m_Handle(stmt) + explicit Parameter(StmtRef stmt) + : m_Index(0), m_Handle(std::move(stmt)) { /* ... */ } @@ -956,8 +952,8 @@ public: /* -------------------------------------------------------------------------------------------- * Index constructor. */ - Parameter(const StmtRef & stmt, Int32 idx) - : m_Index(idx), m_Handle(stmt) + Parameter(StmtRef stmt, Int32 idx) + : m_Index(idx), m_Handle(std::move(stmt)) { SQMOD_VALIDATE_PARAM(*this, m_Index); } @@ -974,8 +970,8 @@ public: /* -------------------------------------------------------------------------------------------- * Dynamic constructor. */ - Parameter(const StmtRef & stmt, const Object & param) - : m_Index(0), m_Handle(stmt) + Parameter(StmtRef stmt, const Object & param) + : m_Index(0), m_Handle(std::move(stmt)) { if (!m_Handle) { @@ -1024,7 +1020,7 @@ public: /* -------------------------------------------------------------------------------------------- * Implicit conversion to boolean for use in boolean operations. */ - operator bool () const + operator bool () const // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) { return m_Index >= 0; } @@ -1355,8 +1351,8 @@ public: /* -------------------------------------------------------------------------------------------- * No column constructor. */ - Column(const StmtRef & stmt) - : m_Index(-1), m_Handle(stmt) + explicit Column(StmtRef stmt) + : m_Index(-1), m_Handle(std::move(stmt)) { /* ... */ } @@ -1364,8 +1360,8 @@ public: /* -------------------------------------------------------------------------------------------- * Index constructor. */ - Column(const StmtRef & stmt, Int32 idx) - : m_Index(idx), m_Handle(stmt) + Column(StmtRef stmt, Int32 idx) + : m_Index(idx), m_Handle(std::move(stmt)) { SQMOD_VALIDATE_COLUMN(*this, m_Index); } @@ -1382,8 +1378,8 @@ public: /* -------------------------------------------------------------------------------------------- * Dynamic constructor. */ - Column(const StmtRef & stmt, const Object & column) - : m_Index(-1), m_Handle(stmt) + Column(StmtRef stmt, const Object & column) + : m_Index(-1), m_Handle(std::move(stmt)) { if (!m_Handle) { @@ -1432,7 +1428,7 @@ public: /* -------------------------------------------------------------------------------------------- * Implicit conversion to boolean for use in boolean operations. */ - operator bool () const + operator bool () const // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) { return m_Index >= 0; } @@ -1678,8 +1674,8 @@ public: /* -------------------------------------------------------------------------------------------- * Direct handle constructor. */ - Statement(const StmtRef & s) - : m_Handle(s) + explicit Statement(StmtRef s) + : m_Handle(std::move(s)) { /* ... */ } @@ -1723,7 +1719,7 @@ public: /* -------------------------------------------------------------------------------------------- * Implicit conversion to the raw connection handle. */ - operator sqlite3_stmt * () + operator sqlite3_stmt * () // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) { return m_Handle ? m_Handle->mPtr : nullptr; } @@ -1731,7 +1727,7 @@ public: /* -------------------------------------------------------------------------------------------- * Implicit conversion to the raw connection handle. */ - operator sqlite3_stmt * () const + operator sqlite3_stmt * () const // NOLINT(google-explicit-constructor,hicpp-explicit-conversions) { return m_Handle ? m_Handle->mPtr : nullptr; } @@ -2441,12 +2437,12 @@ public: /* -------------------------------------------------------------------------------------------- * Construct by taking the handle from a connection. */ - Transaction(const Connection & db); + explicit Transaction(const Connection & db); /* -------------------------------------------------------------------------------------------- * Construct using the direct connection handle. */ - Transaction(ConnRef db); + explicit Transaction(ConnRef db); /* -------------------------------------------------------------------------------------------- * Copy constructor. (disabled) @@ -2481,14 +2477,6 @@ public: return m_Handle ? m_Handle->mName : NullString(); } - /* -------------------------------------------------------------------------------------------- - * Retrieve the associated statement handle. - */ - const ConnRef & GetHandle() const - { - return m_Handle; - } - /* -------------------------------------------------------------------------------------------- * See whether the managed handle is valid. */ diff --git a/squirrel/include/squirrel.h b/squirrel/include/squirrel.h index 66d1d233..5d8907d9 100644 --- a/squirrel/include/squirrel.h +++ b/squirrel/include/squirrel.h @@ -409,6 +409,12 @@ SQUIRREL_API void sq_setnativedebughook(HSQUIRRELVM v,SQDEBUGHOOK hook); # define SQ_UNUSED_ARG(x) x #endif +#ifdef __GNUC__ +# define SQ_UNUSED_TYPEDEF(x) x __attribute__((__unused__)) +#else +# define SQ_UNUSED_TYPEDEF(x) x +#endif + #ifdef __cplusplus } /*extern "C"*/ #endif