From bcdbea2cf84b89c8eaa51f805d05fda3651df13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Sat, 2 Jul 2016 14:11:02 +0200 Subject: [PATCH] Style cleanup on top of PR #86 --- include/SQLiteCpp/Statement.h | 35 ++++++++++++++++++----------------- src/Statement.cpp | 16 ++++++++-------- 2 files changed, 26 insertions(+), 25 deletions(-) diff --git a/include/SQLiteCpp/Statement.h b/include/SQLiteCpp/Statement.h index 9cd8458..0d7bd7c 100644 --- a/include/SQLiteCpp/Statement.h +++ b/include/SQLiteCpp/Statement.h @@ -68,15 +68,15 @@ public: */ Statement(Database& aDatabase, const std::string& aQuery); - // Require C++11 -#if ( __cplusplus>= 201103L) || ( defined(_MSC_VER) && (_MSC_VER >= 1900) ) - #define Statement_CAN_MOVE 1 +#if (__cplusplus >= 201103L) || ( defined(_MSC_VER) && (_MSC_VER >= 1600) ) // C++11: Visual Studio 2010 /** - * @breif Move Constructor + * @brief Move Constructor * - * (Allows inserting into STL containers that may need to move memory when growing.) + * Allows inserting into STL containers that may need to move memory when growing. + * + * @param aOther Statement to move to */ - Statement(Statement &&other); + Statement(Statement&& aOther); #endif /** @@ -113,6 +113,7 @@ public: // This is under-optimized for static data (a static text define in code) // as well as for dynamic allocated buffer which could be transfer to sqlite // instead of being copied. + // => if you now what you are doing, use bindNoCopy() /** * @brief Bind an int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) @@ -125,7 +126,7 @@ public: /** * @brief Bind a 32bits unsigned int value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ - void bind(const int aIndex, const uint32_t aValue); + void bind(const int aIndex, const uint32_t aValue); /** * @brief Bind a double (64bits float) value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ @@ -135,34 +136,34 @@ public: * * @note This uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use */ - void bind(const int aIndex, const std::string& aValue); + void bind(const int aIndex, const std::string& aValue); /** * @brief Bind a string value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * - * @note This uses the SQLITE_STATIC flag, NOT making a copy of the data. It must exist while executing the statement. + * @note This uses the SQLITE_STATIC flag, avoiding a copy of the data. The string must remains unchanged while executing the statement. */ - void bindNoCopy(const int aIndex, const std::string& aValue); + void bindNoCopy(const int aIndex, const std::string& aValue); /** * @brief Bind a text value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * * @note This uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use */ - void bind(const int aIndex, const char* apValue); + void bind(const int aIndex, const char* apValue); /** * @brief Bind a binary blob value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * * @note This uses the SQLITE_TRANSIENT flag, making a copy of the data, for SQLite internal use */ - void bind(const int aIndex, const void* apValue, const int aSize); + void bind(const int aIndex, const void* apValue, const int aSize); /** * @brief Bind a binary blob value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * * @note This uses the SQLITE_STATIC flag, NOT making a copy of the data. It must exist while executing the statement. */ - void bindNoCopy(const int aIndex, const void* apValue, const int aSize); + void bindNoCopy(const int aIndex, const void* apValue, const int aSize); /** * @brief Bind a NULL value to a parameter "?", "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) @@ -172,19 +173,19 @@ public: /** * @brief Bind an int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ - void bind(const char* apName, const int aValue); + void bind(const char* apName, const int aValue); /** * @brief Bind a 64bits int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ - void bind(const char* apName, const sqlite3_int64 aValue); + void bind(const char* apName, const sqlite3_int64 aValue); /** * @brief Bind a 32bits unsigned int value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ - void bind(const char* apName, const uint32_t aValue); + void bind(const char* apName, const uint32_t aValue); /** * @brief Bind a double (64bits float) value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) */ - void bind(const char* apName, const double aValue); + void bind(const char* apName, const double aValue); /** * @brief Bind a string value to a named parameter "?NNN", ":VVV", "@VVV" or "$VVV" in the SQL prepared statement (aIndex >= 1) * diff --git a/src/Statement.cpp b/src/Statement.cpp index 1074f26..f83f00f 100644 --- a/src/Statement.cpp +++ b/src/Statement.cpp @@ -43,15 +43,15 @@ Statement::Statement(Database &aDatabase, const std::string& aQuery) : mColumnCount = sqlite3_column_count(mStmtPtr); } -#ifdef Statement_CAN_MOVE +#if (__cplusplus >= 201103L) || ( defined(_MSC_VER) && (_MSC_VER >= 1600) ) // C++11: Visual Studio 2010 // Move Constructor -Statement::Statement(Statement &&other): -mQuery(std::move(other.mQuery)), -mStmtPtr(other.mStmtPtr), -mColumnCount(other.mColumnCount), -mColumnNames(std::move(other.mColumnNames)), -mbOk(other.mbOk), -mbDone(other.mbDone) +Statement::Statement(Statement&& aOther): + mQuery(std::move(aOther.mQuery)), + mStmtPtr(aOther.mStmtPtr), // TODO: need a move operator + mColumnCount(aOther.mColumnCount), + mColumnNames(std::move(aOther.mColumnNames)), + mbOk(aOther.mbOk), + mbDone(aOther.mbDone) { // other.mStmtPtr = nullptr; // doesn't support reassigning other.mColumnCount = 0;