stage/structure/tokens.h
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // SPDX-License-Identifier: BSD-3-Clause | ||
| 2 | #pragma once | ||
| 3 | |||
| 4 | #include <cstdint> | ||
| 5 | #include <deque> | ||
| 6 | #include <string> | ||
| 7 | #include <string_view> | ||
| 8 | #include <unordered_map> | ||
| 9 | |||
| 10 | namespace chrono::batch_render { | ||
| 11 | |||
| 12 | 41411 | struct Token { | |
| 13 | uint32_t id = 0; | ||
| 14 | |||
| 15 | 261 | bool operator==(const Token& other) const { | |
| 16 | 261 | return id == other.id; | |
| 17 | } | ||
| 18 | |||
| 19 | bool operator!=(const Token& other) const { | ||
| 20 | return !(*this == other); | ||
| 21 | } | ||
| 22 | }; | ||
| 23 | |||
| 24 | 10 | class Tokens { | |
| 25 | public: | ||
| 26 | Tokens(); | ||
| 27 | Tokens(const Tokens&) = delete; | ||
| 28 | Tokens& operator=(const Tokens&) = delete; | ||
| 29 | 1 | Tokens(Tokens&&) = default; | |
| 30 | Tokens& operator=(Tokens&&) = default; | ||
| 31 | |||
| 32 | Token Intern(std::string_view text); | ||
| 33 | Token Find(std::string_view text) const; | ||
| 34 | std::string_view Text(Token token) const; | ||
| 35 | |||
| 36 | 1 | uint32_t Size() const { | |
| 37 | 1 | return uint32_t(m_texts.size()); | |
| 38 | } | ||
| 39 | |||
| 40 | private: | ||
| 41 | std::deque<std::string> m_texts; | ||
| 42 | std::unordered_map<std::string_view, uint32_t> m_ids; | ||
| 43 | }; | ||
| 44 | |||
| 45 | } | ||
| 46 |