diff options
Diffstat (limited to 'Source/WebCore/Modules/indexeddb/IDBKeyPath.h')
-rw-r--r-- | Source/WebCore/Modules/indexeddb/IDBKeyPath.h | 73 |
1 files changed, 21 insertions, 52 deletions
diff --git a/Source/WebCore/Modules/indexeddb/IDBKeyPath.h b/Source/WebCore/Modules/indexeddb/IDBKeyPath.h index 6dcd7deac..c5a04b3d2 100644 --- a/Source/WebCore/Modules/indexeddb/IDBKeyPath.h +++ b/Source/WebCore/Modules/indexeddb/IDBKeyPath.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2010 Google Inc. All rights reserved. + * Copyright (C) 2016-2017 Apple Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -23,71 +24,39 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef IDBKeyPath_h -#define IDBKeyPath_h +#pragma once #if ENABLE(INDEXED_DATABASE) +#include <wtf/Variant.h> #include <wtf/Vector.h> #include <wtf/text/WTFString.h> namespace WebCore { -class KeyedDecoder; -class KeyedEncoder; +using IDBKeyPath = WTF::Variant<String, Vector<String>>; +bool isIDBKeyPathValid(const IDBKeyPath&); -enum IDBKeyPathParseError { - IDBKeyPathParseErrorNone, - IDBKeyPathParseErrorStart, - IDBKeyPathParseErrorIdentifier, - IDBKeyPathParseErrorDot, +enum class IDBKeyPathParseError { + None, + Start, + Identifier, + Dot, }; void IDBParseKeyPath(const String&, Vector<String>&, IDBKeyPathParseError&); - -class IDBKeyPath { -public: - IDBKeyPath() : m_type(NullType) { } - explicit IDBKeyPath(const String&); - explicit IDBKeyPath(const Vector<String>& array); - - enum Type { - NullType = 0, - StringType, - ArrayType - }; - - Type type() const { return m_type; } - - const Vector<String>& array() const - { - ASSERT(m_type == ArrayType); - return m_array; - } - - const String& string() const - { - ASSERT(m_type == StringType); - return m_string; - } - - bool isNull() const { return m_type == NullType; } - bool isValid() const; - bool operator==(const IDBKeyPath& other) const; - - IDBKeyPath isolatedCopy() const; - - void encode(KeyedEncoder&) const; - static bool decode(KeyedDecoder&, IDBKeyPath&); - -private: - Type m_type; - String m_string; - Vector<String> m_array; -}; +IDBKeyPath isolatedCopy(const IDBKeyPath&); +inline std::optional<IDBKeyPath> isolatedCopy(const std::optional<IDBKeyPath>& variant) +{ + if (!variant) + return { }; + return isolatedCopy(variant.value()); +} + +#ifndef NDEBUG +String loggingString(const IDBKeyPath&); +#endif } // namespace WebCore #endif - -#endif // IDBKeyPath_h |