Introducing WTF::TypeSafeEnum and DatabaseError.
authormark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jan 2013 05:17:40 +0000 (05:17 +0000)
committermark.lam@apple.com <mark.lam@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 30 Jan 2013 05:17:40 +0000 (05:17 +0000)
https://bugs.webkit.org/show_bug.cgi?id=108279.

Reviewed by Geoffrey Garen.

Source/WebCore:

DatabaseError will be used later in the webdatabase refactoring effort.
It is currently unused.

No new tests.

* GNUmakefile.list.am:
* Modules/webdatabase/DatabaseError.h: Added.
(WebCore):
* Target.pri:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.vcxproj/WebCore.vcxproj:
* WebCore.vcxproj/WebCore.vcxproj.filters:
* WebCore.xcodeproj/project.pbxproj:

Source/WTF:

* WTF.xcodeproj/project.pbxproj:
* wtf/TypeSafeEnum.h: Added.
(WTF):
(TypeSafeEnum):
(WTF::TypeSafeEnum::TypeSafeEnum):
(WTF::TypeSafeEnum::value):
(WTF::TypeSafeEnum::operator==):
(WTF::TypeSafeEnum::operator!=):
(WTF::TypeSafeEnum::operator<):
(WTF::TypeSafeEnum::operator<=):
(WTF::TypeSafeEnum::operator>):
(WTF::TypeSafeEnum::operator>=):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@141219 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/WTF.xcodeproj/project.pbxproj
Source/WTF/wtf/TypeSafeEnum.h [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Modules/webdatabase/DatabaseError.h [new file with mode: 0644]
Source/WebCore/Target.pri
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj
Source/WebCore/WebCore.vcxproj/WebCore.vcxproj.filters
Source/WebCore/WebCore.xcodeproj/project.pbxproj

index ae01f90..64f38f2 100644 (file)
@@ -1,3 +1,23 @@
+2013-01-29  Mark Lam  <mark.lam@apple.com>
+
+        Introducing WTF::TypeSafeEnum and DatabaseError.
+        https://bugs.webkit.org/show_bug.cgi?id=108279.
+
+        Reviewed by Geoffrey Garen.
+
+        * WTF.xcodeproj/project.pbxproj:
+        * wtf/TypeSafeEnum.h: Added.
+        (WTF):
+        (TypeSafeEnum):
+        (WTF::TypeSafeEnum::TypeSafeEnum):
+        (WTF::TypeSafeEnum::value):
+        (WTF::TypeSafeEnum::operator==):
+        (WTF::TypeSafeEnum::operator!=):
+        (WTF::TypeSafeEnum::operator<):
+        (WTF::TypeSafeEnum::operator<=):
+        (WTF::TypeSafeEnum::operator>):
+        (WTF::TypeSafeEnum::operator>=):
+
 2013-01-29  Sheriff Bot  <webkit.review.bot@gmail.com>
 
         Unreviewed, rolling out r140983.
index 999f4c9..9ff3239 100644 (file)
                F3FBC720161AF7CD00BB4BD4 /* MemoryInstrumentationSequence.h in Headers */ = {isa = PBXBuildFile; fileRef = F3FBC71F161AF7CD00BB4BD4 /* MemoryInstrumentationSequence.h */; };
                FEDACD3D1630F83F00C69634 /* StackStats.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEDACD3B1630F83F00C69634 /* StackStats.cpp */; };
                FEDACD3E1630F83F00C69634 /* StackStats.h in Headers */ = {isa = PBXBuildFile; fileRef = FEDACD3C1630F83F00C69634 /* StackStats.h */; };
+               FE43302716A7ADC300D1585D /* TypeSafeEnum.h in Headers */ = {isa = PBXBuildFile; fileRef = FE43302616A7ADC300D1585D /* TypeSafeEnum.h */; };
 /* End PBXBuildFile section */
 
 /* Begin PBXContainerItemProxy section */
                F3FBC71F161AF7CD00BB4BD4 /* MemoryInstrumentationSequence.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MemoryInstrumentationSequence.h; sourceTree = "<group>"; };
                FEDACD3B1630F83F00C69634 /* StackStats.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = StackStats.cpp; sourceTree = "<group>"; };
                FEDACD3C1630F83F00C69634 /* StackStats.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StackStats.h; sourceTree = "<group>"; };
+               FE43302616A7ADC300D1585D /* TypeSafeEnum.h */ = {isa = PBXFileReference; fileEncoding = 4; path = TypeSafeEnum.h; sourceTree = "<group>"; };
 /* End PBXFileReference section */
 
 /* Begin PBXFrameworksBuildPhase section */
                                A8A4733E151A825B004123FF /* ThreadSafeRefCounted.h */,
                                A8A4733F151A825B004123FF /* ThreadSpecific.h */,
                                A8A47341151A825B004123FF /* TypedArrayBase.h */,
