| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * | 7 * |
| 8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 | 25 |
| 26 #ifndef IDBKey_h | 26 #ifndef IDBKey_h |
| 27 #define IDBKey_h | 27 #define IDBKey_h |
| 28 | 28 |
| 29 #include "modules/ModulesExport.h" | 29 #include "modules/ModulesExport.h" |
| 30 #include "platform/SharedBuffer.h" | 30 #include "platform/SharedBuffer.h" |
| 31 #include "platform/heap/Handle.h" | 31 #include "platform/heap/Handle.h" |
| 32 #include "wtf/Forward.h" | 32 #include "wtf/Forward.h" |
| 33 #include "wtf/Vector.h" | 33 #include "wtf/Vector.h" |
| 34 #include "wtf/text/WTFString.h" | 34 #include "wtf/text/WTFString.h" |
| 35 #include <utility> |
| 35 | 36 |
| 36 namespace blink { | 37 namespace blink { |
| 37 | 38 |
| 38 class MODULES_EXPORT IDBKey : public GarbageCollectedFinalized<IDBKey> { | 39 class MODULES_EXPORT IDBKey : public GarbageCollectedFinalized<IDBKey> { |
| 39 public: | 40 public: |
| 40 typedef HeapVector<Member<IDBKey>> KeyArray; | 41 typedef HeapVector<Member<IDBKey>> KeyArray; |
| 41 | 42 |
| 42 static IDBKey* createInvalid() { return new IDBKey(); } | 43 static IDBKey* createInvalid() { return new IDBKey(); } |
| 43 | 44 |
| 44 static IDBKey* createNumber(double number) { | 45 static IDBKey* createNumber(double number) { |
| 45 return new IDBKey(NumberType, number); | 46 return new IDBKey(NumberType, number); |
| 46 } | 47 } |
| 47 | 48 |
| 48 static IDBKey* createBinary(PassRefPtr<SharedBuffer> binary) { | 49 static IDBKey* createBinary(PassRefPtr<SharedBuffer> binary) { |
| 49 return new IDBKey(std::move(binary)); | 50 return new IDBKey(std::move(binary)); |
| 50 } | 51 } |
| 51 | 52 |
| 52 static IDBKey* createString(const String& string) { | 53 static IDBKey* createString(const String& string) { |
| 53 return new IDBKey(string); | 54 return new IDBKey(string); |
| 54 } | 55 } |
| 55 | 56 |
| 56 static IDBKey* createDate(double date) { return new IDBKey(DateType, date); } | 57 static IDBKey* createDate(double date) { return new IDBKey(DateType, date); } |
| 57 | 58 |
| 58 static IDBKey* createMultiEntryArray(const KeyArray& array) { | 59 static IDBKey* createMultiEntryArray(const KeyArray&); |
| 59 KeyArray result; | |
| 60 | |
| 61 for (size_t i = 0; i < array.size(); i++) { | |
| 62 if (!array[i]->isValid()) | |
| 63 continue; | |
| 64 | |
| 65 bool skip = false; | |
| 66 for (size_t j = 0; j < result.size(); j++) { | |
| 67 if (array[i]->isEqual(result[j].get())) { | |
| 68 skip = true; | |
| 69 break; | |
| 70 } | |
| 71 } | |
| 72 if (!skip) { | |
| 73 result.push_back(array[i]); | |
| 74 } | |
| 75 } | |
| 76 IDBKey* idbKey = new IDBKey(result); | |
| 77 ASSERT(idbKey->isValid()); | |
| 78 return idbKey; | |
| 79 } | |
| 80 | 60 |
| 81 static IDBKey* createArray(const KeyArray& array) { | 61 static IDBKey* createArray(const KeyArray& array) { |
| 82 return new IDBKey(array); | 62 return new IDBKey(array); |
| 83 } | 63 } |
| 84 | 64 |
| 85 ~IDBKey(); | 65 ~IDBKey(); |
| 86 DECLARE_TRACE(); | 66 DECLARE_TRACE(); |
| 87 | 67 |
| 88 // In order of the least to the highest precedent in terms of sort order. | 68 // In order of the least to the highest precedent in terms of sort order. |
| 89 enum Type { | 69 enum Type { |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 129 bool isEqual(const IDBKey* other) const; | 109 bool isEqual(const IDBKey* other) const; |
| 130 | 110 |
| 131 private: | 111 private: |
| 132 IDBKey() : m_type(InvalidType) {} | 112 IDBKey() : m_type(InvalidType) {} |
| 133 IDBKey(Type type, double number) : m_type(type), m_number(number) {} | 113 IDBKey(Type type, double number) : m_type(type), m_number(number) {} |
| 134 explicit IDBKey(const String& value) : m_type(StringType), m_string(value) {} | 114 explicit IDBKey(const String& value) : m_type(StringType), m_string(value) {} |
| 135 explicit IDBKey(PassRefPtr<SharedBuffer> value) | 115 explicit IDBKey(PassRefPtr<SharedBuffer> value) |
| 136 : m_type(BinaryType), m_binary(value) {} | 116 : m_type(BinaryType), m_binary(value) {} |
| 137 explicit IDBKey(const KeyArray& keyArray) | 117 explicit IDBKey(const KeyArray& keyArray) |
| 138 : m_type(ArrayType), m_array(keyArray) {} | 118 : m_type(ArrayType), m_array(keyArray) {} |
| 119 explicit IDBKey(KeyArray&& keyArray) |
| 120 : m_type(ArrayType), m_array(std::move(keyArray)) {} |
| 139 | 121 |
| 140 const Type m_type; | 122 const Type m_type; |
| 141 const KeyArray m_array; | 123 const KeyArray m_array; |
| 142 RefPtr<SharedBuffer> m_binary; | 124 RefPtr<SharedBuffer> m_binary; |
| 143 const String m_string; | 125 const String m_string; |
| 144 const double m_number = 0; | 126 const double m_number = 0; |
| 145 }; | 127 }; |
| 146 | 128 |
| 147 } // namespace blink | 129 } // namespace blink |
| 148 | 130 |
| 149 #endif // IDBKey_h | 131 #endif // IDBKey_h |
| OLD | NEW |