userver: userver/server/auth/user_scopes.hpp Source File
Loading...
Searching...
No Matches
user_scopes.hpp
1#pragma once
2
3#include <functional>
4#include <string>
5#include <string_view>
6#include <vector>
7
8#include <userver/formats/parse/to.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace server::auth {
13
14class UserScope final {
15public:
16 explicit UserScope(std::string value) : value_(std::move(value)) {}
17
18 const std::string& GetValue() const { return value_; }
19
20private:
21 std::string value_;
22};
23
24inline bool operator==(const UserScope& lhs, const UserScope& rhs) { return lhs.GetValue() == rhs.GetValue(); }
25
26inline bool operator!=(const UserScope& lhs, const UserScope& rhs) { return lhs.GetValue() != rhs.GetValue(); }
27
28inline bool operator==(const UserScope& lhs, std::string_view rhs) { return lhs.GetValue() == rhs; }
29
30inline bool operator==(std::string_view lhs, const UserScope& rhs) { return lhs == rhs.GetValue(); }
31
32inline bool operator!=(const UserScope& lhs, std::string_view rhs) { return lhs.GetValue() != rhs; }
33
34inline bool operator!=(std::string_view lhs, const UserScope& rhs) { return lhs != rhs.GetValue(); }
35
36template <class Value>
37UserScope Parse(const Value& v, formats::parse::To<UserScope>) {
38 return UserScope{v.template As<std::string>()};
39}
40
41using UserScopes = std::vector<UserScope>;
42
43} // namespace server::auth
44
45USERVER_NAMESPACE_END
46
47namespace std {
48template <>
49struct hash<USERVER_NAMESPACE::server::auth::UserScope> {
50 std::size_t operator()(const USERVER_NAMESPACE::server::auth::UserScope& v) const {
51 return std::hash<std::string>{}(v.GetValue());
52 }
53};
54} // namespace std