RLMCollection_Private.hpp 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. ////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright 2016 Realm Inc.
  4. //
  5. // Licensed under the Apache License, Version 2.0 (the "License");
  6. // you may not use this file except in compliance with the License.
  7. // You may obtain a copy of the License at
  8. //
  9. // http://www.apache.org/licenses/LICENSE-2.0
  10. //
  11. // Unless required by applicable law or agreed to in writing, software
  12. // distributed under the License is distributed on an "AS IS" BASIS,
  13. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. // See the License for the specific language governing permissions and
  15. // limitations under the License.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////
  18. #import <Realm/RLMCollection_Private.h>
  19. #import <vector>
  20. namespace realm {
  21. class List;
  22. class Results;
  23. class TableView;
  24. struct CollectionChangeSet;
  25. struct NotificationToken;
  26. }
  27. class RLMClassInfo;
  28. @class RLMFastEnumerator;
  29. @protocol RLMFastEnumerable
  30. @property (nonatomic, readonly) RLMRealm *realm;
  31. @property (nonatomic, readonly) RLMClassInfo *objectInfo;
  32. @property (nonatomic, readonly) NSUInteger count;
  33. - (realm::TableView)tableView;
  34. - (RLMFastEnumerator *)fastEnumerator;
  35. @end
  36. // An object which encapulates the shared logic for fast-enumerating RLMArray
  37. // and RLMResults, and has a buffer to store strong references to the current
  38. // set of enumerated items
  39. @interface RLMFastEnumerator : NSObject
  40. - (instancetype)initWithList:(realm::List&)list
  41. collection:(id)collection
  42. realm:(RLMRealm *)realm
  43. classInfo:(RLMClassInfo&)info;
  44. - (instancetype)initWithResults:(realm::Results&)results
  45. collection:(id)collection
  46. realm:(RLMRealm *)realm
  47. classInfo:(RLMClassInfo&)info;
  48. // Detach this enumerator from the source collection. Must be called before the
  49. // source collection is changed.
  50. - (void)detach;
  51. - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
  52. count:(NSUInteger)len;
  53. @end
  54. NSUInteger RLMFastEnumerate(NSFastEnumerationState *state, NSUInteger len, id<RLMFastEnumerable> collection);
  55. @interface RLMNotificationToken ()
  56. - (void)suppressNextNotification;
  57. - (RLMRealm *)realm;
  58. @end
  59. @interface RLMCancellationToken : RLMNotificationToken
  60. - (instancetype)initWithToken:(realm::NotificationToken)token realm:(RLMRealm *)realm;
  61. @end
  62. @interface RLMCollectionChange ()
  63. - (instancetype)initWithChanges:(realm::CollectionChangeSet)indices;
  64. @end
  65. template<typename Collection>
  66. RLMNotificationToken *RLMAddNotificationBlock(id objcCollection,
  67. Collection& collection,
  68. void (^block)(id, RLMCollectionChange *, NSError *),
  69. bool suppressInitialChange=false);
  70. template<typename Collection>
  71. NSArray *RLMCollectionValueForKey(Collection& collection, NSString *key,
  72. RLMRealm *realm, RLMClassInfo& info);
  73. std::vector<std::pair<std::string, bool>> RLMSortDescriptorsToKeypathArray(NSArray<RLMSortDescriptor *> *properties);