+                               FE43302616A7ADC300D1585D /* TypeSafeEnum.h */,
                                A8A47342151A825B004123FF /* TypeTraits.cpp */,
                                A8A47343151A825B004123FF /* TypeTraits.h */,
                                A8A47346151A825B004123FF /* Uint16Array.h */,
                                A8A47454151A825B004123FF /* ThreadSafeRefCounted.h in Headers */,
                                A8A47455151A825B004123FF /* ThreadSpecific.h in Headers */,
                                A8A47457151A825B004123FF /* TypedArrayBase.h in Headers */,
+                               FE43302716A7ADC300D1585D /* TypeSafeEnum.h in Headers */,
                                A8A47459151A825B004123FF /* TypeTraits.h in Headers */,
                                A8A4745C151A825B004123FF /* Uint16Array.h in Headers */,
                                A8A4745D151A825B004123FF /* Uint32Array.h in Headers */,
diff --git a/Source/WTF/wtf/TypeSafeEnum.h b/Source/WTF/wtf/TypeSafeEnum.h
new file mode 100644 (file)
index 0000000..b600c9a
--- /dev/null
@@ -0,0 +1,78 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef WTF_TypeSafeEnum_h
+#define WTF_TypeSafeEnum_h
+
+namespace WTF {
+
+// How to define a type safe enum list using TypeSafeEnum?
+// ======================================================
+// Definition should be a struct that encapsulates an enum list.
+// The enum list should be names Enums.
+//
+// Here's an example of how to define a type safe enum named MyEnum using
+// the TypeSafeEnum template:
+//
+//     struct MyEnumDefinition {
+//         enum Enums {
+//             ValueDefault,
+//             Value1,
+//             ...
+//             ValueN
+//         };
+//     };
+//     typedef TypeSafeEnum<MyEnumDefinition, MyEnumDefinition::ValueDefault> MyEnum;
+//
+// With that, you can now use MyEnum enum values as follow:
+//
+//     MyEnum value1; // value1 is assigned MyEnum::ValueDefault by default.
+//     MyEnum value2 = MyEnum::Value1; // value2 is assigned MyEnum::Value1;
+
+template <typename Definition, typename Definition::Enums defaultValue>
+class TypeSafeEnum : public Definition {
+    typedef enum Definition::Enums Value;
+public:
+    ALWAYS_INLINE TypeSafeEnum() : m_value(defaultValue) { }
+    ALWAYS_INLINE TypeSafeEnum(Value value) : m_value(value) { }
+
+    ALWAYS_INLINE Value value() const { return m_value; }
+
+    ALWAYS_INLINE bool operator==(const TypeSafeEnum other) { return m_value == other.m_value; }
+    ALWAYS_INLINE bool operator!=(const TypeSafeEnum other) { return m_value != other.m_value; }
+    ALWAYS_INLINE bool operator<(const TypeSafeEnum other) { return m_value < other.m_value; }
+    ALWAYS_INLINE bool operator<=(const TypeSafeEnum other) { return m_value <= other.m_value; }
+    ALWAYS_INLINE bool operator>(const TypeSafeEnum other) { return m_value > other.m_value; }
+    ALWAYS_INLINE bool operator>=(const TypeSafeEnum other) { return m_value >= other.m_value; }
+
+private:
+    Value m_value;
+};
+
+} // namespace WTF
+
+using WTF::TypeSafeEnum;
+
+#endif // WTF_TypeSafeEnum_h
index 5bbf471..46396e2 100644 (file)
@@ -1,3 +1,24 @@
+2013-01-29  Mark Lam  <mark.lam@apple.com>
+
+        Introducing WTF::TypeSafeEnum and DatabaseError.
+        https://bugs.webkit.org/show_bug.cgi?id=108279.
+
+        Reviewed by Geoffrey Garen.
+
+        DatabaseError will be used later in the webdatabase refactoring effort.
+        It is currently unused.
+
+        No new tests.
+
+        * GNUmakefile.list.am:
+        * Modules/webdatabase/DatabaseError.h: Added.
+        (WebCore):
+        * Target.pri:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.vcxproj/WebCore.vcxproj:
+        * WebCore.vcxproj/WebCore.vcxproj.filters:
+        * WebCore.xcodeproj/project.pbxproj:
+
 2013-01-29  Elliott Sprehn  <esprehn@chromium.org>
 
         Move ShadowRoot creation into ElementShadow
