Simo 0.0.1
Loading...
Searching...
No Matches
StatOutStream.h
1// Copyright 2026 Matteo Fusi and Contributors
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef SIMO_STATOUTSTREAM_HH
16#define SIMO_STATOUTSTREAM_HH
17
18#include <glaze/yaml.hpp>
19
20namespace Simo::Statistics {
21
22class StatMapper;
23class Statistic;
24
27 public:
28 virtual ~StatOutStreamInterface() = default;
29
30 template <typename Self>
31 Self& operator<<(this Self&& self, const Statistic& s) {
32 return self << s;
33 }
34
35 template <typename Self>
36 void reset(this Self&& self) {
37 self.reset();
38 }
39 template <typename Self>
40 void generate(this Self&& self) {
41 self.generate();
42 }
43};
44
46class StatOutStream : public StatOutStreamInterface {
47 public:
48 ~StatOutStream() override = default;
49
50 StatOutStream() : array(glz::generic_u64::array_t{}) {}
51
52 std::filesystem::path output_path() const { return output_path_; }
53 void output_path(std::filesystem::path path) {
54 output_path_ = std::move(path);
55 }
56
57 StatOutStream& operator<<(const Statistic& s) {
58 array.get<glz::generic_u64::array_t>().emplace_back(
59 s.dump_representation());
60 return *this;
61 }
62
63 void reset() { array = glz::generic_u64::array_t{}; }
64
65 void generate() {
66 std::string buffer;
67 // TODO hanndle errors
68 auto _ = glz::write_file_yaml(array, output_path().c_str());
69 }
70
71 private:
72 std::filesystem::path output_path_;
73 glz::generic_u64 array;
74};
75} // namespace Simo::Statistics
76
77#endif // SIMO_STATOUTSTREAM_HH
Definition StatMapper.h:33
Base class to dump statistics.
Definition StatOutStream.h:26
Base class for all statistics.
Definition Statistic.h:26