Bug 489030 - Rename mozStorageValueArray.* to mozStorageArgValueArray.*
authorShawn Wilsher <me@shawnwilsher.com>
Mon, 20 Apr 2009 08:01:51 -0700
changeset 27530 25386c8ca67744ca4410c0fa8ed63fa5ed829b4a
parent 27529 84df98a671f2f58a436e7c9d5252114ac1707678
child 27531 c65d261e7bf68c3a5fa729b3c88024b688481627
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs489030
milestone1.9.2a1pre
Bug 489030 - Rename mozStorageValueArray.* to mozStorageArgValueArray.* Better reflects the contents of the file. Also updated the file to follow the storage style guidelines. r=asuth
storage/src/Makefile.in
storage/src/mozStorageArgValueArray.cpp
storage/src/mozStorageArgValueArray.h
storage/src/mozStorageConnection.cpp
storage/src/mozStorageStatement.cpp
storage/src/mozStorageValueArray.cpp
storage/src/mozStorageValueArray.h
--- a/storage/src/Makefile.in
+++ b/storage/src/Makefile.in
@@ -63,17 +63,17 @@ REQUIRES = xpcom \
 
 CPPSRCS = \
   mozStorageService.cpp \
   mozStorageConnection.cpp \
   mozStorageStatement.cpp \
   mozStorageStatementWrapper.cpp \
   mozStorageStatementParams.cpp \
   mozStorageStatementRow.cpp \
-  mozStorageValueArray.cpp \
+  mozStorageArgValueArray.cpp \
   mozStorageSQLFunctions.cpp \
   mozStorageRow.cpp \
   mozStorageResultSet.cpp \
   mozStorageError.cpp \
   mozStorageEvents.cpp \
   mozStorageStatementJSHelper.cpp \
   mozStoragePrivateHelpers.cpp \
   mozStorageVariant.cpp \
rename from storage/src/mozStorageValueArray.cpp
rename to storage/src/mozStorageArgValueArray.cpp
--- a/storage/src/mozStorageValueArray.cpp
+++ b/storage/src/mozStorageArgValueArray.cpp
@@ -1,10 +1,11 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
+ * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
@@ -35,204 +36,202 @@
  * 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 "mozStorageValueArray.h"
+#include "mozStorageArgValueArray.h"
 
