RLMCollection_Private.hpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 <Realm/RLMRealm.h>
  20. #import <realm/keys.hpp>
  21. #import <realm/object-store/collection_notifications.hpp>
  22. #import <vector>
  23. #import <mutex>
  24. namespace realm {
  25. class CollectionChangeCallback;
  26. class List;
  27. class Obj;
  28. class Results;
  29. class TableView;
  30. struct CollectionChangeSet;
  31. struct ColKey;
  32. namespace object_store {
  33. class Collection;
  34. class Dictionary;
  35. class Set;
  36. }
  37. }
  38. class RLMClassInfo;
  39. @class RLMFastEnumerator, RLMManagedArray, RLMManagedSet, RLMManagedDictionary, RLMProperty, RLMObjectBase;
  40. RLM_HIDDEN_BEGIN
  41. @protocol RLMCollectionPrivate
  42. @property (nonatomic, readonly) RLMRealm *realm;
  43. @property (nonatomic, readonly) RLMClassInfo *objectInfo;
  44. @property (nonatomic, readonly) NSUInteger count;
  45. - (realm::TableView)tableView;
  46. - (RLMFastEnumerator *)fastEnumerator;
  47. - (realm::NotificationToken)addNotificationCallback:(id)block
  48. keyPaths:(std::optional<std::vector<std::vector<std::pair<realm::TableKey, realm::ColKey>>>>&&)keyPaths;
  49. @end
  50. // An object which encapsulates the shared logic for fast-enumerating RLMArray
  51. // RLMSet and RLMResults, and has a buffer to store strong references to the current
  52. // set of enumerated items
  53. RLM_DIRECT_MEMBERS
  54. @interface RLMFastEnumerator : NSObject
  55. - (instancetype)initWithBackingCollection:(realm::object_store::Collection const&)backingCollection
  56. collection:(id)collection
  57. classInfo:(RLMClassInfo&)info;
  58. - (instancetype)initWithBackingDictionary:(realm::object_store::Dictionary const&)backingDictionary
  59. dictionary:(RLMManagedDictionary *)dictionary
  60. classInfo:(RLMClassInfo&)info;
  61. - (instancetype)initWithResults:(realm::Results&)results
  62. collection:(id)collection
  63. classInfo:(RLMClassInfo&)info;
  64. // Detach this enumerator from the source collection. Must be called before the
  65. // source collection is changed.
  66. - (void)detach;
  67. - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
  68. count:(NSUInteger)len;
  69. @end
  70. NSUInteger RLMFastEnumerate(NSFastEnumerationState *state, NSUInteger len, id<RLMCollectionPrivate> collection);
  71. @interface RLMNotificationToken ()
  72. - (void)suppressNextNotification;
  73. - (RLMRealm *)realm;
  74. @end
  75. @interface RLMCollectionChange ()
  76. - (instancetype)initWithChanges:(realm::CollectionChangeSet)indices;
  77. @end
  78. realm::CollectionChangeCallback RLMWrapCollectionChangeCallback(void (^block)(id, id, NSError *),
  79. id collection, bool skipFirst);
  80. template<typename Collection>
  81. NSArray *RLMCollectionValueForKey(Collection& collection, NSString *key, RLMClassInfo& info);
  82. std::vector<std::pair<std::string, bool>> RLMSortDescriptorsToKeypathArray(NSArray<RLMSortDescriptor *> *properties);
  83. realm::ColKey columnForProperty(NSString *propertyName,
  84. realm::object_store::Collection const& backingCollection,
  85. RLMClassInfo *objectInfo,
  86. RLMPropertyType propertyType,
  87. RLMCollectionType collectionType);
  88. static inline bool canAggregate(RLMPropertyType type, bool allowDate) {
  89. switch (type) {
  90. case RLMPropertyTypeInt:
  91. case RLMPropertyTypeFloat:
  92. case RLMPropertyTypeDouble:
  93. case RLMPropertyTypeDecimal128:
  94. case RLMPropertyTypeAny:
  95. return true;
  96. case RLMPropertyTypeDate:
  97. return allowDate;
  98. default:
  99. return false;
  100. }
  101. }
  102. NSArray *RLMToIndexPathArray(realm::IndexSet const& set, NSUInteger section);
  103. RLM_HIDDEN_END