dom/indexedDB/KeyPath.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/dom/indexedDB/KeyPath.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,110 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +#ifndef mozilla_dom_indexeddb_keypath_h__
    1.11 +#define mozilla_dom_indexeddb_keypath_h__
    1.12 +
    1.13 +#include "mozilla/dom/indexedDB/IndexedDatabase.h"
    1.14 +
    1.15 +#include "mozilla/dom/BindingDeclarations.h"
    1.16 +
    1.17 +BEGIN_INDEXEDDB_NAMESPACE
    1.18 +
    1.19 +class Key;
    1.20 +
    1.21 +class KeyPath
    1.22 +{
    1.23 +public:
    1.24 +  enum KeyPathType {
    1.25 +    NONEXISTENT,
    1.26 +    STRING,
    1.27 +    ARRAY,
    1.28 +    ENDGUARD
    1.29 +  };
    1.30 +
    1.31 +  void SetType(KeyPathType aType);
    1.32 +
    1.33 +  // This does not set exceptions.
    1.34 +  bool AppendStringWithValidation(JSContext* aCx, const nsAString& aString);
    1.35 +
    1.36 +  explicit KeyPath(int aDummy)
    1.37 +  : mType(NONEXISTENT)
    1.38 +  {
    1.39 +    MOZ_COUNT_CTOR(KeyPath);
    1.40 +  }
    1.41 +
    1.42 +  KeyPath(const KeyPath& aOther)
    1.43 +  {
    1.44 +    MOZ_COUNT_CTOR(KeyPath);
    1.45 +    *this = aOther;
    1.46 +  }
    1.47 +
    1.48 +  ~KeyPath()
    1.49 +  {
    1.50 +    MOZ_COUNT_DTOR(KeyPath);
    1.51 +  }
    1.52 +
    1.53 +  static nsresult
    1.54 +  Parse(JSContext* aCx, const nsAString& aString, KeyPath* aKeyPath);
    1.55 +
    1.56 +  static nsresult
    1.57 +  Parse(JSContext* aCx, const Sequence<nsString>& aStrings, KeyPath* aKeyPath);
    1.58 +
    1.59 +  static nsresult
    1.60 +  Parse(JSContext* aCx, const JS::Value& aValue, KeyPath* aKeyPath);
    1.61 +
    1.62 +  nsresult
    1.63 +  ExtractKey(JSContext* aCx, const JS::Value& aValue, Key& aKey) const;
    1.64 +
    1.65 +  nsresult
    1.66 +  ExtractKeyAsJSVal(JSContext* aCx, const JS::Value& aValue,
    1.67 +                    JS::Value* aOutVal) const;
    1.68 +
    1.69 +  typedef nsresult
    1.70 +  (*ExtractOrCreateKeyCallback)(JSContext* aCx, void* aClosure);
    1.71 +
    1.72 +  nsresult
    1.73 +  ExtractOrCreateKey(JSContext* aCx, const JS::Value& aValue, Key& aKey,
    1.74 +                     ExtractOrCreateKeyCallback aCallback,
    1.75 +                     void* aClosure) const;
    1.76 +
    1.77 +  inline bool IsValid() const {
    1.78 +    return mType != NONEXISTENT;
    1.79 +  }
    1.80 +
    1.81 +  inline bool IsArray() const {
    1.82 +    return mType == ARRAY;
    1.83 +  }
    1.84 +
    1.85 +  inline bool IsString() const {
    1.86 +    return mType == STRING;
    1.87 +  }
    1.88 +
    1.89 +  inline bool IsEmpty() const {
    1.90 +    return mType == STRING && mStrings[0].IsEmpty();
    1.91 +  }
    1.92 +
    1.93 +  bool operator==(const KeyPath& aOther) const
    1.94 +  {
    1.95 +    return mType == aOther.mType && mStrings == aOther.mStrings;
    1.96 +  }
    1.97 +
    1.98 +  void SerializeToString(nsAString& aString) const;
    1.99 +  static KeyPath DeserializeFromString(const nsAString& aString);
   1.100 +
   1.101 +  nsresult ToJSVal(JSContext* aCx, JS::MutableHandle<JS::Value> aValue) const;
   1.102 +  nsresult ToJSVal(JSContext* aCx, JS::Heap<JS::Value>& aValue) const;
   1.103 +
   1.104 +  bool IsAllowedForObjectStore(bool aAutoIncrement) const;
   1.105 +
   1.106 +  KeyPathType mType;
   1.107 +
   1.108 +  nsTArray<nsString> mStrings;
   1.109 +};
   1.110 +
   1.111 +END_INDEXEDDB_NAMESPACE
   1.112 +
   1.113 +#endif /* mozilla_dom_indexeddb_keypath_h__ */

mercurial