|
16 | 16 |
|
17 | 17 | #import "FIRSnapshotMetadata.h"
|
18 | 18 |
|
19 |
| -#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" |
20 |
| - |
21 |
| -NS_ASSUME_NONNULL_BEGIN |
22 |
| - |
23 |
| -@interface FIRSnapshotMetadata () |
| 19 | +#include <utility> |
24 | 20 |
|
25 |
| -- (instancetype)initWithPendingWrites:(BOOL)pendingWrites fromCache:(BOOL)fromCache; |
| 21 | +#import "Firestore/Source/API/FIRSnapshotMetadata+Internal.h" |
26 | 22 |
|
27 |
| -@end |
| 23 | +#include "Firestore/core/src/firebase/firestore/api/snapshot_metadata.h" |
28 | 24 |
|
29 |
| -@implementation FIRSnapshotMetadata (Internal) |
| 25 | +NS_ASSUME_NONNULL_BEGIN |
30 | 26 |
|
31 |
| -+ (instancetype)snapshotMetadataWithPendingWrites:(BOOL)pendingWrites fromCache:(BOOL)fromCache { |
32 |
| - return [[FIRSnapshotMetadata alloc] initWithPendingWrites:pendingWrites fromCache:fromCache]; |
| 27 | +@implementation FIRSnapshotMetadata { |
| 28 | + SnapshotMetadata _metadata; |
33 | 29 | }
|
34 | 30 |
|
35 |
| -@end |
36 |
| - |
37 |
| -@implementation FIRSnapshotMetadata |
38 |
| - |
39 |
| -- (instancetype)initWithPendingWrites:(BOOL)pendingWrites fromCache:(BOOL)fromCache { |
| 31 | +- (instancetype)initWithMetadata:(SnapshotMetadata)metadata { |
40 | 32 | if (self = [super init]) {
|
41 |
| - _pendingWrites = pendingWrites; |
42 |
| - _fromCache = fromCache; |
| 33 | + _metadata = std::move(metadata); |
43 | 34 | }
|
44 | 35 | return self;
|
45 | 36 | }
|
46 | 37 |
|
| 38 | +- (instancetype)initWithPendingWrites:(bool)pendingWrites fromCache:(bool)fromCache { |
| 39 | + SnapshotMetadata wrapped(pendingWrites, fromCache); |
| 40 | + return [self initWithMetadata:std::move(wrapped)]; |
| 41 | +} |
| 42 | + |
47 | 43 | // NSObject Methods
|
48 | 44 | - (BOOL)isEqual:(nullable id)other {
|
49 | 45 | if (other == self) return YES;
|
50 |
| - if (![[other class] isEqual:[self class]]) return NO; |
| 46 | + if (![other isKindOfClass:[FIRSnapshotMetadata class]]) return NO; |
51 | 47 |
|
52 |
| - return [self isEqualToMetadata:other]; |
| 48 | + FIRSnapshotMetadata *otherMetadata = other; |
| 49 | + return _metadata == otherMetadata->_metadata; |
53 | 50 | }
|
54 | 51 |
|
55 |
| -- (BOOL)isEqualToMetadata:(nullable FIRSnapshotMetadata *)metadata { |
56 |
| - if (self == metadata) return YES; |
57 |
| - if (metadata == nil) return NO; |
| 52 | +- (NSUInteger)hash { |
| 53 | + return _metadata.Hash(); |
| 54 | +} |
58 | 55 |
|
59 |
| - return self.pendingWrites == metadata.pendingWrites && self.fromCache == metadata.fromCache; |
| 56 | +- (BOOL)hasPendingWrites { |
| 57 | + return _metadata.pending_writes(); |
60 | 58 | }
|
61 | 59 |
|
62 |
| -- (NSUInteger)hash { |
63 |
| - NSUInteger hash = self.pendingWrites ? 1 : 0; |
64 |
| - hash = hash * 31u + (self.fromCache ? 1 : 0); |
65 |
| - return hash; |
| 60 | +- (BOOL)isFromCache { |
| 61 | + return _metadata.from_cache(); |
66 | 62 | }
|
67 | 63 |
|
68 | 64 | @end
|
|
0 commit comments