userver: userver/server/auth/user_scopes.hpp Source File
⚠️ This is the documentation for an old userver version. Click here to switch to the latest version.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
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 {
15 public:
16 explicit UserScope(std::string value) : value_(std::move(value)) {}
17
18 const std::string& GetValue() const { return value_; }
19
20 private:
21 std::string value_;
22};
23
24inline bool operator==(const UserScope& lhs, const UserScope& rhs) {
25 return lhs.GetValue() == rhs.GetValue();
26}
27
28inline bool operator!=(const UserScope& lhs, const UserScope& rhs) {
29 return lhs.GetValue() != rhs.GetValue();
30}
31
32inline bool operator==(const UserScope& lhs, std::string_view rhs) {
33 return lhs.GetValue() == rhs;
34}
35
36inline bool operator==(std::string_view lhs, const UserScope& rhs) {
37 return lhs == rhs.GetValue();
38}
39
40inline bool operator!=(const UserScope& lhs, std::string_view rhs) {
41 return lhs.GetValue() != rhs;
42}
43
44inline bool operator!=(std::string_view lhs, const UserScope& rhs) {
45 return lhs != rhs.GetValue();
46}
47
48template <class Value>
49UserScope Parse(const Value& v, formats::parse::To<UserScope>) {
50 return UserScope{v.template As<std::string>()};
51}
52
53using UserScopes = std::vector<UserScope>;
54
55} // namespace server::auth
56
57USERVER_NAMESPACE_END
58
59namespace std {
60template <>
61struct hash<USERVER_NAMESPACE::server::auth::UserScope> {
62 std::size_t operator()(
63 const USERVER_NAMESPACE::server::auth::UserScope& v) const {
64 return std::hash<std::string>{}(v.GetValue());
65 }
66};
67} // namespace std