index ece2449..0fba6cd 100644 (file)
@@ -2108,6 +2108,7 @@ webcore_modules_sources += \
        Source/WebCore/Modules/webdatabase/DatabaseContext.cpp \
        Source/WebCore/Modules/webdatabase/DatabaseContext.h \
        Source/WebCore/Modules/webdatabase/DatabaseDetails.h \
+       Source/WebCore/Modules/webdatabase/DatabaseError.h \
        Source/WebCore/Modules/webdatabase/DatabaseManager.cpp \
        Source/WebCore/Modules/webdatabase/DatabaseManager.h \
        Source/WebCore/Modules/webdatabase/DatabaseManagerClient.h \
diff --git a/Source/WebCore/Modules/webdatabase/DatabaseError.h b/Source/WebCore/Modules/webdatabase/DatabaseError.h
new file mode 100644 (file)
index 0000000..3824151
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
+ */
+
+#ifndef DatabaseError_h
+#define DatabaseError_h
+
+#if ENABLE(SQL_DATABASE)
+
+#include <wtf/TypeSafeEnum.h>
+
+namespace WebCore {
+
+struct DatabaseErrorDefinition {
+    enum Enums {
+        None = 0,
+        CannotOpenDatabase,
+        DatabaseIsBeingDeleted,
+        DatabaseSizeExceededQuota,
+        DatabaseSizeOverflowed
+    };
+};
+
+typedef TypeSafeEnum<DatabaseErrorDefinition, DatabaseErrorDefinition::None> DatabaseError;
+
+} // namespace WebCore
+
+#endif // ENABLE(SQL_DATABASE)
+
+#endif // DatabaseError_h
index d65a70c..44f02b6 100644 (file)
@@ -1441,6 +1441,7 @@ HEADERS += \
     Modules/webdatabase/Database.h \
     Modules/webdatabase/DatabaseBackend.h \
     Modules/webdatabase/DatabaseCallback.h \
+    Modules/webdatabase/DatabaseError.h \
     Modules/webdatabase/DatabaseManager.h \
     Modules/webdatabase/DatabaseServer.h \
     Modules/webdatabase/DatabaseSync.h \
index 39194be..052fb40 100755 (executable)
                                        >
                                </File>
                                <File
+                                       RelativePath="..\Modules\webdatabase\DatabaseError.h"
+                                       >
+                               </File>
+                               <File
                                        RelativePath="..\Modules\webdatabase\DatabaseManager.cpp"
                                        >
                                </File>
index d746385..95a2db5 100644 (file)
     <ClInclude Include="..\Modules\webdatabase\DatabaseBackend.h" />
     <ClInclude Include="..\Modules\webdatabase\DatabaseCallback.h" />
     <ClInclude Include="..\Modules\webdatabase\DatabaseContext.h" />
+    <ClInclude Include="..\Modules\webdatabase\DatabaseError.h" />
     <ClInclude Include="..\Modules\webdatabase\DatabaseManager.h" />
     <ClInclude Include="..\Modules\webdatabase\DatabaseServer.h" />
     <ClInclude Include="..\Modules\webdatabase\DatabaseSync.h" />
index 2f7b9c1..92a499c 100644 (file)
     <ClInclude Include="..\Modules\webdatabase\DatabaseContext.h">
       <Filter>Modules\webdatabase</Filter>
     </ClInclude>
