Coverage Report

Created: 2025-07-06 13:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/builds/MusicScience37Projects/utility-libraries/cpp-stat-bench/include/stat_bench/custom_output_name.h
Line
Count
Source
1
/*
2
 * Copyright 2024 MusicScience37 (Kenta Kabashima)
3
 *
4
 * Licensed under the Apache License, Version 2.0 (the "License");
5
 * you may not use this file except in compliance with the License.
6
 * You may obtain a copy of the License at
7
 *
8
 *     http://www.apache.org/licenses/LICENSE-2.0
9
 *
10
 * Unless required by applicable law or agreed to in writing, software
11
 * distributed under the License is distributed on an "AS IS" BASIS,
12
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
 * See the License for the specific language governing permissions and
14
 * limitations under the License.
15
 */
16
/*!
17
 * \file
18
 * \brief Definition of CustomOutputName class.
19
 */
20
#pragma once
21
22
#include <ostream>
23
#include <string>
24
#include <utility>
25
26
#include <fmt/base.h>
27
28
#include "stat_bench/util/utf8_string.h"
29
30
namespace stat_bench {
31
32
/*!
33
 * \brief Class of names of custom outputs.
34
 */
35
class CustomOutputName {
36
public:
37
    /*!
38
     * \brief Constructor.
39
     *
40
     * \param[in] str String of the name.
41
     */
42
    explicit CustomOutputName(util::Utf8String str) noexcept;
43
44
    /*!
45
     * \brief Constructor.
46
     *
47
     * \param[in] str String of the name.
48
     */
49
    explicit CustomOutputName(std::string str)
50
2.35k
        : CustomOutputName(util::Utf8String(std::move(str))) {}
51
52
    /*!
53
     * \brief Get the string of the name.
54
     *
55
     * \return String of the name.
56
     */
57
    [[nodiscard]] auto str() const noexcept -> const util::Utf8String&;
58
59
private:
60
    //! String of the name.
61
    util::Utf8String str_;
62
};
63
64
/*!
65
 * \brief Compare two CustomOutputName objects.
66
 *
67
 * \param[in] lhs Left-hand side object.
68
 * \param[in] rhs Right-hand side object.
69
 * \retval true The two objects are equal.
70
 * \retval false The two objects are not equal.
71
 */
72
[[nodiscard]] inline auto operator==(
73
416
    const CustomOutputName& lhs, const CustomOutputName& rhs) noexcept -> bool {
74
416
    return lhs.str() == rhs.str();
75
416
}
76
77
/*!
78
 * \brief Compare two CustomOutputName objects.
79
 *
80
 * \param[in] lhs Left-hand side object.
81
 * \param[in] rhs Right-hand side object.
82
 * \retval true The two objects are not equal.
83
 * \retval false The two objects are equal.
84
 */
85
[[nodiscard]] inline auto operator!=(
86
2
    const CustomOutputName& lhs, const CustomOutputName& rhs) noexcept -> bool {
87
2
    return !(lhs == rhs);
88
2
}
89
90
}  // namespace stat_bench
91
92
namespace fmt {
93
94
/*!
95
 * \brief Implementation of fmt::formatter for
96
 * stat_bench::CustomOutputName.
97
 */
98
template <>
99
struct formatter<stat_bench::CustomOutputName>
100
    : public formatter<stat_bench::util::Utf8String> {
101
    /*!
102
     * \brief Format.
103
     *
104
     * \param[in] val Value.
105
     * \param[in] context Context.
106
     * \return Output iterator after formatting.
107
     */
108
    auto format(const stat_bench::CustomOutputName& val,
109
301
        fmt::format_context& context) const -> fmt::format_context::iterator {
110
301
        return formatter<stat_bench::util::Utf8String>::format(
111
301
            val.str(), context);
112
301
    }
113
};
114
115
}  // namespace fmt
116
117
namespace stat_bench {
118
119
/*!
120
 * \brief Format to a stream.
121
 *
122
 * \param[in,out] stream Stream.
123
 * \param[in] val Value.
124
 * \return Stream.
125
 */
126
inline auto operator<<(std::ostream& stream, const CustomOutputName& val)
127
1
    -> std::ostream& {
128
1
    return stream << val.str();
129
1
}
130
131
}  // namespace stat_bench