Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / content / common / indexed_db / indexed_db_key.h
blobf9618786aa0ac849f04af005ff087757080fd7ce
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CONTENT_COMMON_INDEXED_DB_INDEXED_DB_KEY_H_
6 #define CONTENT_COMMON_INDEXED_DB_INDEXED_DB_KEY_H_
8 #include <string>
9 #include <vector>
11 #include "base/basictypes.h"
12 #include "base/logging.h"
13 #include "base/strings/string16.h"
14 #include "content/common/content_export.h"
15 #include "third_party/WebKit/public/platform/modules/indexeddb/WebIDBTypes.h"
17 namespace blink {
18 class WebIDBKey;
21 namespace content {
23 class CONTENT_EXPORT IndexedDBKey {
24 public:
25 typedef std::vector<IndexedDBKey> KeyArray;
27 IndexedDBKey(); // Defaults to blink::WebIDBKeyTypeInvalid.
28 explicit IndexedDBKey(blink::WebIDBKeyType); // must be Null or Invalid
29 explicit IndexedDBKey(const KeyArray& array);
30 explicit IndexedDBKey(const std::string& binary);
31 explicit IndexedDBKey(const base::string16& string);
32 IndexedDBKey(double number,
33 blink::WebIDBKeyType type); // must be date or number
34 IndexedDBKey(const IndexedDBKey& other);
35 ~IndexedDBKey();
36 IndexedDBKey& operator=(const IndexedDBKey& other);
38 bool IsValid() const;
40 bool IsLessThan(const IndexedDBKey& other) const;
41 bool Equals(const IndexedDBKey& other) const;
43 blink::WebIDBKeyType type() const { return type_; }
44 const std::vector<IndexedDBKey>& array() const {
45 DCHECK_EQ(type_, blink::WebIDBKeyTypeArray);
46 return array_;
48 const std::string& binary() const {
49 DCHECK_EQ(type_, blink::WebIDBKeyTypeBinary);
50 return binary_;
52 const base::string16& string() const {
53 DCHECK_EQ(type_, blink::WebIDBKeyTypeString);
54 return string_;
56 double date() const {
57 DCHECK_EQ(type_, blink::WebIDBKeyTypeDate);
58 return number_;
60 double number() const {
61 DCHECK_EQ(type_, blink::WebIDBKeyTypeNumber);
62 return number_;
65 size_t size_estimate() const { return size_estimate_; }
67 private:
68 int CompareTo(const IndexedDBKey& other) const;
70 blink::WebIDBKeyType type_;
71 std::vector<IndexedDBKey> array_;
72 std::string binary_;
73 base::string16 string_;
74 double number_ = 0;
76 size_t size_estimate_;
79 } // namespace content
81 #endif // CONTENT_COMMON_INDEXED_DB_INDEXED_DB_KEY_H_