FSTDocumentKey.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import <Foundation/Foundation.h>
  17. #include <initializer_list>
  18. #include <string>
  19. #include "Firestore/core/src/firebase/firestore/model/resource_path.h"
  20. NS_ASSUME_NONNULL_BEGIN
  21. /** FSTDocumentKey represents the location of a document in the Firestore database. */
  22. @interface FSTDocumentKey : NSObject <NSCopying>
  23. /**
  24. * Creates and returns a new document key with the given path.
  25. *
  26. * @param path The path to the document.
  27. * @return A new instance of FSTDocumentKey.
  28. */
  29. + (instancetype)keyWithPath:(firebase::firestore::model::ResourcePath)path;
  30. /**
  31. * Creates and returns a new document key with a path with the given segments.
  32. *
  33. * @param segments The segments of the path to the document.
  34. * @return A new instance of FSTDocumentKey.
  35. */
  36. + (instancetype)keyWithSegments:(std::initializer_list<std::string>)segments;
  37. /**
  38. * Creates and returns a new document key from the given resource path string.
  39. *
  40. * @param resourcePath The slash-separated segments of the resource's path.
  41. * @return A new instance of FSTDocumentKey.
  42. */
  43. + (instancetype)keyWithPathString:(NSString *)resourcePath;
  44. /** Returns true iff the given path is a path to a document. */
  45. + (BOOL)isDocumentKey:(const firebase::firestore::model::ResourcePath &)path;
  46. - (BOOL)isEqualToKey:(FSTDocumentKey *)other;
  47. - (NSComparisonResult)compare:(FSTDocumentKey *)other;
  48. /** The path to the document. */
  49. - (const firebase::firestore::model::ResourcePath &)path;
  50. @end
  51. extern const NSComparator FSTDocumentKeyComparator;
  52. /** The field path string that represents the document's key. */
  53. extern NSString *const kDocumentKeyPath;
  54. NS_ASSUME_NONNULL_END