Bug 483880 - Pull out implementation of mozStorageVariant_base so we can include it in more than one file
authorShawn Wilsher <sdwilsh@shawnwilsher.com>
Fri, 20 Mar 2009 16:28:16 -0400
changeset 26423 762b098aed655532d406d052d78ef693d99832c1
parent 26422 56722f4fc2f64e8cfb5116f664e12a6a4376b11e
child 26424 3aba63a26a48c3215fa87b9dc81a5accb11c99be
push id6060
push usersdwilsh@shawnwilsher.com
push dateFri, 20 Mar 2009 20:28:48 +0000
treeherdermozilla-central@762b098aed65 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
bugs483880
milestone1.9.2a1pre
Bug 483880 - Pull out implementation of mozStorageVariant_base so we can include it in more than one file The current implementation means it can only be #included once, which makes it not terribly useful for other consumers. r=asuth
storage/src/Makefile.in
storage/src/mozStorageVariant.cpp
storage/src/mozStorageVariant.h
--- a/storage/src/Makefile.in
+++ b/storage/src/Makefile.in
@@ -71,16 +71,17 @@ CPPSRCS = \
   mozStorageValueArray.cpp \
   mozStorageUnicodeFunctions.cpp \
   mozStorageRow.cpp \
   mozStorageResultSet.cpp \
   mozStorageError.cpp \
   mozStorageEvents.cpp \
   mozStorageStatementJSHelper.cpp \
   mozStoragePrivateHelpers.cpp \
+  mozStorageVariant.cpp \
   $(NULL)
 
 LOCAL_INCLUDES = \
 	$(SQLITE_CFLAGS)
 
 # This is the default value.  If we ever change it when compiling sqlite, we
 # will need to change it here as well.
 DEFINES += -DSQLITE_MAX_LIKE_PATTERN_LENGTH=50000
