aboutsummaryrefslogtreecommitdiffhomepage
path: root/Firestore/core
diff options
context:
space:
mode:
authorGravatar zxu <zxu@google.com>2018-02-15 17:23:08 -0500
committerGravatar GitHub <noreply@github.com>2018-02-15 17:23:08 -0500
commitfd9fd271d0dba3935a6f5611a1554f2c59b696af (patch)
treebe6d8355254891cb83201c7bfac2082c0f95978f /Firestore/core
parent6889850b251ab56186bc13765baee0c3d0f1ae61 (diff)
replacing Auth/FSTUser by C++ auth implementation (#804)
* replacing Auth/FSTUser by C++ auth implementation * address changes
Diffstat (limited to 'Firestore/core')
-rw-r--r--Firestore/core/src/firebase/firestore/auth/user.h19
-rw-r--r--Firestore/core/test/firebase/firestore/auth/user_test.cc5
2 files changed, 24 insertions, 0 deletions
diff --git a/Firestore/core/src/firebase/firestore/auth/user.h b/Firestore/core/src/firebase/firestore/auth/user.h
index 58b8b55..cc7b66d 100644
--- a/Firestore/core/src/firebase/firestore/auth/user.h
+++ b/Firestore/core/src/firebase/firestore/auth/user.h
@@ -17,6 +17,11 @@
#ifndef FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_AUTH_USER_H_
#define FIRESTORE_CORE_SRC_FIREBASE_FIRESTORE_AUTH_USER_H_
+#if defined(__OBJC__)
+#import <Foundation/Foundation.h>
+#include "Firestore/core/src/firebase/firestore/util/string_apple.h"
+#endif // defined(__OBJC__)
+
#include <string>
#include "absl/strings/string_view.h"
@@ -38,6 +43,12 @@ class User {
/** Construct an authenticated user with the given UID. */
explicit User(const absl::string_view uid);
+#if defined(__OBJC__)
+ explicit User(NSString* uid)
+ : User(firebase::firestore::util::MakeStringView(uid)) {
+ }
+#endif // defined(__OBJC__)
+
const std::string& uid() const {
return uid_;
}
@@ -69,6 +80,14 @@ inline bool operator!=(const User& lhs, const User& rhs) {
return !(lhs == rhs);
}
+// Specializations of std::hash is prohibited. We define a hash function to be
+// passed through manually.
+struct HashUser {
+ inline int64_t operator()(const User& user) const {
+ return std::hash<std::string>{}(user.uid());
+ }
+};
+
} // namespace auth
} // namespace firestore
} // namespace firebase
diff --git a/Firestore/core/test/firebase/firestore/auth/user_test.cc b/Firestore/core/test/firebase/firestore/auth/user_test.cc
index a9f764d..7277283 100644
--- a/Firestore/core/test/firebase/firestore/auth/user_test.cc
+++ b/Firestore/core/test/firebase/firestore/auth/user_test.cc
@@ -49,6 +49,11 @@ TEST(User, Comparison) {
EXPECT_NE(User("abc"), User("xyz"));
}
+TEST(User, Hash) {
+ const HashUser hash;
+ EXPECT_EQ(hash(User("abc")), hash(User("abc")));
+}
+
} // namespace auth
} // namespace firestore
} // namespace firebase