Bug 489624 - Update mozStorageRow.* to follow style guidelines
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Fri, 08 May 2009 20:29:56 -0400
changeset 28142 c9b6ca7c431f15f2da557647b02c86530790f4bb
parent 28141 5293c44639243bf3f111efb1ee4bc31a65a2f559
child 28143 1d27d30234e251dd090ef5e523080929a174fd1b
push idunknown
push userunknown
push dateunknown
bugs489624
milestone1.9.2a1pre
Bug 489624 - Update mozStorageRow.* to follow style guidelines Consistent spacing, consistent naming, and namespaces - OH MY! r=asuth
storage/src/mozStorageArgValueArray.cpp
storage/src/mozStorageAsyncStatementExecution.cpp
storage/src/mozStoragePrivateHelpers.h
storage/src/mozStorageRow.cpp
storage/src/mozStorageRow.h
--- a/storage/src/mozStorageArgValueArray.cpp
+++ b/storage/src/mozStorageArgValueArray.cpp
@@ -36,24 +36,22 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsError.h"
 #include "nsMemory.h"
 #include "nsString.h"
 
+#include "mozStoragePrivateHelpers.h"
 #include "mozStorageArgValueArray.h"
 
 namespace mozilla {
 namespace storage {
 
-#define ENSURE_INDEX_VALUE(aIndex, aCount) \
-  NS_ENSURE_TRUE(aIndex < aCount, NS_ERROR_INVALID_ARG)
-
 ////////////////////////////////////////////////////////////////////////////////
 //// ArgValueArray
 
 ArgValueArray::ArgValueArray(PRInt32 aArgc,
                              sqlite3_value **aArgv)
 : mArgc(aArgc)
 , mArgv(aArgv)
 {
--- a/storage/src/mozStorageAsyncStatementExecution.cpp
+++ b/storage/src/mozStorageAsyncStatementExecution.cpp
@@ -340,17 +340,17 @@ AsyncExecuteStatements::buildAndNotifyRe
   // up running when it checks back with us to see if it should run.
   nsAutoUnlock cancelationScope(mLock);
 
   // Build result object if we need it.
   if (!mResultSet)
     mResultSet = new ResultSet();
   NS_ENSURE_TRUE(mResultSet, NS_ERROR_OUT_OF_MEMORY);
 
-  nsRefPtr<mozStorageRow> row(new mozStorageRow());
+  nsRefPtr<Row> row(new Row());
   NS_ENSURE_TRUE(row, NS_ERROR_OUT_OF_MEMORY);
 
   nsresult rv = row->initialize(aStatement);
   NS_ENSURE_SUCCESS(rv, rv);
 
   rv = mResultSet->add(row);
   NS_ENSURE_SUCCESS(rv, rv);
 
--- a/storage/src/mozStoragePrivateHelpers.h
+++ b/storage/src/mozStoragePrivateHelpers.h
@@ -36,25 +36,36 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #ifndef _mozStoragePrivateHelpers_h_
 #define _mozStoragePrivateHelpers_h_
 
-#include "mozStorage.h"
-
 /**
  * This file contains convenience methods for mozStorage.
  */
 
+#include "mozStorage.h"
+
+struct sqlite3_stmt;
+
 namespace mozilla {
 namespace storage {
 
+////////////////////////////////////////////////////////////////////////////////
+//// Macros
+
+#define ENSURE_INDEX_VALUE(aIndex, aCount) \
+  NS_ENSURE_TRUE(aIndex < aCount, NS_ERROR_INVALID_ARG)
+
+////////////////////////////////////////////////////////////////////////////////
+//// Functions
+
 /**
  * Converts a SQLite return code to an nsresult return code.
  *
  * @param aSQLiteResultCode
  *        The SQLite return code to convert.
  * @returns the corresponding nsresult code for aSQLiteResultCode.
  */
 nsresult convertResultCode(int aSQLiteResultCode);
--- a/storage/src/mozStorageRow.cpp
+++ b/storage/src/mozStorageRow.cpp
@@ -35,127 +35,129 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 #include "nsString.h"
 
 #include "sqlite3.h"
+#include "mozStoragePrivateHelpers.h"
 #include "mozStorageVariant.h"
 #include "mozStorageRow.h"
 
-using namespace mozilla::storage;
+namespace mozilla {
+namespace storage {
 
 ////////////////////////////////////////////////////////////////////////////////
-//// mozStorageRow
-
-/**
- * Note:  This object is only ever accessed on one thread at a time.  It it not
- *        threadsafe, but it does need threadsafe AddRef and Release.
- */
-NS_IMPL_THREADSAFE_ISUPPORTS2(
-  mozStorageRow,
-  mozIStorageRow,
-  mozIStorageValueArray
-)
+//// Row
 
 nsresult
-mozStorageRow::initialize(sqlite3_stmt *aStatement)
+Row::initialize(sqlite3_stmt *aStatement)
 {
   // Initialize the hash table
   NS_ENSURE_TRUE(mNameHashtable.Init(), NS_ERROR_OUT_OF_MEMORY);
 
   // Get the number of results
-  mNumCols = sqlite3_column_count(aStatement);
+  mNumCols = ::sqlite3_column_count(aStatement);
 
   // Start copying over values
   for (PRUint32 i = 0; i < mNumCols; i++) {
     // Store the value
     nsIVariant *variant = nsnull;
-    int type = sqlite3_column_type(aStatement, i);
+    int type = ::sqlite3_column_type(aStatement, i);
     switch (type) {
       case SQLITE_INTEGER:
-        variant = new IntegerVariant(sqlite3_column_int64(aStatement, i));
+        variant = new IntegerVariant(::sqlite3_column_int64(aStatement, i));
         break;
       case SQLITE_FLOAT:
-        variant = new FloatVariant(sqlite3_column_double(aStatement, i));
+        variant = new FloatVariant(::sqlite3_column_double(aStatement, i));
         break;
       case SQLITE_TEXT:
       {
         nsDependentString str(
-          static_cast<const PRUnichar *>(sqlite3_column_text16(aStatement, i))
+          static_cast<const PRUnichar *>(::sqlite3_column_text16(aStatement, i))
         );
         variant = new TextVariant(str);
         break;
       }
       case SQLITE_NULL:
         variant = new NullVariant();
         break;
       case SQLITE_BLOB:
       {
-        int size = sqlite3_column_bytes(aStatement, i);
-        const void *data = sqlite3_column_blob(aStatement, i);
+        int size = ::sqlite3_column_bytes(aStatement, i);
+        const void *data = ::sqlite3_column_blob(aStatement, i);
         variant = new BlobVariant(std::pair<const void *, int>(data, size));
         break;
       }
       default:
         return NS_ERROR_UNEXPECTED;
     }
     NS_ENSURE_TRUE(variant, NS_ERROR_OUT_OF_MEMORY);
 
     // Insert into our storage array
     NS_ENSURE_TRUE(mData.InsertObjectAt(variant, i), NS_ERROR_OUT_OF_MEMORY);
 
     // Associate the name (if any) with the index
-    const char *name = sqlite3_column_name(aStatement, i);
+    const char *name = ::sqlite3_column_name(aStatement, i);
     if (!name) break;
     nsCAutoString colName(name);
     mNameHashtable.Put(colName, i);
   }
 
   return NS_OK;
 }
 
+/**
+ * Note:  This object is only ever accessed on one thread at a time.  It it not
+ *        threadsafe, but it does need threadsafe AddRef and Release.
+ */
+NS_IMPL_THREADSAFE_ISUPPORTS2(
+  Row,
+  mozIStorageRow,
+  mozIStorageValueArray
+)
+
 ////////////////////////////////////////////////////////////////////////////////
 //// mozIStorageRow
 
 NS_IMETHODIMP
-mozStorageRow::GetResultByIndex(PRUint32 aIndex, nsIVariant **_result)
+Row::GetResultByIndex(PRUint32 aIndex,
+                      nsIVariant **_result)
 {
-  if (aIndex >= mNumCols)
-    return NS_ERROR_ILLEGAL_VALUE;
-
+  ENSURE_INDEX_VALUE(aIndex, mNumCols);
   NS_ADDREF(*_result = mData.ObjectAt(aIndex));
   return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetResultByName(const nsACString &aName, nsIVariant **_result)
+Row::GetResultByName(const nsACString &aName,
+                     nsIVariant **_result)
 {
   PRUint32 index;
   NS_ENSURE_TRUE(mNameHashtable.Get(aName, &index), NS_ERROR_NOT_AVAILABLE);
   return GetResultByIndex(index, _result);
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 //// mozIStorageValueArray
 
 NS_IMETHODIMP
-mozStorageRow::GetNumEntries(PRUint32 *_entries)
+Row::GetNumEntries(PRUint32 *_entries)
 {
   *_entries = mNumCols;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetTypeOfIndex(PRUint32 aIndex, PRInt32 *_type)
+Row::GetTypeOfIndex(PRUint32 aIndex,
+                    PRInt32 *_type)
 {
-  if (aIndex >= mNumCols)
-    return NS_ERROR_ILLEGAL_VALUE;
+  ENSURE_INDEX_VALUE(aIndex, mNumCols);
 
   PRUint16 type;
   (void)mData.ObjectAt(aIndex)->GetDataType(&type);
   switch (type) {
     case nsIDataType::VTYPE_INT32:
     case nsIDataType::VTYPE_INT64:
       *_type = mozIStorageValueArray::VALUE_TYPE_INTEGER;
       break;
@@ -171,93 +173,98 @@ mozStorageRow::GetTypeOfIndex(PRUint32 a
     default:
       *_type = mozIStorageValueArray::VALUE_TYPE_NULL;
       break;
   }
   return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetInt32(PRUint32 aIndex, PRInt32 *_value)
+Row::GetInt32(PRUint32 aIndex,
+              PRInt32 *_value)
 {
-  if (aIndex >= mNumCols)
-    return NS_ERROR_ILLEGAL_VALUE;
-
+  ENSURE_INDEX_VALUE(aIndex, mNumCols);
   return mData.ObjectAt(aIndex)->GetAsInt32(_value);
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetInt64(PRUint32 aIndex, PRInt64 *_value)
+Row::GetInt64(PRUint32 aIndex,
+              PRInt64 *_value)
 {
-  if (aIndex >= mNumCols)
-    return NS_ERROR_ILLEGAL_VALUE;
-
+  ENSURE_INDEX_VALUE(aIndex, mNumCols);
   return mData.ObjectAt(aIndex)->GetAsInt64(_value);
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetDouble(PRUint32 aIndex, double *_value)
+Row::GetDouble(PRUint32 aIndex,
+               double *_value)
 {
-  if (aIndex >= mNumCols)
-    return NS_ERROR_ILLEGAL_VALUE;
-
+  ENSURE_INDEX_VALUE(aIndex, mNumCols);
   return mData.ObjectAt(aIndex)->GetAsDouble(_value);
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetUTF8String(PRUint32 aIndex, nsACString &_value)
+Row::GetUTF8String(PRUint32 aIndex,
+                   nsACString &_value)
 {
-  if (aIndex >= mNumCols)
-    return NS_ERROR_ILLEGAL_VALUE;
-
+  ENSURE_INDEX_VALUE(aIndex, mNumCols);
   return mData.ObjectAt(aIndex)->GetAsAUTF8String(_value);
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetString(PRUint32 aIndex, nsAString &_value)
+Row::GetString(PRUint32 aIndex,
+               nsAString &_value)
 {
-  if (aIndex >= mNumCols)
-    return NS_ERROR_ILLEGAL_VALUE;
-
+  ENSURE_INDEX_VALUE(aIndex, mNumCols);
   return mData.ObjectAt(aIndex)->GetAsAString(_value);
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetBlob(PRUint32 aIndex, PRUint32 *_size, PRUint8 **_blob)
+Row::GetBlob(PRUint32 aIndex,
+             PRUint32 *_size,
+             PRUint8 **_blob)
 {
-  if (aIndex >= mNumCols)
-    return NS_ERROR_ILLEGAL_VALUE;
+  ENSURE_INDEX_VALUE(aIndex, mNumCols);
 
   PRUint16 type;
   nsIID interfaceIID;
   return mData.ObjectAt(aIndex)->GetAsArray(&type, &interfaceIID, _size,
                                             reinterpret_cast<void **>(_blob));
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetIsNull(PRUint32 aIndex, PRBool *_isNull)
+Row::GetIsNull(PRUint32 aIndex,
+               PRBool *_isNull)
 {
-  if (aIndex >= mNumCols)
-    return NS_ERROR_ILLEGAL_VALUE;
+  ENSURE_INDEX_VALUE(aIndex, mNumCols);
 
   PRUint16 type;
   (void)mData.ObjectAt(aIndex)->GetDataType(&type);
   *_isNull = type == nsIDataType::VTYPE_VOID;
   return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetSharedUTF8String(PRUint32, PRUint32 *, char const **)
+Row::GetSharedUTF8String(PRUint32,
+                         PRUint32 *,
+                         char const **)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetSharedString(PRUint32, PRUint32 *, const PRUnichar **)
+Row::GetSharedString(PRUint32,
+                     PRUint32 *,
+                     const PRUnichar **)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 NS_IMETHODIMP
-mozStorageRow::GetSharedBlob(PRUint32, PRUint32 *, const PRUint8 **)
+Row::GetSharedBlob(PRUint32,
+                   PRUint32 *,
+                   const PRUint8 **)
 {
   return NS_ERROR_NOT_IMPLEMENTED;
 }
+
+} // namespace storage
+} // namespace mozilla
--- a/storage/src/mozStorageRow.h
+++ b/storage/src/mozStorageRow.h
@@ -41,17 +41,20 @@
 #define __mozStorageRow_h__
 
 #include "mozIStorageRow.h"
 #include "nsCOMArray.h"
 #include "nsDataHashtable.h"
 class nsIVariant;
 struct sqlite3_stmt;
 
-class mozStorageRow : public mozIStorageRow
+namespace mozilla {
+namespace storage {
+
+class Row : public mozIStorageRow
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_MOZISTORAGEROW
   NS_DECL_MOZISTORAGEVALUEARRAY
 
   /**
    * Initializes the object with the given statement.  Copies the values from
@@ -74,9 +77,12 @@ private:
   nsCOMArray<nsIVariant> mData;
 
   /**
    * Maps a given name to a column index.
    */
   nsDataHashtable<nsCStringHashKey, PRUint32> mNameHashtable;
 };
 
+} // namespace storage
+} // namespace mozilla
+
 #endif // __mozStorageRow_h__