FOverwrite.m 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright 2017 Google
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #import "FirebaseDatabase/Sources/Core/Operation/FOverwrite.h"
  17. #import "FirebaseDatabase/Sources/Core/Operation/FOperationSource.h"
  18. #import "FirebaseDatabase/Sources/Snapshot/FNode.h"
  19. @interface FOverwrite ()
  20. @property(nonatomic, strong, readwrite) FOperationSource *source;
  21. @property(nonatomic, readwrite) FOperationType type;
  22. @property(nonatomic, strong, readwrite) FPath *path;
  23. @property(nonatomic, strong) id<FNode> snap;
  24. @end
  25. @implementation FOverwrite
  26. @synthesize source;
  27. @synthesize type;
  28. @synthesize path;
  29. @synthesize snap;
  30. - (id)initWithSource:(FOperationSource *)aSource
  31. path:(FPath *)aPath
  32. snap:(id<FNode>)aSnap {
  33. self = [super init];
  34. if (self) {
  35. self.source = aSource;
  36. self.type = FOperationTypeOverwrite;
  37. self.path = aPath;
  38. self.snap = aSnap;
  39. }
  40. return self;
  41. }
  42. - (FOverwrite *)operationForChild:(NSString *)childKey {
  43. if ([self.path isEmpty]) {
  44. return [[FOverwrite alloc]
  45. initWithSource:self.source
  46. path:[FPath empty]
  47. snap:[self.snap getImmediateChild:childKey]];
  48. } else {
  49. return [[FOverwrite alloc] initWithSource:self.source
  50. path:[self.path popFront]
  51. snap:self.snap];
  52. }
  53. }
  54. - (NSString *)description {
  55. return [NSString
  56. stringWithFormat:@"FOverwrite { path=%@, source=%@, snapshot=%@ }",
  57. self.path, self.source, self.snap];
  58. }
  59. @end