Thread System 0.3.1
High-performance C++20 thread pool with work stealing and DAG scheduling
Loading...
Searching...
No Matches
test_type.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
7#include "utilities/core/formatter.h"
8#include "utilities/conversion/convert_string.h"
9
10#include <string>
11#include <array>
12#include <cstdint>
13#include <string_view>
14
22enum class test_priority : uint8_t
23{
24 Top = 0,
25 Middle,
26 Bottom
27};
28
29namespace test_detail
30{
34 constexpr std::array test_priority_strings = { "Top", "Middle", "Bottom" };
35
39 constexpr size_t test_priority_count = test_priority_strings.size();
40
41 // Compile-time check to ensure test_priority_strings and test_priority are in sync
42 static_assert(test_priority_count == static_cast<size_t>(test_priority::Bottom) + 1,
43 "test_priority_strings and test_priority enum are out of sync");
44}
45
51[[nodiscard]] constexpr std::string_view to_string(test_priority priority)
52{
53 auto index = static_cast<size_t>(priority);
55 : "Unknown";
56}
57
62[[nodiscard]] inline auto all_types(void) -> std::vector<test_priority>
63{
65}
66
67// ----------------------------------------------------------------------------
68// Formatter specializations for test_priority
69// ----------------------------------------------------------------------------
70
75template <> struct std::formatter<test_priority> : std::formatter<std::string_view>
76{
84 template <typename FormatContext>
85 auto format(const test_priority& priority, FormatContext& ctx) const
86 {
87 return std::formatter<std::string_view>::format(to_string(priority), ctx);
88 }
89};
90
95template <>
96struct std::formatter<test_priority, wchar_t> : std::formatter<std::wstring_view, wchar_t>
97{
105 template <typename FormatContext>
106 auto format(const test_priority& priority, FormatContext& ctx) const
107 {
108 auto str = to_string(priority);
109 auto wstr = convert_string::to_wstring(str);
110 return std::formatter<std::wstring_view, wchar_t>::format(wstr, ctx);
111 }
112};
constexpr std::array test_priority_strings
Array of string representations for each test priority level.
Definition test_type.h:34
constexpr size_t test_priority_count
Total number of test types available in test_priority_strings.
Definition test_type.h:39
auto format(const test_priority &priority, FormatContext &ctx) const
Formats a test_priority value as a wide string.
Definition test_type.h:106
auto format(const test_priority &priority, FormatContext &ctx) const
Formats a test_priority value as a string.
Definition test_type.h:85
test_priority
Enumeration of test priority levels.
Definition test_type.h:23
@ Bottom
Bottom priority.
@ Top
Top priority.
@ Middle
Middle priority.
constexpr std::string_view to_string(test_priority priority)
Converts a test_priority value to its string representation.
Definition test_type.h:51
auto all_types(void) -> std::vector< test_priority >
Converts a string to a job_types value.
Definition test_type.h:62