FSTDocumentKey.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. // Using forward declaration to avoid circular dependency (`document_key.h` includes this header).`
  21. namespace firebase {
  22. namespace firestore {
  23. namespace model {
  24. class DocumentKey;
  25. }
  26. }
  27. }
  28. NS_ASSUME_NONNULL_BEGIN
  29. /** FSTDocumentKey represents the location of a document in the Firestore database. */
  30. @interface FSTDocumentKey : NSObject <NSCopying>
  31. /**
  32. * Creates and returns a new document key with the given path.
  33. *
  34. * @param path The path to the document.
  35. * @return A new instance of FSTDocumentKey.
  36. */
  37. + (instancetype)keyWithPath:(firebase::firestore::model::ResourcePath)path;
  38. + (instancetype)keyWithDocumentKey:(const firebase::firestore::model::DocumentKey &)documentKey;
  39. /**
  40. * Creates and returns a new document key with a path with the given segments.
  41. *
  42. * @param segments The segments of the path to the document.
  43. * @return A new instance of FSTDocumentKey.
  44. */
  45. + (instancetype)keyWithSegments:(std::initializer_list<std::string>)segments;
  46. /**
  47. * Creates and returns a new document key from the given resource path string.
  48. *
  49. * @param resourcePath The slash-separated segments of the resource's path.
  50. * @return A new instance of FSTDocumentKey.
  51. */
  52. + (instancetype)keyWithPathString:(NSString *)resourcePath;
  53. /** Returns true iff the given path is a path to a document. */
  54. + (BOOL)isDocumentKey:(const firebase::firestore::model::ResourcePath &)path;
  55. - (BOOL)isEqualToKey:(FSTDocumentKey *)other;
  56. - (NSComparisonResult)compare:(FSTDocumentKey *)other;
  57. /** The path to the document. */
  58. - (const firebase::firestore::model::ResourcePath &)path;
  59. @end
  60. extern const NSComparator FSTDocumentKeyComparator;
  61. /** The field path string that represents the document's key. */
  62. extern NSString *const kDocumentKeyPath;
  63. NS_ASSUME_NONNULL_END