1 /* 2 * Copyright (C) 2011 Google Inc. All rights reserved. 3 * 4 * Redistribution and use in source and binary forms, with or without 5 * modification, are permitted provided that the following conditions 6 * are met: 7 * 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24 */ 25 26 #include "config.h" 27 #include "public/platform/WebIDBKeyPath.h" 28 29 #include "public/platform/WebString.h" 30 #include "public/platform/WebVector.h" 31 #include "wtf/Vector.h" 32 #include "modules/indexeddb/IDBKeyPath.h" 33 34 using namespace WebCore; 35 36 namespace blink { 37 38 WebIDBKeyPath WebIDBKeyPath::create(const WebString& keyPath) 39 { 40 return WebIDBKeyPath(IDBKeyPath(keyPath)); 41 } 42 43 WebIDBKeyPath WebIDBKeyPath::create(const WebVector<WebString>& keyPath) 44 { 45 Vector<String> strings; 46 for (size_t i = 0; i < keyPath.size(); ++i) 47 strings.append(keyPath[i]); 48 return WebIDBKeyPath(IDBKeyPath(strings)); 49 } 50 51 WebIDBKeyPath WebIDBKeyPath::createNull() 52 { 53 return WebIDBKeyPath(IDBKeyPath()); 54 } 55 56 void WebIDBKeyPath::assign(const WebIDBKeyPath& keyPath) 57 { 58 ASSERT(keyPath.m_private.get()); 59 m_private.reset(new IDBKeyPath(keyPath)); 60 } 61 62 void WebIDBKeyPath::reset() 63 { 64 m_private.reset(0); 65 } 66 67 bool WebIDBKeyPath::isValid() const 68 { 69 ASSERT(m_private.get()); 70 return m_private->isValid(); 71 } 72 73 WebIDBKeyPathType WebIDBKeyPath::keyPathType() const 74 { 75 ASSERT(m_private.get()); 76 return static_cast<WebIDBKeyPathType>(m_private->type()); 77 } 78 79 WebVector<WebString> WebIDBKeyPath::array() const 80 { 81 ASSERT(m_private.get()); 82 ASSERT(m_private->type() == IDBKeyPath::ArrayType); 83 return m_private->array(); 84 } 85 86 WebString WebIDBKeyPath::string() const 87 { 88 ASSERT(m_private.get()); 89 ASSERT(m_private->type() == IDBKeyPath::StringType); 90 return m_private->string(); 91 } 92 93 WebIDBKeyPath::WebIDBKeyPath(const WebCore::IDBKeyPath& value) 94 : m_private(new IDBKeyPath(value)) 95 { 96 ASSERT(m_private.get()); 97 } 98 99 WebIDBKeyPath& WebIDBKeyPath::operator=(const WebCore::IDBKeyPath& value) 100 { 101 ASSERT(m_private.get()); 102 m_private.reset(new IDBKeyPath(value)); 103 return *this; 104 } 105 106 WebIDBKeyPath::operator const WebCore::IDBKeyPath&() const 107 { 108 ASSERT(m_private.get()); 109 return *(m_private.get()); 110 } 111 112 } // namespace blink 113