FIRTransactionOptions.mm 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * Copyright 2022 Google LLC
  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 "FIRTransactionOptions.h"
  17. #import "FIRTransactionOptions+Internal.h"
  18. #import <Foundation/Foundation.h>
  19. #include <cstdint>
  20. #include <string>
  21. #include "Firestore/core/src/api/firestore.h"
  22. #include "Firestore/core/src/util/exception.h"
  23. NS_ASSUME_NONNULL_BEGIN
  24. using firebase::firestore::api::kDefaultTransactionMaxAttempts;
  25. using firebase::firestore::util::ThrowInvalidArgument;
  26. @implementation FIRTransactionOptions
  27. - (instancetype)init {
  28. if (self = [super init]) {
  29. _maxAttempts = [[self class] defaultMaxAttempts];
  30. }
  31. return self;
  32. }
  33. + (int)defaultMaxAttempts {
  34. return kDefaultTransactionMaxAttempts;
  35. }
  36. - (BOOL)isEqual:(id)other {
  37. if (self == other) {
  38. return YES;
  39. } else if (![other isKindOfClass:[FIRTransactionOptions class]]) {
  40. return NO;
  41. }
  42. FIRTransactionOptions *otherOptions = (FIRTransactionOptions *)other;
  43. return self.maxAttempts == otherOptions.maxAttempts;
  44. }
  45. - (NSUInteger)hash {
  46. return _maxAttempts * 31;
  47. }
  48. - (id)copyWithZone:(__unused NSZone *_Nullable)zone {
  49. FIRTransactionOptions *copy = [[FIRTransactionOptions alloc] init];
  50. copy.maxAttempts = self.maxAttempts;
  51. return copy;
  52. }
  53. - (void)setMaxAttempts:(NSInteger)maxAttempts {
  54. if (maxAttempts <= 0 || maxAttempts > INT32_MAX) {
  55. ThrowInvalidArgument("Invalid maxAttempts: %s", std::to_string(maxAttempts));
  56. }
  57. _maxAttempts = maxAttempts;
  58. }
  59. @end
  60. NS_ASSUME_NONNULL_END