cpp-stat-bench 0.24.0
Benchmark library with statistics for C++.
Loading...
Searching...
No Matches
msgpack_reporter.cpp
Go to the documentation of this file.
1/*
2 * Copyright 2023 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 */
21
22#include <cstdio>
23#include <utility>
24
25#include <msgpack_light/output_stream.h>
26#include <msgpack_light/serialize.h>
27
28#include "stat_bench/reporter/msgpack_data_file_helper.h" // IWYU pragma: keep
31
32namespace stat_bench {
33namespace reporter {
34
38class MsgpackOutputFileStream : public msgpack_light::output_stream {
39public:
45 explicit MsgpackOutputFileStream(const std::string& file_path)
46 : file_(std::fopen(file_path.c_str(), "wb")) {}
47
48 MsgpackOutputFileStream(const MsgpackOutputFileStream&) = delete;
49 MsgpackOutputFileStream(MsgpackOutputFileStream&&) = delete;
50 auto operator=(const MsgpackOutputFileStream&)
51 -> MsgpackOutputFileStream& = delete;
52 auto operator=(MsgpackOutputFileStream&&)
53 -> MsgpackOutputFileStream& = delete;
54
58 ~MsgpackOutputFileStream() { (void)std::fclose(file_); }
59
66 void write(const unsigned char* data, std::size_t size) override {
67 if (std::fwrite(data, 1, size, file_) != size) {
68 throw StatBenchException("Failed to write data.");
69 }
70 }
71
72private:
74 std::FILE* file_;
75};
76
78 : DataFileReporterBase(std::move(file_path)) {}
79
81 const std::string& file_path, const data_file_spec::RootData& data) {
83
84 MsgpackOutputFileStream stream{file_path};
85 msgpack_light::serialize_to(stream, data);
86}
87
88} // namespace reporter
89} // namespace stat_bench
DataFileReporterBase(std::string file_path)
Constructor.
MsgPackReporter(std::string file_path)
Constructor.
void write_data_file(const std::string &file_path, const data_file_spec::RootData &data) override
Write a data file.
Helper of MsgPack data files.
Definition of MsgPackReporter class.
Namespace of reporters of results of benchmarks.
void prepare_directory_for(const std::string &path)
Prepare a directory for a file.
Namespace of stat_bench source codes.
STL namespace.
Declaration of prepare_directory function.
Definition of StatBenchException class.
Struct of root objects in data files.