dReal4
stat.h
1 #pragma once
2 
3 #include <atomic>
4 
5 namespace dreal {
6 
7 /// Base class for statistics.
8 class Stat {
9  public:
10  explicit Stat(bool enabled) : enabled_{enabled} {}
11  Stat(const Stat&) = default;
12  Stat(Stat&&) = default;
13  Stat& operator=(const Stat&) = delete;
14  Stat& operator=(Stat&&) = delete;
15  virtual ~Stat() = default;
16 
17  /// Returns true if the logging is enabled. Normally, this is
18  /// checked in the destructor of a derived class and determine
19  /// whether to log or not.
20  bool enabled() const { return enabled_; }
21 
22  protected:
23  template <typename T>
24  void increase(std::atomic<T>* v) {
25  if (enabled_) {
26  std::atomic_fetch_add_explicit(v, 1, std::memory_order_relaxed);
27  }
28  }
29 
30  private:
31  const bool enabled_{false};
32 };
33 } // namespace dreal
bool enabled() const
Returns true if the logging is enabled.
Definition: stat.h:20
Sum type of symbolic::Expression and symbolic::Formula.
Definition: api.cc:9
Base class for statistics.
Definition: stat.h:8