Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
simple_token.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef BASE_SIMPLE_TOKEN_H_
6#define BASE_SIMPLE_TOKEN_H_
7
8#include <functional>
9#include <optional>
10#include <string>
11
12namespace base {
13
14// A simple string wrapping token.
16 public:
17 // Create a random SimpleToken.
18 static SimpleToken Create();
19
20 // Creates an empty SimpleToken.
21 // Assign to it with Create() before using it.
22 SimpleToken() = default;
23 ~SimpleToken() = default;
24 // Creates an token that wrapps the input string.
25 SimpleToken(const std::string& token);
26
27 // Hex representation of the unguessable token.
28 std::string ToString() const { return token_; }
29
30 explicit constexpr operator bool() const { return !token_.empty(); }
31
32 constexpr bool operator<(const SimpleToken& other) const {
33 return token_.compare(other.token_) < 0;
34 }
35
36 constexpr bool operator==(const SimpleToken& other) const {
37 return token_.compare(other.token_) == 0;
38 }
39
40 constexpr bool operator!=(const SimpleToken& other) const {
41 return !(*this == other);
42 }
43
44 private:
45 std::string token_;
46};
47
48std::ostream& operator<<(std::ostream& out, const SimpleToken& token);
49
50std::optional<base::SimpleToken> ValueToSimpleToken(std::string str);
51
52std::string SimpleTokenToValue(const SimpleToken& token);
53
54size_t SimpleTokenHash(const SimpleToken& SimpleToken);
55
56} // namespace base
57
58#endif // BASE_SIMPLE_TOKEN_H_
constexpr bool operator!=(const SimpleToken &other) const
constexpr bool operator==(const SimpleToken &other) const
SimpleToken()=default
std::string ToString() const
static SimpleToken Create()
~SimpleToken()=default
constexpr bool operator<(const SimpleToken &other) const
size_t SimpleTokenHash(const SimpleToken &SimpleToken)
std::optional< base::SimpleToken > ValueToSimpleToken(std::string str)
std::string SimpleTokenToValue(const SimpleToken &token)
std::ostream & operator<<(std::ostream &out, const SimpleToken &token)