Files
firebase-ios-sdk/Firebase/Database/Core/Operation/FAckUserWrite.m
T

66 lines
2.3 KiB
Objective-C
Raw Normal View History

2017-05-15 12:27:07 -07:00
/*
* Copyright 2017 Google
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#import "FAckUserWrite.h"
#import "FImmutableTree.h"
2019-08-05 13:27:47 -07:00
#import "FOperationSource.h"
#import "FPath.h"
2017-05-15 12:27:07 -07:00
@implementation FAckUserWrite
2019-08-05 13:27:47 -07:00
- (id)initWithPath:(FPath *)operationPath
affectedTree:(FImmutableTree *)tree
revert:(BOOL)shouldRevert {
2017-05-15 12:27:07 -07:00
self = [super init];
if (self) {
self->_source = [FOperationSource userInstance];
self->_type = FOperationTypeAckUserWrite;
self->_path = operationPath;
self->_affectedTree = tree;
self->_revert = shouldRevert;
}
return self;
}
2019-08-05 13:27:47 -07:00
- (FAckUserWrite *)operationForChild:(NSString *)childKey {
2017-05-15 12:27:07 -07:00
if (![self.path isEmpty]) {
2019-08-05 13:27:47 -07:00
NSAssert([self.path.getFront isEqualToString:childKey],
@"operationForChild called for unrelated child.");
return [[FAckUserWrite alloc] initWithPath:[self.path popFront]
affectedTree:self.affectedTree
revert:self.revert];
2017-05-15 12:27:07 -07:00
} else if (self.affectedTree.value != nil) {
2019-08-05 13:27:47 -07:00
NSAssert(self.affectedTree.children.isEmpty,
@"affectedTree should not have overlapping affected paths.");
2017-05-15 12:27:07 -07:00
// All child locations are affected as well; just return same operation.
return self;
} else {
2019-08-05 13:27:47 -07:00
FImmutableTree *childTree =
[self.affectedTree subtreeAtPath:[[FPath alloc] initWith:childKey]];
return [[FAckUserWrite alloc] initWithPath:[FPath empty]
affectedTree:childTree
revert:self.revert];
2017-05-15 12:27:07 -07:00
}
}
2019-08-05 13:27:47 -07:00
- (NSString *)description {
return
[NSString stringWithFormat:
@"FAckUserWrite { path=%@, revert=%d, affectedTree=%@ }",
self.path, self.revert, self.affectedTree];
2017-05-15 12:27:07 -07:00
}
@end