cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
parameter_dict.h
Go to the documentation of this file.
1/*
2 * Copyright 2021 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 */
20#pragma once
21
22// IWYU pragma: no_include <string>
23
24#include <cstddef>
25#include <functional>
26#include <unordered_map>
27#include <utility>
28
29#include <fmt/base.h>
30#include <fmt/format.h>
31
37
38namespace stat_bench {
39namespace param {
40
45public:
51 explicit ParameterDict(
53
60 [[nodiscard]] auto empty() const noexcept -> bool;
61
69 [[nodiscard]] auto has(const ParameterName& param_name) const -> bool;
70
78 template <typename T>
79 [[nodiscard]] auto get(const ParameterName& param_name) const -> const T& {
80 const auto iter = data_.find(param_name);
81 if (iter == data_.end()) {
83 fmt::format("Parameter {} not found.", param_name));
84 }
85 return iter->second.as<T>();
86 }
87
94 [[nodiscard]] auto get_as_double(const ParameterName& param_name) const
95 -> double;
96
103 [[nodiscard]] auto get_as_variant(const ParameterName& param_name) const
105
112 [[nodiscard]] auto format_to(fmt::format_context::iterator out) const
113 -> fmt::format_context::iterator;
114
120 [[nodiscard]] auto as_string_dict() const
121 -> std::unordered_map<util::Utf8String, util::Utf8String>;
122
129 [[nodiscard]] auto clone_without(const ParameterName& param_name) const
130 -> ParameterDict;
131
137 [[nodiscard]] auto calculate_hash() const -> std::size_t;
138
146 [[nodiscard]] auto operator==(const ParameterDict& rhs) const -> bool;
147
155 [[nodiscard]] auto operator!=(const ParameterDict& rhs) const -> bool;
156
157private:
159 util::OrderedMap<ParameterName, ParameterValue> data_;
160};
161
162} // namespace param
163} // namespace stat_bench
164
165namespace fmt {
166
171template <>
172struct formatter<stat_bench::param::ParameterDict>
173 : public formatter<string_view> {
182 format_context& context) const -> typename format_context::iterator;
183};
184
185} // namespace fmt
186
187namespace std {
188
192template <>
193class hash<stat_bench::param::ParameterDict> {
194public:
202 -> std::size_t {
203 return dict.calculate_hash();
204 }
205};
206
207} // namespace std
Class of exceptions in this library.
Class of dictionaries of parameters.
auto format_to(fmt::format_context::iterator out) const -> fmt::format_context::iterator
Format to string.
auto get_as_double(const ParameterName &param_name) const -> double
Get a parameter value as double.
auto has(const ParameterName &param_name) const -> bool
Check whether this has a parameter with a name.
auto get_as_variant(const ParameterName &param_name) const -> ParameterValueVariant
Get a parameter value as a variant object.
auto empty() const noexcept -> bool
Check whether this is empty.
auto clone_without(const ParameterName &param_name) const -> ParameterDict
Create a new dictionary without a parameter.
auto as_string_dict() const -> std::unordered_map< util::Utf8String, util::Utf8String >
Get as a dictionary of string values.
ParameterDict(util::OrderedMap< ParameterName, ParameterValue > data)
Constructor.
auto calculate_hash() const -> std::size_t
Calculate hash value.
auto get(const ParameterName &param_name) const -> const T &
Get a parameter value.
Class of names of parameters.
Class of values of parameters.
Class of mapping which preserves order of insertion.
Definition ordered_map.h:39
auto operator()(const stat_bench::param::ParameterDict &dict) const -> std::size_t
Operator.
Namespace of fmt library.
Namespace of parameters of benchmarks.
std::variant< bool, std::intmax_t, std::uintmax_t, long double, std::string > ParameterValueVariant
Type of variant of parameter values.
Namespace of utility functions and classes.
Namespace of stat_bench source codes.
STL namespace.
Definition of OrderedMap class.
Definition of ParameterName class.
Definition of ParameterValue class.
Definition of StatBenchException class.
auto format(const stat_bench::param::ParameterDict &val, format_context &context) const -> typename format_context::iterator
Format.
Definition of Utf8String class.