carl  24.04
Computer ARithmetic Library
StatisticsCollector.h
Go to the documentation of this file.
1 #pragma once
2 
4 
5 #include <memory>
6 #include <string>
7 #include <vector>
8 
9 namespace carl {
10 namespace statistics {
11 
12 class Statistics;
13 
14 class StatisticsCollector: public carl::Singleton<StatisticsCollector> {
15 private:
16  std::vector<std::unique_ptr<Statistics>> mStatistics;
17 public:
18  template<typename T>
19  T& get(const std::string& name) {
20  auto& ptr = mStatistics.emplace_back(std::make_unique<T>());
21  ptr->set_name(name);
22  return static_cast<T&>(*ptr);
23  }
24 
25  void collect();
26 
27  const auto& statistics() const {
28  return mStatistics;
29  }
30 };
31 
32 template<typename T>
33 auto& get(const std::string& name) {
34  return StatisticsCollector::getInstance().get<T>(name);
35 }
36 
37 }
38 }
carl is the main namespace for the library.
auto & get(const std::string &name)
Base class that implements a singleton.
Definition: Singleton.h:24
static StatisticsCollector & getInstance()
Returns the single instance of this class by reference.
Definition: Singleton.h:45
T & get(const std::string &name)
std::vector< std::unique_ptr< Statistics > > mStatistics