From 554a79b64d0be4c0c122f17b1ed5c931b32b4031 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Rombauts?= Date: Wed, 5 Dec 2012 17:36:02 +0100 Subject: [PATCH] =?UTF-8?q?Added=20a=20copy=20constructor=20that=20increme?= =?UTF-8?q?nts=C2=A0the=20reference=20counter,=20thanks=20to=20a=20patch?= =?UTF-8?q?=20from=20Mark=20P.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/SQLiteC++/Column.cpp | 20 ++++++++++++++++---- src/SQLiteC++/Column.h | 11 +++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/SQLiteC++/Column.cpp b/src/SQLiteC++/Column.cpp index 8ca61b5..3108696 100644 --- a/src/SQLiteC++/Column.cpp +++ b/src/SQLiteC++/Column.cpp @@ -16,10 +16,22 @@ namespace SQLite // Encapsulation of a Column in a Row of the result. Column::Column(sqlite3* apSQLite, sqlite3_stmt* apStmt, unsigned int* apStmtRefCount, int aIndex) throw() : // nothrow - mpSQLite(apSQLite), - mpStmt(apStmt), - mpStmtRefCount(apStmtRefCount), - mIndex(aIndex) + mpSQLite (apSQLite), + mpStmt (apStmt), + mpStmtRefCount (apStmtRefCount), + mIndex (aIndex) +{ + // Increment the reference counter of the sqlite3_stmt, + // telling the Statement object not to finalize the sqlite3_stmt during the lifetime of this Column objet + (*mpStmtRefCount)++; +} + +// Copy constructor +Column::Column(const Column& copy) throw() : // nothrow + mpSQLite (copy.mpSQLite), + mpStmt (copy.mpStmt), + mpStmtRefCount (copy.mpStmtRefCount), + mIndex (copy.mIndex) { // Increment the reference counter of the sqlite3_stmt, // telling the Statement object not to finalize the sqlite3_stmt during the lifetime of this Column objet diff --git a/src/SQLiteC++/Column.h b/src/SQLiteC++/Column.h index 47fbec6..265a032 100644 --- a/src/SQLiteC++/Column.h +++ b/src/SQLiteC++/Column.h @@ -30,8 +30,11 @@ public: * @brief Compile and register the SQL query for the provided SQLite Database Connection */ explicit Column(sqlite3* apSQLite, sqlite3_stmt* apStmt, unsigned int* apStmtRefCount, int aIndex) throw(); // nothrow - /// Basic destructor - virtual ~Column(void) throw(); // nothrow + /// Simple destructor + virtual ~Column(void) throw(); // nothrow + + /// @brief copy constructor : only way to copy a valid instance + Column(const Column& aOther) throw(); // nothrow /// Return the integer value of the column. int getInt (void) const throw(); @@ -78,9 +81,9 @@ public: #endif private: - // Column is copyable, but copy should not be used elsewhere than in return form getColumn + // Forbid default constructor and assignment operator (no implementation) + // so that there is no way of having a Column instance not initialized Column(void); - // TODO Column(const Column&); Column& operator=(const Column&); private: