diff options
author | Tim King <taking@cs.nyu.edu> | 2018-02-02 17:03:10 -0800 |
---|---|---|
committer | Andrew Reynolds <andrew.j.reynolds@gmail.com> | 2018-02-02 19:03:10 -0600 |
commit | 1b24f3f0fd5fdd4163a46689949fa8a5c60f3322 (patch) | |
tree | d312cd6b42f002a4545e819bb097ada72d6249e0 /src/util/ostream_util.h | |
parent | ae5c1a5c3a9c6eb7d1af1a4ddbcb841cf7ce4c70 (diff) |
Restoring ostream format. Resolves a few CIDs 1362780. (#1543)
Diffstat (limited to 'src/util/ostream_util.h')
-rw-r--r-- | src/util/ostream_util.h | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/util/ostream_util.h b/src/util/ostream_util.h new file mode 100644 index 000000000..e047caa17 --- /dev/null +++ b/src/util/ostream_util.h @@ -0,0 +1,49 @@ +/********************* */ +/*! \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 */ |