+    <ClInclude Include="..\Modules\webdatabase\DatabaseError.h">
+      <Filter>Modules\webdatabase</Filter>
+    </ClInclude>
     <ClInclude Include="..\Modules\webdatabase\DatabaseManager.h">
       <Filter>Modules\webdatabase</Filter>
     </ClInclude>
index 788251c..7c6ec98 100644 (file)
                97BC6A271505F081001B74AC /* DatabaseContext.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97BC69E51505F081001B74AC /* DatabaseContext.cpp */; };
                97BC6A281505F081001B74AC /* DatabaseContext.h in Headers */ = {isa = PBXBuildFile; fileRef = 97BC69E61505F081001B74AC /* DatabaseContext.h */; settings = {ATTRIBUTES = (Private, ); }; };
                97BC6A291505F081001B74AC /* DatabaseDetails.h in Headers */ = {isa = PBXBuildFile; fileRef = 97BC69E71505F081001B74AC /* DatabaseDetails.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               FE09DB49169E2D6E00622557 /* DatabaseError.h in Headers */ = {isa = PBXBuildFile; fileRef = FE09DB46169E2D6E00622557 /* DatabaseError.h */; settings = {ATTRIBUTES = (Private, ); }; };
                FEB26D28167A8F2A00FDD26B /* DatabaseServer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FEB26D27167A8F2A00FDD26B /* DatabaseServer.cpp */; };
                FEAF6654167970320062D0C5 /* DatabaseServer.h in Headers */ = {isa = PBXBuildFile; fileRef = FEAF6653167970070062D0C5 /* DatabaseServer.h */; settings = {ATTRIBUTES = (Private, ); }; };
                97BC6A2A1505F081001B74AC /* DatabaseSync.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 97BC69E81505F081001B74AC /* DatabaseSync.cpp */; };
                97BC69E51505F081001B74AC /* DatabaseContext.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DatabaseContext.cpp; path = Modules/webdatabase/DatabaseContext.cpp; sourceTree = "<group>"; };
                97BC69E61505F081001B74AC /* DatabaseContext.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DatabaseContext.h; path = Modules/webdatabase/DatabaseContext.h; sourceTree = "<group>"; };
                97BC69E71505F081001B74AC /* DatabaseDetails.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DatabaseDetails.h; path = Modules/webdatabase/DatabaseDetails.h; sourceTree = "<group>"; };
+               FE09DB46169E2D6E00622557 /* DatabaseError.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DatabaseError.h; path = Modules/webdatabase/DatabaseError.h; sourceTree = "<group>"; };
                FEAF6653167970070062D0C5 /* DatabaseServer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = DatabaseServer.h; path = Modules/webdatabase/DatabaseServer.h; sourceTree = "<group>"; };
                FEB26D27167A8F2A00FDD26B /* DatabaseServer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DatabaseServer.cpp; path = Modules/webdatabase/DatabaseServer.cpp; sourceTree = "<group>"; };
                97BC69E81505F081001B74AC /* DatabaseSync.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = DatabaseSync.cpp; path = Modules/webdatabase/DatabaseSync.cpp; sourceTree = "<group>"; };
                                97BC69E51505F081001B74AC /* DatabaseContext.cpp */,
                                97BC69E61505F081001B74AC /* DatabaseContext.h */,
                                97BC69E71505F081001B74AC /* DatabaseDetails.h */,
+                               FE09DB46169E2D6E00622557 /* DatabaseError.h */,
                                FE456F161677D74E005EDDF9 /* DatabaseManager.cpp */,
                                FE456F171677D74E005EDDF9 /* DatabaseManager.h */,
                                97BC69F11505F081001B74AC /* DatabaseManagerClient.h */,
                                97BC6A251505F081001B74AC /* DatabaseCallback.h in Headers */,
                                97BC6A281505F081001B74AC /* DatabaseContext.h in Headers */,
                                97BC6A291505F081001B74AC /* DatabaseDetails.h in Headers */,
+                               FE09DB49169E2D6E00622557 /* DatabaseError.h in Headers */,
                                FE456F191677D74E005EDDF9 /* DatabaseManager.h in Headers */,
                                97BC6A331505F081001B74AC /* DatabaseManagerClient.h in Headers */,
                                FEAF6654167970320062D0C5 /* DatabaseServer.h in Headers */,