new file mode 100644
--- /dev/null
+++ b/storage/src/mozStorageVariant.cpp
@@ -0,0 +1,208 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
+ * vim: sw=2 ts=2 sts=2 expandtab
+ * ***** 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,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * Mozilla Corporation
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Shawn Wilsher <me@shawnwilsher.com> (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * 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 ***** */
+
+#include "mozStorageVariant.h"
+
+////////////////////////////////////////////////////////////////////////////////
+//// mozStorageVariant_base
+
+NS_IMPL_THREADSAFE_ISUPPORTS1(
+  mozStorageVariant_base,
+  nsIVariant
+)
+
+////////////////////////////////////////////////////////////////////////////////
+//// nsIVariant
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetDataType(PRUint16 *_type)
+{
+  *_type = nsIDataType::VTYPE_EMPTY;
+  return NS_OK;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsInt32(PRInt32 *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsInt64(PRInt64 *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsDouble(double *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsAUTF8String(nsACString &)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsAString(nsAString &)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsArray(PRUint16 *, nsIID *, PRUint32 *, void **)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsInt8(PRUint8 *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsInt16(PRInt16 *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsUint8(PRUint8 *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsUint16(PRUint16 *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsUint32(PRUint32 *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsUint64(PRUint64 *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsFloat(float *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsBool(PRBool *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsChar(char *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsWChar(PRUnichar *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsID(nsID *)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsDOMString(nsAString &)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsString(char **)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsWString(PRUnichar **)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsISupports(nsISupports **)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsInterface(nsIID **, void **)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsACString(nsACString &)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsStringWithSize(PRUint32 *, char **)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
+
+NS_IMETHODIMP
+mozStorageVariant_base::GetAsWStringWithSize(PRUint32 *, PRUnichar **)
+{
+  return NS_ERROR_CANNOT_CONVERT_DATA;
+}
--- a/storage/src/mozStorageVariant.h
+++ b/storage/src/mozStorageVariant.h
@@ -35,81 +35,46 @@
  * 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 __mozStorageVariant_h__
 #define __mozStorageVariant_h__
 
+#include <utility>
+
 #include "nsIVariant.h"
+#include "nsString.h"
 #include "nsTArray.h"
-#include <utility>
 
 /**
  * This class is used by the storage module whenever an nsIVariant needs to be
  * returned.  We provide traits for the basic sqlite types to make use easier.
  * The following types map to the indicated sqlite type:
  * PRInt64   -> INTEGER (use mozStorageInteger)
  * double    -> FLOAT (use mozStorageFloat)
  * nsString  -> TEXT (use mozStorageText)
  * nsCString -> TEXT (use mozStorageUTF8Text)
  * PRUint8[] -> BLOB (use mozStorageBlob)
  * nsnull    -> NULL (use mozStorageNull)
  */
 
-#define NO_CONVERSION return NS_ERROR_CANNOT_CONVERT_DATA;
-
 ////////////////////////////////////////////////////////////////////////////////
 //// Base Class
 
 class mozStorageVariant_base : public nsIVariant
 {
 public:
   NS_DECL_ISUPPORTS
-
-  NS_IMETHOD GetDataType(PRUint16 *_type)
-  {
-    *_type = nsIDataType::VTYPE_EMPTY;
-    return NS_OK;
-  }
-
-  NS_IMETHOD GetAsInt32(PRInt32 *_integer) { NO_CONVERSION }
-  NS_IMETHOD GetAsInt64(PRInt64 *) { NO_CONVERSION }
-  NS_IMETHOD GetAsDouble(double *) { NO_CONVERSION }
-  NS_IMETHOD GetAsAUTF8String(nsACString &) { NO_CONVERSION }
-  NS_IMETHOD GetAsAString(nsAString &) { NO_CONVERSION }
-  NS_IMETHOD GetAsArray(PRUint16 *, nsIID *, PRUint32 *, void **) { NO_CONVERSION }
-  NS_IMETHOD GetAsInt8(PRUint8 *) { NO_CONVERSION }
-  NS_IMETHOD GetAsInt16(PRInt16 *) { NO_CONVERSION }
-  NS_IMETHOD GetAsUint8(PRUint8 *) { NO_CONVERSION }
-  NS_IMETHOD GetAsUint16(PRUint16 *) { NO_CONVERSION }
-  NS_IMETHOD GetAsUint32(PRUint32 *) { NO_CONVERSION }
-  NS_IMETHOD GetAsUint64(PRUint64 *) { NO_CONVERSION }
-  NS_IMETHOD GetAsFloat(float *) { NO_CONVERSION }
-  NS_IMETHOD GetAsBool(PRBool *) { NO_CONVERSION }
-  NS_IMETHOD GetAsChar(char *) { NO_CONVERSION }
-  NS_IMETHOD GetAsWChar(PRUnichar *) { NO_CONVERSION }
-  NS_IMETHOD GetAsID(nsID *) { NO_CONVERSION }
-  NS_IMETHOD GetAsDOMString(nsAString &) { NO_CONVERSION }
-  NS_IMETHOD GetAsString(char **) { NO_CONVERSION }
-  NS_IMETHOD GetAsWString(PRUnichar **) { NO_CONVERSION }
-  NS_IMETHOD GetAsISupports(nsISupports **) { NO_CONVERSION }
-  NS_IMETHOD GetAsInterface(nsIID **, void **) { NO_CONVERSION }
-  NS_IMETHOD GetAsACString(nsACString &) { NO_CONVERSION }
-  NS_IMETHOD GetAsStringWithSize(PRUint32 *, char **) { NO_CONVERSION }
-  NS_IMETHOD GetAsWStringWithSize(PRUint32 *, PRUnichar **) { NO_CONVERSION }
+  NS_DECL_NSIVARIANT
 
 protected:
   virtual ~mozStorageVariant_base() { }
 };
-NS_IMPL_THREADSAFE_ISUPPORTS1(
-  mozStorageVariant_base,
-  nsIVariant
-)
 
 ////////////////////////////////////////////////////////////////////////////////
 //// Traits
 
 /**
  * Generics
  */
 
@@ -122,16 +87,18 @@ struct variant_traits
 template <typename DataType>
 struct variant_storage_traits
 {
   typedef DataType ConstructorType;
   typedef DataType StorageType;
   static inline StorageType storage_conversion(ConstructorType aData) { return aData; }
 };
 
+#define NO_CONVERSION return NS_ERROR_CANNOT_CONVERT_DATA;
+
 template <typename DataType>
 struct variant_integer_traits
 {
   typedef typename variant_storage_traits<DataType>::StorageType StorageType;
   static inline nsresult asInt32(StorageType, PRInt32 *) { NO_CONVERSION }
   static inline nsresult asInt64(StorageType, PRInt64 *) { NO_CONVERSION }
 };
 
@@ -153,16 +120,18 @@ struct variant_text_traits
 template <typename DataType>
 struct variant_blob_traits
 {
   typedef typename variant_storage_traits<DataType>::StorageType StorageType;
   static inline nsresult asArray(StorageType, PRUint16 *, PRUint32 *, void **)
   { NO_CONVERSION }
 };
 
+#undef NO_CONVERSION
+
 /**
  * INTEGER types
  */
 
 template < >
 struct variant_traits<PRInt64>
 {
   static inline PRUint16 type() { return nsIDataType::VTYPE_INT64; }