added iOS source code
[wl-app.git] / iOS / Pods / Realm / include / RLMCollection_Private.hpp
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
19 #import <Realm/RLMCollection_Private.h>
20
21 #import <vector>
22
23 namespace realm {
24     class List;
25     class Results;
26     class TableView;
27     struct CollectionChangeSet;
28     struct NotificationToken;
29 }
30 class RLMClassInfo;
31 @class RLMFastEnumerator;
32
33 @protocol RLMFastEnumerable
34 @property (nonatomic, readonly) RLMRealm *realm;
35 @property (nonatomic, readonly) RLMClassInfo *objectInfo;
36 @property (nonatomic, readonly) NSUInteger count;
37
38 - (realm::TableView)tableView;
39 - (RLMFastEnumerator *)fastEnumerator;
40 @end
41
42 // An object which encapulates the shared logic for fast-enumerating RLMArray
43 // and RLMResults, and has a buffer to store strong references to the current
44 // set of enumerated items
45 @interface RLMFastEnumerator : NSObject
46 - (instancetype)initWithList:(realm::List&)list
47                   collection:(id)collection
48                        realm:(RLMRealm *)realm
49                    classInfo:(RLMClassInfo&)info;
50 - (instancetype)initWithResults:(realm::Results&)results
51                      collection:(id)collection
52                           realm:(RLMRealm *)realm
53                       classInfo:(RLMClassInfo&)info;
54
55 // Detach this enumerator from the source collection. Must be called before the
56 // source collection is changed.
57 - (void)detach;
58
59 - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state
60                                     count:(NSUInteger)len;
61 @end
62 NSUInteger RLMFastEnumerate(NSFastEnumerationState *state, NSUInteger len, id<RLMFastEnumerable> collection);
63
64 @interface RLMNotificationToken ()
65 - (void)suppressNextNotification;
66 - (RLMRealm *)realm;
67 @end
68
69 @interface RLMCancellationToken : RLMNotificationToken
70 - (instancetype)initWithToken:(realm::NotificationToken)token realm:(RLMRealm *)realm;
71 @end
72
73 @interface RLMCollectionChange ()
74 - (instancetype)initWithChanges:(realm::CollectionChangeSet)indices;
75 @end
76
77 template<typename Collection>
78 RLMNotificationToken *RLMAddNotificationBlock(id objcCollection,
79                                               Collection& collection,
80                                               void (^block)(id, RLMCollectionChange *, NSError *),
81                                               bool suppressInitialChange=false);
82
83 template<typename Collection>
84 NSArray *RLMCollectionValueForKey(Collection& collection, NSString *key,
85                                   RLMRealm *realm, RLMClassInfo& info);
86
87 std::vector<std::pair<std::string, bool>> RLMSortDescriptorsToKeypathArray(NSArray<RLMSortDescriptor *> *properties);