michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #ifndef mozilla_dom_indexeddb_keypath_h__ michael@0: #define mozilla_dom_indexeddb_keypath_h__ michael@0: michael@0: #include "mozilla/dom/indexedDB/IndexedDatabase.h" michael@0: michael@0: #include "mozilla/dom/BindingDeclarations.h" michael@0: michael@0: BEGIN_INDEXEDDB_NAMESPACE michael@0: michael@0: class Key; michael@0: michael@0: class KeyPath michael@0: { michael@0: public: michael@0: enum KeyPathType { michael@0: NONEXISTENT, michael@0: STRING, michael@0: ARRAY, michael@0: ENDGUARD michael@0: }; michael@0: michael@0: void SetType(KeyPathType aType); michael@0: michael@0: // This does not set exceptions. michael@0: bool AppendStringWithValidation(JSContext* aCx, const nsAString& aString); michael@0: michael@0: explicit KeyPath(int aDummy) michael@0: : mType(NONEXISTENT) michael@0: { michael@0: MOZ_COUNT_CTOR(KeyPath); michael@0: } michael@0: michael@0: KeyPath(const KeyPath& aOther) michael@0: { michael@0: MOZ_COUNT_CTOR(KeyPath); michael@0: *this = aOther; michael@0: } michael@0: michael@0: ~KeyPath() michael@0: { michael@0: MOZ_COUNT_DTOR(KeyPath); michael@0: } michael@0: michael@0: static nsresult michael@0: Parse(JSContext* aCx, const nsAString& aString, KeyPath* aKeyPath); michael@0: michael@0: static nsresult michael@0: Parse(JSContext* aCx, const Sequence& aStrings, KeyPath* aKeyPath); michael@0: michael@0: static nsresult michael@0: Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath); michael@0: michael@0: nsresult michael@0: ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const; michael@0: michael@0: nsresult michael@0: ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue, michael@0: JS::Value* aOutVal) const; michael@0: michael@0: typedef nsresult michael@0: (*ExtractOrCreateKeyCallback)(JSContext* aCx, void* aClosure); michael@0: michael@0: nsresult michael@0: ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue, Key& aKey, michael@0: ExtractOrCreateKeyCallback aCallback, michael@0: void* aClosure) const; michael@0: michael@0: inline bool IsValid() const { michael@0: return mType != NONEXISTENT; michael@0: } michael@0: michael@0: inline bool IsArray() const { michael@0: return mType == ARRAY; michael@0: } michael@0: michael@0: inline bool IsString() const { michael@0: return mType == STRING; michael@0: } michael@0: michael@0: inline bool IsEmpty() const { michael@0: return mType == STRING && mStrings[0].IsEmpty(); michael@0: } michael@0: michael@0: bool operator==(const KeyPath& aOther) const michael@0: { michael@0: return mType == aOther.mType && mStrings == aOther.mStrings; michael@0: } michael@0: michael@0: void SerializeToString(nsAString& aString) const; michael@0: static KeyPath DeserializeFromString(const nsAString& aString); michael@0: michael@0: nsresult ToJSVal(JSContext* aCx, JS::MutableHandle aValue) const; michael@0: nsresult ToJSVal(JSContext* aCx, JS::Heap& aValue) const; michael@0: michael@0: bool IsAllowedForObjectStore(bool aAutoIncrement) const; michael@0: michael@0: KeyPathType mType; michael@0: michael@0: nsTArray mStrings; michael@0: }; michael@0: michael@0: END_INDEXEDDB_NAMESPACE michael@0: michael@0: #endif /* mozilla_dom_indexeddb_keypath_h__ */