-/***
- *** mozStorageArgvValueArray
- ***/
+namespace mozilla {
+namespace storage {
+
+#define ENSURE_INDEX_VALUE(aIndex, aCount) \
+  NS_ENSURE_TRUE(aIndex < aCount, NS_ERROR_INVALID_ARG)
 
-/* Implementation file */
-NS_IMPL_ISUPPORTS1(mozStorageArgvValueArray, mozIStorageValueArray)
+////////////////////////////////////////////////////////////////////////////////
+//// ArgValueArray
 
-mozStorageArgvValueArray::mozStorageArgvValueArray(PRInt32 aArgc, sqlite3_value **aArgv)
-    : mArgc(aArgc), mArgv(aArgv)
+ArgValueArray::ArgValueArray(PRInt32 aArgc,
+                             sqlite3_value **aArgv)
+: mArgc(aArgc)
+, mArgv(aArgv)
 {
 }
 
-mozStorageArgvValueArray::~mozStorageArgvValueArray()
-{
-    /* do nothing, we don't own the array */
-}
-
-/* readonly attribute unsigned long length; */
-NS_IMETHODIMP
-mozStorageArgvValueArray::GetNumEntries(PRUint32 *aLength)
-{
-    *aLength = mArgc;
-    return NS_OK;
-}
-
-/* long getTypeOfIndex (in unsigned long aIndex); */
-NS_IMETHODIMP
-mozStorageArgvValueArray::GetTypeOfIndex(PRUint32 aIndex, PRInt32 *_retval)
-{
-    if (aIndex < 0 || aIndex >= mArgc)
-        return NS_ERROR_ILLEGAL_VALUE;
+NS_IMPL_ISUPPORTS1(
+  ArgValueArray,
+  mozIStorageValueArray
+)
 
-    int t = sqlite3_value_type (mArgv[aIndex]);
-    switch (t) {
-        case SQLITE_INTEGER:
-            *_retval = VALUE_TYPE_INTEGER;
-            break;
-        case SQLITE_FLOAT:
-            *_retval = VALUE_TYPE_FLOAT;
-            break;
-        case SQLITE_TEXT:
-            *_retval = VALUE_TYPE_TEXT;
-            break;
-        case SQLITE_BLOB:
-            *_retval = VALUE_TYPE_BLOB;
-            break;
-        case SQLITE_NULL:
-            *_retval = VALUE_TYPE_NULL;
-            break;
-        default:
-            // ???
-            return NS_ERROR_FAILURE;
-    }
+////////////////////////////////////////////////////////////////////////////////
+//// mozIStorageValueArray
 
-    return NS_OK;
+NS_IMETHODIMP
+ArgValueArray::GetNumEntries(PRUint32 *_size)
+{
+  *_size = mArgc;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetInt32(PRUint32 aIndex, PRInt32 *_retval)
+ArgValueArray::GetTypeOfIndex(PRUint32 aIndex,
+                              PRInt32 *_type)
 {
-    if (aIndex < 0 || aIndex >= mArgc)
-        return NS_ERROR_ILLEGAL_VALUE;
+  ENSURE_INDEX_VALUE(aIndex, mArgc);
 
-    *_retval = sqlite3_value_int (mArgv[aIndex]);
+  int t = ::sqlite3_value_type(mArgv[aIndex]);
+  switch (t) {
+    case SQLITE_INTEGER:
+      *_type = VALUE_TYPE_INTEGER;
+      break;
+    case SQLITE_FLOAT:
+      *_type = VALUE_TYPE_FLOAT;
+      break;
+    case SQLITE_TEXT:
+      *_type = VALUE_TYPE_TEXT;
+      break;
+    case SQLITE_BLOB:
+      *_type = VALUE_TYPE_BLOB;
+      break;
+    case SQLITE_NULL:
+      *_type = VALUE_TYPE_NULL;
+      break;
+    default:
+      return NS_ERROR_FAILURE;
+  }
 
-    return NS_OK;
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetInt64(PRUint32 aIndex, PRInt64 *_retval)
+ArgValueArray::GetInt32(PRUint32 aIndex,
+                        PRInt32 *_value)
 {
-    if (aIndex < 0 || aIndex >= mArgc)
-        return NS_ERROR_ILLEGAL_VALUE;
+  ENSURE_INDEX_VALUE(aIndex, mArgc);
 
-    *_retval = sqlite3_value_int64 (mArgv[aIndex]);
-
-    return NS_OK;
+  *_value = ::sqlite3_value_int(mArgv[aIndex]);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetDouble(PRUint32 aIndex, double *_retval)
+ArgValueArray::GetInt64(PRUint32 aIndex,
+                        PRInt64 *_value)
 {
-    if (aIndex < 0 || aIndex >= mArgc)
-        return NS_ERROR_ILLEGAL_VALUE;
+  ENSURE_INDEX_VALUE(aIndex, mArgc);
+
+  *_value = ::sqlite3_value_int64(mArgv[aIndex]);
+  return NS_OK;
+}
 
-    *_retval = sqlite3_value_double (mArgv[aIndex]);
+NS_IMETHODIMP
+ArgValueArray::GetDouble(PRUint32 aIndex,
+                         double *_value)
+{
+  ENSURE_INDEX_VALUE(aIndex, mArgc);
 
-    return NS_OK;
+  *_value = ::sqlite3_value_double(mArgv[aIndex]);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetUTF8String(PRUint32 aIndex, nsACString & _retval)
+ArgValueArray::GetUTF8String(PRUint32 aIndex,
+                             nsACString &_value)
 {
-    if (aIndex < 0 || aIndex >= mArgc)
-        return NS_ERROR_ILLEGAL_VALUE;
+  ENSURE_INDEX_VALUE(aIndex, mArgc);
 
-    if (sqlite3_value_type (mArgv[aIndex]) == SQLITE_NULL) {
-        // null columns get IsVoid set to distinguish them from empty strings
-        _retval.Truncate(0);
-        _retval.SetIsVoid(PR_TRUE);
-    } else {
-        int slen = sqlite3_value_bytes (mArgv[aIndex]);
-        const unsigned char *cstr = sqlite3_value_text (mArgv[aIndex]);
-        _retval.Assign ((char *) cstr, slen);
-    }
-    return NS_OK;
+  if (::sqlite3_value_type(mArgv[aIndex]) == SQLITE_NULL) {
+    // NULL columns should have IsVoid set to distinguish them from an empty
+    // string.
+    _value.Truncate(0);
+    _value.SetIsVoid(PR_TRUE);
+  }
+  else {
+    _value.Assign(reinterpret_cast<const char *>(::sqlite3_value_text(mArgv[aIndex])),
+                  ::sqlite3_value_bytes(mArgv[aIndex]));
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetString(PRUint32 aIndex, nsAString & _retval)
+ArgValueArray::GetString(PRUint32 aIndex,
+                         nsAString &_value)
 {
-    if (aIndex < 0 || aIndex >= mArgc)
-        return NS_ERROR_ILLEGAL_VALUE;
+  ENSURE_INDEX_VALUE(aIndex, mArgc);
 
-    if (sqlite3_value_type (mArgv[aIndex]) == SQLITE_NULL) {
-        // null columns get IsVoid set to distinguish them from empty strings
-        _retval.Truncate(0);
-        _retval.SetIsVoid(PR_TRUE);
-    } else {
-        int slen = sqlite3_value_bytes16 (mArgv[aIndex]);
-        const PRUnichar *wstr = (const PRUnichar *) sqlite3_value_text16 (mArgv[aIndex]);
-        _retval.Assign (wstr, slen/2);
-    }
-    return NS_OK;
+  if (::sqlite3_value_type(mArgv[aIndex]) == SQLITE_NULL) {
+    // NULL columns should have IsVoid set to distinguish them from an empty
+    // string.
+    _value.Truncate(0);
+    _value.SetIsVoid(PR_TRUE);
+  } else {
+    _value.Assign(static_cast<const PRUnichar *>(::sqlite3_value_text16(mArgv[aIndex])),
+                  ::sqlite3_value_bytes16(mArgv[aIndex]) / 2);
+  }
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetBlob(PRUint32 aIndex, PRUint32 *aDataSize, PRUint8 **aData)
+ArgValueArray::GetBlob(PRUint32 aIndex,
+                       PRUint32 *_size, PRUint8 **_blob)
 {
-    if (aIndex < 0 || aIndex >= mArgc)
-        return NS_ERROR_ILLEGAL_VALUE;
-
-    int blobsize = sqlite3_value_bytes (mArgv[aIndex]);
-    const void *blob = sqlite3_value_blob (mArgv[aIndex]);
+  ENSURE_INDEX_VALUE(aIndex, mArgc);
 
-    void *blobcopy = nsMemory::Clone(blob, blobsize);
-    if (blobcopy == NULL)
-        return NS_ERROR_OUT_OF_MEMORY;
+  int size = ::sqlite3_value_bytes(mArgv[aIndex]);
+  void *blob = nsMemory::Clone(::sqlite3_value_blob(mArgv[aIndex]), size);
+  NS_ENSURE_TRUE(blob, NS_ERROR_OUT_OF_MEMORY);
 
-    *aData = (PRUint8*) blobcopy;
-    *aDataSize = blobsize;
-
-    return NS_OK;
+  *_blob = static_cast<PRUint8 *>(blob);
+  *_size = size;
+  return NS_OK;
 }
 
-/* boolean getIsNull (in unsigned long aIndex); */
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetIsNull(PRUint32 aIndex, PRBool *_retval)
+ArgValueArray::GetIsNull(PRUint32 aIndex,
+                         PRBool *_isNull)
 {
-    // GetTypeOfIndex will check aIndex for us, so we don't have to.
-    PRInt32 t;
-    nsresult rv = GetTypeOfIndex (aIndex, &t);
-    NS_ENSURE_SUCCESS(rv, rv);
+  // GetTypeOfIndex will check aIndex for us, so we don't have to.
+  PRInt32 type;
+  nsresult rv = GetTypeOfIndex(aIndex, &type);
+  NS_ENSURE_SUCCESS(rv, rv);
 
-    if (t == VALUE_TYPE_NULL)
-        *_retval = PR_TRUE;
-    else
-        *_retval = PR_FALSE;
-
-    return NS_OK;
+  *_isNull = (type == VALUE_TYPE_NULL);
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetSharedUTF8String(PRUint32 aIndex, PRUint32 *aLength, const char **_retval)
+ArgValueArray::GetSharedUTF8String(PRUint32 aIndex,
+                                   PRUint32 *_length,
+                                   const char **_string)
 {
-    if (aLength) {
-        int slen = sqlite3_value_bytes (mArgv[aIndex]);
-        *aLength = slen;
-    }
+  if (_length)
+    *_length = ::sqlite3_value_bytes(mArgv[aIndex]);
 
-    *_retval = (const char*) sqlite3_value_text (mArgv[aIndex]);
-    return NS_OK;
+  *_string = reinterpret_cast<const char *>(::sqlite3_value_text(mArgv[aIndex]));
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetSharedString(PRUint32 aIndex, PRUint32 *aLength, const PRUnichar **_retval)
+ArgValueArray::GetSharedString(PRUint32 aIndex,
+                               PRUint32 *_length,
+                               const PRUnichar **_string)
 {
-    if (aLength) {
-        int slen = sqlite3_value_bytes16 (mArgv[aIndex]);
-        *aLength = slen;
-    }
+  if (_length)
+    *_length = ::sqlite3_value_bytes(mArgv[aIndex]);
 
-    *_retval = (const PRUnichar*) sqlite3_value_text16 (mArgv[aIndex]);
-    return NS_OK;
+  *_string = static_cast<const PRUnichar *>(::sqlite3_value_text16(mArgv[aIndex]));
+  return NS_OK;
 }
 
 NS_IMETHODIMP
-mozStorageArgvValueArray::GetSharedBlob(PRUint32 aIndex, PRUint32 *aDataSize, const PRUint8 **aData)
+ArgValueArray::GetSharedBlob(PRUint32 aIndex,
+                             PRUint32 *_size,
+                             const PRUint8 **_blob)
 {
-    *aDataSize = sqlite3_value_bytes (mArgv[aIndex]);
-    *aData = (const PRUint8*) sqlite3_value_blob (mArgv[aIndex]);
+  *_size = ::sqlite3_value_bytes(mArgv[aIndex]);
+  *_blob = static_cast<const PRUint8 *>(::sqlite3_value_blob(mArgv[aIndex]));
+  return NS_OK;
+}
 
-    return NS_OK;
-}
+} // namespace storage
+} // namespace mozilla
rename from storage/src/mozStorageValueArray.h
rename to storage/src/mozStorageArgValueArray.h
--- a/storage/src/mozStorageValueArray.h
+++ b/storage/src/mozStorageArgValueArray.h
@@ -1,10 +1,11 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/* ***** BEGIN LICENSE BLOCK *****
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 et lcs=trail\:.,tab\:>~ :
+ * ***** BEGIN LICENSE BLOCK *****
  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
  *
  * The contents of this file are subject to the Mozilla Public License Version
  * 1.1 (the "License"); you may not use this file except in compliance with
  * the License. You may obtain a copy of the License at
  * http://www.mozilla.org/MPL/
  *
  * Software distributed under the License is distributed on an "AS IS" basis,
@@ -31,31 +32,35 @@
  * use your version of this file under the terms of the MPL, indicate your
  * decision by deleting the provisions above and replace them with the notice
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * 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 _MOZSTORAGEVALUEARRAY_H_
-#define _MOZSTORAGEVALUEARRAY_H_
+#ifndef _mozStorageArgValueArray_h_
+#define _mozStorageArgValueArray_h_
 
 #include "mozIStorageValueArray.h"
 
 #include <sqlite3.h>
 
-class mozStorageArgvValueArray : public mozIStorageValueArray
+namespace mozilla {
+namespace storage {
+
+class ArgValueArray : public mozIStorageValueArray
 {
 public:
-    mozStorageArgvValueArray (PRInt32 aArgc, sqlite3_value **aArgv);
-    ~mozStorageArgvValueArray();
+  ArgValueArray(PRInt32 aArgc, sqlite3_value **aArgv);
 
-    // interfaces
-    NS_DECL_ISUPPORTS
-    NS_DECL_MOZISTORAGEVALUEARRAY
+  NS_DECL_ISUPPORTS
+  NS_DECL_MOZISTORAGEVALUEARRAY
 
 private:
-    PRUint32 mArgc;
-    sqlite3_value **mArgv;
+  PRUint32 mArgc;
+  sqlite3_value **mArgv;
 };
 
-#endif /* _MOZSTORAGEVALUEARRAY_H_ */
+} // namespace storage
+} // namespace mozilla
+
+#endif // _mozStorageArgValueArray_h_
--- a/storage/src/mozStorageConnection.cpp
+++ b/storage/src/mozStorageConnection.cpp
@@ -55,17 +55,17 @@
 #include "mozIStorageAggregateFunction.h"
 #include "mozIStorageFunction.h"
 
 #include "mozStorageEvents.h"
 #include "mozStorageSQLFunctions.h"
 #include "mozStorageConnection.h"
 #include "mozStorageService.h"
 #include "mozStorageStatement.h"
-#include "mozStorageValueArray.h"
+#include "mozStorageArgValueArray.h"
 #include "mozStoragePrivateHelpers.h"
 
 #include "prlog.h"
 #include "prprf.h"
 
 #ifdef PR_LOGGING
 PRLogModuleInfo* gStorageLog = nsnull;
 #endif
@@ -201,18 +201,17 @@ void
 basicFunctionHelper(sqlite3_context *aCtx,
                     int aArgc,
                     sqlite3_value **aArgv)
 {
   void *userData = ::sqlite3_user_data(aCtx);
 
   mozIStorageFunction *func = static_cast<mozIStorageFunction *>(userData);
 
-  nsRefPtr<mozStorageArgvValueArray> arguments =
-    new mozStorageArgvValueArray(aArgc, aArgv);
+  nsRefPtr<ArgValueArray> arguments(new ArgValueArray(aArgc, aArgv));
   if (!arguments)
       return;
 
   nsCOMPtr<nsIVariant> result;
   if (NS_FAILED(func->OnFunctionCall(arguments, getter_AddRefs(result)))) {
     NS_WARNING("User function returned error code!");
     ::sqlite3_result_error(aCtx,
                            "User function returned error code",
@@ -231,18 +230,17 @@ void
 aggregateFunctionStepHelper(sqlite3_context *aCtx,
                             int aArgc,
                             sqlite3_value **aArgv)
 {
   void *userData = ::sqlite3_user_data(aCtx);
   mozIStorageAggregateFunction *func =
     static_cast<mozIStorageAggregateFunction *>(userData);
 
-  nsRefPtr<mozStorageArgvValueArray> arguments =
-    new mozStorageArgvValueArray(aArgc, aArgv);
+  nsRefPtr<ArgValueArray> arguments(new ArgValueArray(aArgc, aArgv));
   if (!arguments)
     return;
 
   if (NS_FAILED(func->OnStep(arguments)))
     NS_WARNING("User aggregate step function returned error code!");
 }
 
 void
--- a/storage/src/mozStorageStatement.cpp
+++ b/storage/src/mozStorageStatement.cpp
@@ -45,17 +45,16 @@
 #include "nsError.h"
 #include "nsISimpleEnumerator.h"
 #include "nsMemory.h"
 #include "nsIClassInfoImpl.h"
 #include "nsIProgrammingLanguage.h"
 
 #include "mozStorageConnection.h"
 #include "mozStorageStatementJSHelper.h"
-#include "mozStorageValueArray.h"
 #include "mozStoragePrivateHelpers.h"
 #include "mozStorageEvents.h"
 #include "mozStorageStatementParams.h"
 #include "mozStorageStatementRow.h"
 #include "mozStorageStatement.h"
 
 #include "prlog.h"