cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
json_data_file_helper.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#include <functional>
23#include <string>
24#include <unordered_map>
25
26#include <nlohmann/adl_serializer.hpp>
27#include <nlohmann/json.hpp>
28
31
32namespace nlohmann {
33
38template <>
39struct adl_serializer<stat_bench::util::Utf8String> {
46 static void to_json(json& j, const stat_bench::util::Utf8String& val) {
47 j = val.str();
48 }
49
56 static void from_json(const json& j, stat_bench::util::Utf8String& val) {
57 val = stat_bench::util::Utf8String(j.get<std::string>());
58 }
59};
60
66template <>
67struct adl_serializer<std::unordered_map<stat_bench::util::Utf8String,
68 stat_bench::util::Utf8String>> {
75 static void to_json(json& j,
76 const std::unordered_map<stat_bench::util::Utf8String,
78 for (const auto& [key, value] : val) {
79 j[key.str()] = value.str();
80 }
81 }
82
89 static void from_json(const json& j,
90 std::unordered_map<stat_bench::util::Utf8String,
92 for (auto it = j.begin(); it != j.end(); ++it) {
93 val[stat_bench::util::Utf8String(it.key())] =
94 stat_bench::util::Utf8String(it.value().get<std::string>());
95 }
96 }
97};
98
99} // namespace nlohmann
100
101namespace stat_bench {
102namespace reporter {
103namespace data_file_spec {
104
105#ifndef STAT_BENCH_DOCUMENTATION
106
107NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(StatData, mean, max, min, median, variance,
108 standard_deviation, standard_error)
109
110NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(DurationData, stat, values)
111
112NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CustomStatOutputData, name, stat, values)
113
114NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(CustomOutputData, name, value)
115
116NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(MeasurementData, group_name, case_name,
117 params, measurer_name, iterations, samples, durations, custom_stat_outputs,
118 custom_outputs)
119
120NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(
121 RootData, started_at, finished_at, measurements)
122
123#endif
124
125} // namespace data_file_spec
126} // namespace reporter
127} // namespace stat_bench
Class of UTF-8 encoded string.
Definition utf8_string.h:35
auto str() const noexcept -> const std::string &
Get the string.
Definition of structs to specify the structure of data files.
Namespace of nlohmann::json library.
Namespace of specification of data files.
Namespace of reporters of results of benchmarks.
Namespace of stat_bench source codes.
STL namespace.
static void from_json(const json &j, stat_bench::util::Utf8String &val)
Convert JSON to a value.
static void to_json(json &j, const stat_bench::util::Utf8String &val)
Convert a value to JSON.
static void from_json(const json &j, std::unordered_map< stat_bench::util::Utf8String, stat_bench::util::Utf8String > &val)
Convert JSON to a value.
static void to_json(json &j, const std::unordered_map< stat_bench::util::Utf8String, stat_bench::util::Utf8String > &val)
Convert a value to JSON.
Struct of custom outputs without statistics.
Struct of custom outputs with statistics.
Struct of root objects in data files.
Definition of Utf8String class.