FOverwrite.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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 "FOverwrite.h"
  17. #import "FNode.h"
  18. #import "FOperationSource.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 path:(FPath *)aPath snap:(id <FNode>)aSnap {
  31. self = [super init];
  32. if (self) {
  33. self.source = aSource;
  34. self.type = FOperationTypeOverwrite;
  35. self.path = aPath;
  36. self.snap = aSnap;
  37. }
  38. return self;
  39. }
  40. - (FOverwrite *) operationForChild:(NSString *)childKey {
  41. if ([self.path isEmpty]) {
  42. return [[FOverwrite alloc] initWithSource:self.source
  43. path:[FPath empty]
  44. snap:[self.snap getImmediateChild:childKey]];
  45. } else {
  46. return [[FOverwrite alloc] initWithSource:self.source
  47. path:[self.path popFront]
  48. snap:self.snap];
  49. }
  50. }
  51. - (NSString *) description {
  52. return [NSString stringWithFormat:@"FOverwrite { path=%@, source=%@, snapshot=%@ }", self.path, self.source, self.snap];
  53. }
  54. @end