Simo 0.0.1
Loading...
Searching...
No Matches
Count.h
1/*
2 * Copyright 2026 Matteo Fusi and Contributors
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#ifndef SIMO_STATISTICS_COUNT_HH
18#define SIMO_STATISTICS_COUNT_HH
19
20#include <sstream>
21#include <string>
22
23#include "Simo/compiler/Compiler.h"
24#include "Statistic.h"
25
26namespace Simo::Statistics {
28class SIMO_PUBLIC Count : public Statistic {
29 public:
30 BOOST_TYPE_INDEX_REGISTER_RUNTIME_CLASS(Statistic)
31 constexpr Count(const std::string& name, const int64_t initial_value)
32 : Statistic(name), val(initial_value) {}
33
34 constexpr Count(const Count& other) : Count(other.name_, other.val) {}
35
36 explicit constexpr Count(const std::string& name) : Count(name, 0) {}
37
38 constexpr Count() : Count("") {}
39
40 Count& operator=(const Count& other);
41
42 Count& operator+=(const int64_t& delta);
43
44 Count& operator-=(const int64_t& delta);
45
46 Count& operator++();
47
48 Count operator++(int);
49
50 Count& operator--();
51
52 Count operator--(int);
53
54 Count operator-(const Count& other) const;
55 Count operator+(const int64_t& delta) const;
56 [[nodiscard]] std::unique_ptr<Statistic> compute_delta(
57 const Statistic& other) const override;
58 void assign_from(const Statistic& other) override;
59
60 int64_t operator()() const;
61
62 [[nodiscard]] int64_t value() const;
63
64 // std::string serialize() override;
65
66 [[nodiscard]] std::unique_ptr<Statistic> clone() const override {
67 return std::make_unique<Count>(*this);
68 }
69
70 [[nodiscard]] glz::generic_u64 dump_representation() const override;
71
72 protected:
73 int64_t val{0};
74};
75} // namespace Simo::Statistics
76
77#endif // SIMO_STATISTICS_COUNT_HH
std::unique_ptr< Statistic > compute_delta(const Statistic &other) const override
Definition Count.cc:70
std::unique_ptr< Statistic > clone() const override
Create a new copy of this statistic.
Definition Count.h:66