const char* filename = inputFromStdin ? "<stdin>" : argv[firstArgIndex];
ReferenceStat< const char* > s_statFilename("filename", filename);
- StatisticsRegistry::registerStat(&s_statFilename);
+ RegisterStatistic statFilenameReg(&s_statFilename);
if(options.inputLanguage == language::input::LANG_AUTO) {
if( inputFromStdin ) {
#endif
ReferenceStat< Result > s_statSatResult("sat/unsat", result);
- StatisticsRegistry::registerStat(&s_statSatResult);
+ RegisterStatistic statSatResultReg(&s_statSatResult);
if(options.statistics) {
StatisticsRegistry::flushStatistics(*options.err);
}
- StatisticsRegistry::unregisterStat(&s_statSatResult);
- StatisticsRegistry::unregisterStat(&s_statFilename);
-
return returnValue;
}
} \
} _StatField
+/**
+ * Resource-acquisition-is-initialization idiom for statistics
+ * registry. Useful for stack-based statistics (like in the driver).
+ * Generally, for statistics kept in a member field of class, it's
+ * better to use the above KEEP_STATISTIC(), which does declaration of
+ * the member, construction of the statistic, and
+ * registration/unregistration. This RAII class only does
+ * registration and unregistration.
+ */
+class RegisterStatistic {
+ Stat* d_stat;
+public:
+ RegisterStatistic(Stat* stat) : d_stat(stat) {
+ StatisticsRegistry::registerStat(d_stat);
+ }
+ ~RegisterStatistic() {
+ StatisticsRegistry::unregisterStat(d_stat);
+ }
+};/* class RegisterStatistic */
+
#undef __CVC4_USE_STATISTICS
}/* CVC4 namespace */