2 * Copyright (C) 2011 Google Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
18 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
19 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
20 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
21 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "public/platform/modules/indexeddb/WebIDBKey.h"
31 #include "modules/indexeddb/IDBKey.h"
35 WebIDBKey
WebIDBKey::createArray(const WebVector
<WebIDBKey
>& array
)
38 key
.assignArray(array
);
42 WebIDBKey
WebIDBKey::createBinary(const WebData
& binary
)
45 key
.assignBinary(binary
);
49 WebIDBKey
WebIDBKey::createString(const WebString
& string
)
52 key
.assignString(string
);
56 WebIDBKey
WebIDBKey::createDate(double date
)
63 WebIDBKey
WebIDBKey::createNumber(double number
)
66 key
.assignNumber(number
);
70 WebIDBKey
WebIDBKey::createInvalid()
77 WebIDBKey
WebIDBKey::createNull()
84 #if BLINK_WEB_IMPLEMENTATION || !LINK_CORE_MODULES_SEPARATELY
85 void WebIDBKey::reset()
91 void WebIDBKey::assign(const WebIDBKey
& value
)
93 m_private
= value
.m_private
;
96 static IDBKey
* convertFromWebIDBKeyArray(const WebVector
<WebIDBKey
>& array
)
98 IDBKey::KeyArray keys
;
99 keys
.reserveCapacity(array
.size());
100 for (size_t i
= 0; i
< array
.size(); ++i
) {
101 switch (array
[i
].keyType()) {
102 case WebIDBKeyTypeArray
:
103 keys
.append(convertFromWebIDBKeyArray(array
[i
].array()));
105 case WebIDBKeyTypeBinary
:
106 keys
.append(IDBKey::createBinary(array
[i
].binary()));
108 case WebIDBKeyTypeString
:
109 keys
.append(IDBKey::createString(array
[i
].string()));
111 case WebIDBKeyTypeDate
:
112 keys
.append(IDBKey::createDate(array
[i
].date()));
114 case WebIDBKeyTypeNumber
:
115 keys
.append(IDBKey::createNumber(array
[i
].number()));
117 case WebIDBKeyTypeInvalid
:
118 keys
.append(IDBKey::createInvalid());
120 case WebIDBKeyTypeNull
:
121 case WebIDBKeyTypeMin
:
122 ASSERT_NOT_REACHED();
126 return IDBKey::createArray(keys
);
129 static void convertToWebIDBKeyArray(const IDBKey::KeyArray
& array
, WebVector
<WebIDBKey
>& result
)
131 WebVector
<WebIDBKey
> keys(array
.size());
132 WebVector
<WebIDBKey
> subkeys
;
133 for (size_t i
= 0; i
< array
.size(); ++i
) {
134 IDBKey
* key
= array
[i
];
135 switch (key
->type()) {
136 case IDBKey::ArrayType
:
137 convertToWebIDBKeyArray(key
->array(), subkeys
);
138 keys
[i
] = WebIDBKey::createArray(subkeys
);
140 case IDBKey::BinaryType
:
141 keys
[i
] = WebIDBKey::createBinary(key
->binary());
143 case IDBKey::StringType
:
144 keys
[i
] = WebIDBKey::createString(key
->string());
146 case IDBKey::DateType
:
147 keys
[i
] = WebIDBKey::createDate(key
->date());
149 case IDBKey::NumberType
:
150 keys
[i
] = WebIDBKey::createNumber(key
->number());
152 case IDBKey::InvalidType
:
153 keys
[i
] = WebIDBKey::createInvalid();
155 case IDBKey::MinType
:
156 ASSERT_NOT_REACHED();
163 void WebIDBKey::assignArray(const WebVector
<WebIDBKey
>& array
)
165 m_private
= convertFromWebIDBKeyArray(array
);
168 void WebIDBKey::assignBinary(const WebData
& binary
)
170 m_private
= IDBKey::createBinary(binary
);
173 void WebIDBKey::assignString(const WebString
& string
)
175 m_private
= IDBKey::createString(string
);
178 void WebIDBKey::assignDate(double date
)
180 m_private
= IDBKey::createDate(date
);
183 void WebIDBKey::assignNumber(double number
)
185 m_private
= IDBKey::createNumber(number
);
188 void WebIDBKey::assignInvalid()
190 m_private
= IDBKey::createInvalid();
193 void WebIDBKey::assignNull()
198 WebIDBKeyType
WebIDBKey::keyType() const
200 if (!m_private
.get())
201 return WebIDBKeyTypeNull
;
202 return static_cast<WebIDBKeyType
>(m_private
->type());
205 bool WebIDBKey::isValid() const
207 if (!m_private
.get())
209 return m_private
->isValid();
212 WebVector
<WebIDBKey
> WebIDBKey::array() const
214 WebVector
<WebIDBKey
> keys
;
215 convertToWebIDBKeyArray(m_private
->array(), keys
);
219 WebData
WebIDBKey::binary() const
221 return m_private
->binary();
224 WebString
WebIDBKey::string() const
226 return m_private
->string();
229 double WebIDBKey::date() const
231 return m_private
->date();
234 double WebIDBKey::number() const
236 return m_private
->number();