| 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 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 48 static IDBKey* createBinary(PassRefPtr<SharedBuffer> binary) { | 48 static IDBKey* createBinary(PassRefPtr<SharedBuffer> binary) { |
| 49 return new IDBKey(std::move(binary)); | 49 return new IDBKey(std::move(binary)); |
| 50 } | 50 } |
| 51 | 51 |
| 52 static IDBKey* createString(const String& string) { | 52 static IDBKey* createString(const String& string) { |
| 53 return new IDBKey(string); | 53 return new IDBKey(string); |
| 54 } | 54 } |
| 55 | 55 |
| 56 static IDBKey* createDate(double date) { return new IDBKey(DateType, date); } | 56 static IDBKey* createDate(double date) { return new IDBKey(DateType, date); } |
| 57 | 57 |
| 58 static IDBKey* createMultiEntryArray(const KeyArray& array) { | |
| 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 | |
| 81 static IDBKey* createArray(const KeyArray& array) { | 58 static IDBKey* createArray(const KeyArray& array) { |
| 82 return new IDBKey(array); | 59 return new IDBKey(array); |
| 83 } | 60 } |
| 84 | 61 |
| 85 ~IDBKey(); | 62 ~IDBKey(); |
| 86 DECLARE_TRACE(); | 63 DECLARE_TRACE(); |
| 87 | 64 |
| 88 // In order of the least to the highest precedent in terms of sort order. | 65 // In order of the least to the highest precedent in terms of sort order. |
| 89 enum Type { | 66 enum Type { |
| 90 InvalidType = 0, | 67 InvalidType = 0, |
| (...skipping 30 matching lines...) Expand all Loading... |
| 121 | 98 |
| 122 double number() const { | 99 double number() const { |
| 123 ASSERT(m_type == NumberType); | 100 ASSERT(m_type == NumberType); |
| 124 return m_number; | 101 return m_number; |
| 125 } | 102 } |
| 126 | 103 |
| 127 int compare(const IDBKey* other) const; | 104 int compare(const IDBKey* other) const; |
| 128 bool isLessThan(const IDBKey* other) const; | 105 bool isLessThan(const IDBKey* other) const; |
| 129 bool isEqual(const IDBKey* other) const; | 106 bool isEqual(const IDBKey* other) const; |
| 130 | 107 |
| 108 // Returns a new key array with invalid keys and duplicates removed. |
| 109 KeyArray toMultiEntryArray() const; |
| 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) {} |
| 139 | 119 |
| 140 const Type m_type; | 120 const Type m_type; |
| 141 const KeyArray m_array; | 121 const KeyArray m_array; |
| 142 RefPtr<SharedBuffer> m_binary; | 122 RefPtr<SharedBuffer> m_binary; |
| 143 const String m_string; | 123 const String m_string; |
| 144 const double m_number = 0; | 124 const double m_number = 0; |
| 145 }; | 125 }; |
| 146 | 126 |
| 147 } // namespace blink | 127 } // namespace blink |
| 148 | 128 |
| 149 #endif // IDBKey_h | 129 #endif // IDBKey_h |
| OLD | NEW |