GCC Code Coverage Report
Directory: . Exec Total Coverage
File: src/util/statistics.h Lines: 4 5 80.0 %
Date: 2021-03-23 Branches: 0 0 0.0 %

Line Exec Source
1
/*********************                                                        */
2
/*! \file statistics.h
3
 ** \verbatim
4
 ** Top contributors (to current version):
5
 **   Morgan Deters, Andres Noetzli, Mathias Preiner
6
 ** This file is part of the CVC4 project.
7
 ** Copyright (c) 2009-2021 by the authors listed in the file AUTHORS
8
 ** in the top-level source directory and their institutional affiliations.
9
 ** All rights reserved.  See the file COPYING in the top-level source
10
 ** directory for licensing information.\endverbatim
11
 **
12
 ** \brief [[ Add one-line brief description here ]]
13
 **
14
 ** [[ Add lengthier description here ]]
15
 ** \todo document this file
16
 **/
17
18
#include "cvc4_public.h"
19
20
#ifndef CVC4__STATISTICS_H
21
#define CVC4__STATISTICS_H
22
23
#include <iterator>
24
#include <ostream>
25
#include <set>
26
#include <string>
27
#include <utility>
28
29
#include "cvc4_export.h"
30
#include "util/sexpr.h"
31
32
namespace CVC4 {
33
34
class Stat;
35
36
class CVC4_EXPORT StatisticsBase
37
{
38
 protected:
39
  /** A helper class for comparing two statistics */
40
  struct StatCmp {
41
    bool operator()(const Stat* s1, const Stat* s2) const;
42
  };/* struct StatisticsRegistry::StatCmp */
43
44
  /** A type for a set of statistics */
45
  typedef std::set< Stat*, StatCmp > StatSet;
46
47
  /** The set of statistics in this object */
48
  StatSet d_stats;
49
50
  StatisticsBase();
51
  StatisticsBase(const StatisticsBase& stats);
52
  StatisticsBase& operator=(const StatisticsBase& stats);
53
54
public:
55
56
9601
  virtual ~StatisticsBase() { }
57
58
  class iterator : public std::iterator<std::input_iterator_tag,
59
                                        std::pair<std::string, SExpr> >
60
  {
61
    StatSet::iterator d_it;
62
63
40
    iterator(StatSet::iterator it) : d_it(it) { }
64
65
    friend class StatisticsBase;
66
67
  public:
68
    iterator() : d_it() { }
69
    iterator(const iterator& it) : d_it(it.d_it) { }
70
    value_type operator*() const;
71
38
    iterator& operator++() { ++d_it; return *this; }
72
    iterator operator++(int) { iterator old = *this; ++d_it; return old; }
73
    bool operator==(const iterator& i) const { return d_it == i.d_it; }
74
39
    bool operator!=(const iterator& i) const { return d_it != i.d_it; }
75
  }; /* class StatisticsBase::iterator */
76
77
  /** An iterator type over a set of statistics. */
78
  typedef iterator const_iterator;
79
80
  /** Flush all statistics to the given output stream. */
81
  void flushInformation(std::ostream& out) const;
82
83
  /**
84
   * Flush all statistics to the given file descriptor. Safe to use in a signal
85
   * handler.
86
   */
87
  void safeFlushInformation(int fd) const;
88
89
  /** Get the value of a named statistic. */
90
  SExpr getStatistic(std::string name) const;
91
92
  /**
93
   * Get an iterator to the beginning of the range of the set of
94
   * statistics.
95
   */
96
  const_iterator begin() const;
97
98
  /**
99
   * Get an iterator to the end of the range of the set of statistics.
100
   */
101
  const_iterator end() const;
102
103
}; /* class StatisticsBase */
104
105
class Statistics : public StatisticsBase
106
{
107
  void clear();
108
  void copyFrom(const StatisticsBase&);
109
110
public:
111
112
  /**
113
   * Override the copy constructor to do a "deep" copy of statistics
114
   * values.
115
   */
116
  Statistics(const StatisticsBase& stats);
117
  Statistics(const Statistics& stats);
118
119
  ~Statistics();
120
121
  /**
122
   * Override the assignment operator to do a "deep" copy of statistics
123
   * values.
124
   */
125
  Statistics& operator=(const StatisticsBase& stats);
126
  Statistics& operator=(const Statistics& stats);
127
128
}; /* class Statistics */
129
130
}/* CVC4 namespace */
131
132
#endif /* CVC4__STATISTICS_H */