1 /********************* */
4 ** Original author: taking
5 ** Major contributors: none
6 ** Minor contributors (to current version): mdeters
7 ** This file is part of the CVC4 prototype.
8 ** Copyright (c) 2009, 2010 The Analysis of Computer Systems Group (ACSys)
9 ** Courant Institute of Mathematical Sciences
10 ** New York University
11 ** See the file COPYING in the top-level source directory for licensing
12 ** information.\endverbatim
14 ** \brief [[ Add one-line brief description here ]]
16 ** [[ Add lengthier description here ]]
17 ** \todo document this file
20 #include "cvc4_public.h"
22 #ifndef __CVC4__STATS_H
23 #define __CVC4__STATS_H
28 #include "util/Assert.h"
33 #ifdef CVC4_STATISTICS_ON
34 # define USE_STATISTICS true
36 # define USE_STATISTICS false
39 class CVC4_PUBLIC Stat
;
41 class CVC4_PUBLIC StatisticsRegistry
{
45 typedef std::set
< Stat
*, StatCmp
> StatSet
;
46 static StatSet d_registeredStats
;
49 static void flushStatistics(std::ostream
& out
);
51 static inline void registerStat(Stat
* s
) throw (AssertionException
);
52 static inline void unregisterStat(Stat
* s
) throw (AssertionException
);
53 };/* class StatisticsRegistry */
56 class CVC4_PUBLIC Stat
{
60 static std::string s_delim
;
64 Stat(const std::string
& s
) throw (CVC4::AssertionException
) : d_name(s
)
67 AlwaysAssert(d_name
.find(s_delim
) == std::string::npos
);
72 virtual void flushInformation(std::ostream
& out
) const = 0;
74 void flushStat(std::ostream
& out
) const{
76 out
<< d_name
<< s_delim
;
77 flushInformation(out
);
81 const std::string
& getName() const {
86 struct StatisticsRegistry::StatCmp
{
87 bool operator()(const Stat
* s1
, const Stat
* s2
) const
89 return (s1
->getName()) < (s2
->getName());
93 inline void StatisticsRegistry::registerStat(Stat
* s
) throw (AssertionException
){
95 AlwaysAssert(d_registeredStats
.find(s
) == d_registeredStats
.end());
96 d_registeredStats
.insert(s
);
99 inline void StatisticsRegistry::unregisterStat(Stat
* s
) throw (AssertionException
){
101 AlwaysAssert(d_registeredStats
.find(s
) != d_registeredStats
.end());
102 d_registeredStats
.erase(s
);
109 * class T must have stream insertion operation defined.
110 * std::ostream& operator<<(std::ostream&, const T&);
113 class DataStat
: public Stat
{
115 DataStat(const std::string
& s
) : Stat(s
) {}
117 virtual const T
& getData() const = 0;
118 virtual void setData(const T
&) = 0;
120 void flushInformation(std::ostream
& out
) const{
127 /** T must have an assignment operator=(). */
129 class ReferenceStat
: public DataStat
<T
>{
134 ReferenceStat(const std::string
& s
):
135 DataStat
<T
>(s
), d_data(NULL
)
138 ReferenceStat(const std::string
& s
, const T
& data
):
139 DataStat
<T
>(s
),d_data(NULL
)
144 void setData(const T
& t
){
149 const T
& getData() const{
158 /** T must have an operator=() and a copy constructor. */
160 class BackedStat
: public DataStat
<T
>{
166 BackedStat(const std::string
& s
, const T
& init
): DataStat
<T
>(s
), d_data(init
)
169 void setData(const T
& t
) {
175 BackedStat
<T
>& operator=(const T
& t
){
182 const T
& getData() const{
191 class IntStat
: public BackedStat
<int64_t>{
194 IntStat(const std::string
& s
, int64_t init
): BackedStat
<int64_t>(s
, init
)
197 IntStat
& operator++(){
204 IntStat
& operator+=(int64_t val
){
211 void maxAssign(int64_t val
){
219 void minAssign(int64_t val
){
228 #undef USE_STATISTICS
230 }/* CVC4 namespace */
232 #endif /* __CVC4__STATS_H */