6 #ifndef DISMEC_STATS_BASE_H
7 #define DISMEC_STATS_BASE_H
12 #include <nlohmann/json_fwd.hpp>
15 class StatisticsCollection;
54 return TagContainer(std::move(name), std::make_shared<int>());
76 [[nodiscard]]
virtual std::unique_ptr<Statistics>
clone()
const = 0;
102 virtual void record_int(
long integer) {
throw std::logic_error(
"Not implemented"); }
126 template<
class Derived>
130 static_assert(std::is_final_v<Derived>,
"Derived needs to be declared final, because further derived classes would break the merge code.");
131 static_cast<Derived*
>(
this)->merge_imp(
dynamic_cast<const Derived&
>(other));
135 for(
int i = 0; i < vector.size(); ++i) {
136 static_cast<Derived*
>(
this)->
record(vector.coeff(i));
Helper class for implementing Statistics classes.
void merge(const Statistics &other) override
Merges this statistics of another one of the same type and settings.
void record_vec(const DenseRealVector &vector) override
This class manages a collection of named Statistics objects.
TODO maybe we should solve this with a variant which does the dispatch of expected type and tag.
virtual void record_vec(const DenseRealVector &vector)
virtual void merge(const Statistics &other)=0
Merges this statistics of another one of the same type and settings.
void record(long integer)
virtual void setup(const StatisticsCollection &source)
This function has to be called before the Statistics is used to collect data for the first time.
virtual ~Statistics()=default
virtual void record_real(real_t real)
virtual nlohmann::json to_json() const =0
Converts the statistics current value into a json object.
virtual void record_int(long integer)
void record(const DenseRealVector &vector)
virtual std::unique_ptr< Statistics > clone() const =0
A tag container combines a name with a shared pointer, which points to the tag value.
static TagContainer create_full_container(std::string name)
int get_value() const
Returns the current value of the tag. Requires the container to not be empty.
std::shared_ptr< int > m_Value
const std::string & get_name() const
returns the name of the associated tag
static TagContainer create_empty_container(std::string name)
void set_value(int value)
Updates the value of the tag. Requires the container to not be empty.
TagContainer(std::string name, std::shared_ptr< int > val)
std::unique_ptr< stats::Statistics > make_stat_from_json(const nlohmann::json &source)
Generates a stats::Statistics object based on a json configuration.
types::DenseVector< real_t > DenseRealVector
Any dense, real values vector.
float real_t
The default type for floating point values.