2017-10-03 08:55:22 -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.
|
|
|
|
|
*/
|
|
|
|
|
|
2018-04-09 11:54:39 -07:00
|
|
|
#import "FIRFieldPath.h"
|
2017-10-03 08:55:22 -07:00
|
|
|
|
2018-03-14 08:57:31 -04:00
|
|
|
#include <functional>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
2018-04-09 11:54:39 -07:00
|
|
|
#import "Firestore/Source/API/FIRFieldPath+Internal.h"
|
2017-10-03 08:55:22 -07:00
|
|
|
|
2020-04-20 14:57:34 -07:00
|
|
|
#include "Firestore/core/src/model/field_path.h"
|
|
|
|
|
#include "Firestore/core/src/util/exception.h"
|
|
|
|
|
#include "Firestore/core/src/util/hashing.h"
|
|
|
|
|
#include "Firestore/core/src/util/string_apple.h"
|
2018-03-14 08:57:31 -04:00
|
|
|
|
|
|
|
|
namespace util = firebase::firestore::util;
|
|
|
|
|
using firebase::firestore::model::FieldPath;
|
2019-10-18 12:58:45 -07:00
|
|
|
using firebase::firestore::util::ThrowInvalidArgument;
|
2018-03-14 08:57:31 -04:00
|
|
|
|
2017-10-03 08:55:22 -07:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
2018-03-14 08:57:31 -04:00
|
|
|
@interface FIRFieldPath () {
|
|
|
|
|
/** Internal field path representation */
|
|
|
|
|
firebase::firestore::model::FieldPath _internalValue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
2017-10-03 08:55:22 -07:00
|
|
|
@implementation FIRFieldPath
|
|
|
|
|
|
|
|
|
|
- (instancetype)initWithFields:(NSArray<NSString *> *)fieldNames {
|
|
|
|
|
if (fieldNames.count == 0) {
|
2019-03-28 13:19:28 -07:00
|
|
|
ThrowInvalidArgument("Invalid field path. Provided names must not be empty.");
|
2017-10-03 08:55:22 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 22:07:45 -07:00
|
|
|
std::vector<std::string> converted;
|
|
|
|
|
converted.reserve(fieldNames.count);
|
|
|
|
|
for (NSString *fieldName in fieldNames) {
|
|
|
|
|
converted.emplace_back(util::MakeString(fieldName));
|
2017-10-03 08:55:22 -07:00
|
|
|
}
|
|
|
|
|
|
2019-06-13 22:07:45 -07:00
|
|
|
return [self initPrivate:FieldPath::FromSegments(std::move(converted))];
|
2017-10-03 08:55:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (instancetype)documentID {
|
2018-03-14 08:57:31 -04:00
|
|
|
return [[FIRFieldPath alloc] initPrivate:FieldPath::KeyFieldPath()];
|
2017-10-03 08:55:22 -07:00
|
|
|
}
|
|
|
|
|
|
2018-03-14 08:57:31 -04:00
|
|
|
- (instancetype)initPrivate:(FieldPath)fieldPath {
|
2017-10-03 08:55:22 -07:00
|
|
|
if (self = [super init]) {
|
2018-03-14 08:57:31 -04:00
|
|
|
_internalValue = std::move(fieldPath);
|
2017-10-03 08:55:22 -07:00
|
|
|
}
|
|
|
|
|
return self;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
+ (instancetype)pathWithDotSeparatedString:(NSString *)path {
|
2019-04-11 14:44:11 -07:00
|
|
|
return
|
|
|
|
|
[[FIRFieldPath alloc] initPrivate:FieldPath::FromDotSeparatedString(util::MakeString(path))];
|
2017-10-03 08:55:22 -07:00
|
|
|
}
|
|
|
|
|
|
2020-04-20 14:23:36 -07:00
|
|
|
- (id)copyWithZone:(__unused NSZone *_Nullable)zone {
|
2018-03-14 08:57:31 -04:00
|
|
|
return [[[self class] alloc] initPrivate:_internalValue];
|
2017-10-03 08:55:22 -07:00
|
|
|
}
|
|
|
|
|
|
2017-12-19 13:47:04 -05:00
|
|
|
- (BOOL)isEqual:(nullable id)object {
|
2017-10-03 08:55:22 -07:00
|
|
|
if (self == object) {
|
|
|
|
|
return YES;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (![object isKindOfClass:[FIRFieldPath class]]) {
|
|
|
|
|
return NO;
|
|
|
|
|
}
|
|
|
|
|
|
2018-03-14 08:57:31 -04:00
|
|
|
return _internalValue == ((FIRFieldPath *)object)->_internalValue;
|
2017-10-03 08:55:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (NSUInteger)hash {
|
2018-05-06 14:12:20 -07:00
|
|
|
return util::Hash(_internalValue);
|
2018-03-14 08:57:31 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
- (const firebase::firestore::model::FieldPath &)internalValue {
|
|
|
|
|
return _internalValue;
|
2017-10-03 08:55:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|