return !cmd->fail();
}
-void printStatsIncremental(std::ostream& out, const std::string& prvsStatsString, const std::string& curStatsString) {
+void printStatsIncremental(std::ostream& out,
+ const std::string& prvsStatsString,
+ const std::string& curStatsString)
+{
if(prvsStatsString == "") {
out << curStatsString;
return;
(std::istringstream(curStatValue) >> curFloat);
if(isFloat) {
+ const std::streamsize old_precision = out.precision();
out << curStatName << ", " << curStatValue << " "
<< "(" << std::setprecision(8) << (curFloat-prvsFloat) << ")"
<< std::endl;
+ out.precision(old_precision);
} else {
out << curStatName << ", " << curStatValue << std::endl;
}
#include "theory/arith/constraint.h"
#include "theory/arith/cut_log.h"
#include "theory/arith/normal_form.h"
+#include "util/ostream_util.h"
using namespace std;
}
void PrimitiveVec::print(std::ostream& out) const{
Assert(initialized());
- out << len << " ";
- out.precision(15);
+ StreamFormatScope scope(out);
+
+ out << len << " " << std::setprecision(15);
for(int i = 1; i <= len; ++i){
out << "["<< inds[i] <<", " << coeffs[i]<<"]";
}
index.h \
maybe.h \
ntuple.h \
+ ostream_util.cpp \
+ ostream_util.h \
proof.h \
regexp.cpp \
regexp.h \
--- /dev/null
+/********************* */
+/*! \file result.cpp
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Tim King, Morgan Deters, Andrew Reynolds
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved. See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Utilities for using ostreams.
+ **
+ ** Utilities for using ostreams.
+ **/
+#include "util/ostream_util.h"
+
+namespace CVC4 {
+
+StreamFormatScope::StreamFormatScope(std::ostream& out)
+ : d_out(out), d_format_flags(out.flags()), d_precision(out.precision())
+{
+}
+
+StreamFormatScope::~StreamFormatScope()
+{
+ d_out.precision(d_precision);
+ d_out.flags(d_format_flags);
+}
+
+} // namespace CVC4
--- /dev/null
+/********************* */
+/*! \file ostream_util.h
+ ** \verbatim
+ ** Top contributors (to current version):
+ ** Tim King
+ ** This file is part of the CVC4 project.
+ ** Copyright (c) 2009-2017 by the authors listed in the file AUTHORS
+ ** in the top-level source directory) and their institutional affiliations.
+ ** All rights reserved. See the file COPYING in the top-level source
+ ** directory for licensing information.\endverbatim
+ **
+ ** \brief Utilities for using ostreams.
+ **
+ ** Utilities for using ostreams.
+ **/
+
+#include "cvc4_private.h"
+
+#ifndef __CVC4__UTIL__OSTREAM_UTIL_H
+#define __CVC4__UTIL__OSTREAM_UTIL_H
+
+#include <ios>
+#include <ostream>
+
+namespace CVC4 {
+
+// Saves the formatting of an ostream and restores the previous settings on
+// destruction. Example usage:
+// void Foo::Print(std::ostream& out) {
+// StreamFormatScope format_scope(out);
+// out << std::setprecision(6) << bar();
+// }
+class StreamFormatScope
+{
+ public:
+ // `out` must outlive StreamFormatScope.
+ StreamFormatScope(std::ostream& out);
+ ~StreamFormatScope();
+
+ private:
+ // Does not own the memory of d_out
+ std::ostream& d_out;
+ std::ios_base::fmtflags d_format_flags;
+ std::streamsize d_precision;
+};
+
+} // namespace CVC4
+
+#endif /* __CVC4__UTIL__OSTREAM_UTIL_H */
#include "base/cvc4_assert.h"
#include "options/set_language.h"
+#include "util/ostream_util.h"
#include "util/smt2_quote_string.h"
namespace CVC4 {
void SExpr::toStreamRec(std::ostream& out, const SExpr& sexpr,
OutputLanguage language, int indent) {
+ StreamFormatScope scope(out);
+
if (sexpr.isInteger()) {
out << sexpr.getIntegerValue();
} else if (sexpr.isRational()) {
#include "base/cvc4_assert.h"
#include "lib/clock_gettime.h"
-
+#include "util/ostream_util.h"
#ifdef CVC4_STATISTICS_ON
# define __CVC4_USE_STATISTICS true
/** Output a timespec on an output stream. */
std::ostream& operator<<(std::ostream& os, const timespec& t) {
// assumes t.tv_nsec is in range
+ StreamFormatScope format_scope(os);
return os << t.tv_sec << "."
<< std::setfill('0') << std::setw(9) << std::right << t.tv_nsec;
}