summaryrefslogtreecommitdiff
path: root/src/smt/managed_ostreams.cpp
diff options
context:
space:
mode:
authorGereon Kremer <nafur42@gmail.com>2021-08-04 11:35:41 -0700
committerGitHub <noreply@github.com>2021-08-04 18:35:41 +0000
commitcc9155e74a4c7fbbf66f736e0d6f67499329ba69 (patch)
tree7285753f9645683bc5190856bf61f250a9f62225 /src/smt/managed_ostreams.cpp
parent3f2e127061ee03db1ba8ff56d9dfb42fbe9d60b1 (diff)
Refactor managed streams (#6934)
This PR introduces a new ManagedStream class that replaces the previous ManagedOstream. It allows to directly store the (wrapped) stream objects in the options. Handling the stream options is moved from the options manager to option predicates and the different options for input and output streams are combined into a single one. Some associated utilities (open_ostream.h and update_ostream.h) are now obsolete and thus removed.
Diffstat (limited to 'src/smt/managed_ostreams.cpp')
-rw-r--r--src/smt/managed_ostreams.cpp169
1 files changed, 0 insertions, 169 deletions
diff --git a/src/smt/managed_ostreams.cpp b/src/smt/managed_ostreams.cpp
deleted file mode 100644
index b09448c11..000000000
--- a/src/smt/managed_ostreams.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/******************************************************************************
- * Top contributors (to current version):
- * Tim King, Aina Niemetz
- *
- * This file is part of the cvc5 project.
- *
- * Copyright (c) 2009-2021 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.
- * ****************************************************************************
- *
- * Wrappers to handle memory management of ostreams.
- *
- * This file contains wrappers to handle special cases of managing memory
- * related to ostreams.
- */
-
-#include "smt/managed_ostreams.h"
-
-#include <ostream>
-
-#include "base/check.h"
-#include "options/open_ostream.h"
-#include "options/option_exception.h"
-#include "options/smt_options.h"
-#include "smt/update_ostream.h"
-
-namespace cvc5 {
-
-ManagedOstream::ManagedOstream() : d_managed(NULL) {}
-
-ManagedOstream::~ManagedOstream() {
- manage(NULL);
- Assert(d_managed == NULL);
-}
-
-void ManagedOstream::set(const std::string& filename) {
- std::pair<bool, std::ostream*> pair = open(filename);
- initialize(pair.second);
- manage(pair.first ? pair.second : NULL);
-}
-
-std::pair<bool, std::ostream*> ManagedOstream::open(const std::string& filename)
- const {
- OstreamOpener opener(getName());
- addSpecialCases(&opener);
- return opener.open(filename);
-}
-
-void ManagedOstream::manage(std::ostream* new_managed_value) {
- if(d_managed == new_managed_value){
- // This is a no-op.
- } else {
- Assert(d_managed != new_managed_value);
- std::ostream* old_managed_value = d_managed;
- d_managed = new_managed_value;
- if(old_managed_value != NULL){
- delete old_managed_value;
- }
- }
-}
-
-ManagedDumpOStream::~ManagedDumpOStream() {
- if(Dump.getStreamPointer() == getManagedOstream()) {
- Dump.setStream(&null_os);
- }
-}
-
-std::string ManagedDumpOStream::defaultSource() const{
- return options::dumpToFileName();
-}
-
-
-void ManagedDumpOStream::initialize(std::ostream* outStream) {
-#ifdef CVC5_DUMPING
- DumpOstreamUpdate dumpGetStream;
- dumpGetStream.apply(outStream);
-#else /* CVC5_DUMPING */
- throw OptionException(
- "The dumping feature was disabled in this build of cvc5.");
-#endif /* CVC5_DUMPING */
-}
-
-void ManagedDumpOStream::addSpecialCases(OstreamOpener* opener) const {
- opener->addSpecialCase("-", &DumpOutC::dump_cout);
-}
-
-ManagedRegularOutputChannel::~ManagedRegularOutputChannel() {
- // Set all ostream that may still be using the old value of this channel
- // to null_os. Consult RegularOutputChannelListener for the list of
- // channels.
- if(options::err() == getManagedOstream()){
- Options::current().base.err = &null_os;
- }
-}
-
-std::string ManagedRegularOutputChannel::defaultSource() const {
- return options::regularChannelName();
-}
-
-void ManagedRegularOutputChannel::initialize(std::ostream* outStream) {
- OptionsErrOstreamUpdate optionsErrOstreamUpdate;
- optionsErrOstreamUpdate.apply(outStream);
-}
-
-void ManagedRegularOutputChannel::addSpecialCases(OstreamOpener* opener)
- const {
- opener->addSpecialCase("stdout", &std::cout);
- opener->addSpecialCase("stderr", &std::cerr);
-}
-
-ManagedDiagnosticOutputChannel::~ManagedDiagnosticOutputChannel() {
- // Set all ostreams that may still be using the old value of this channel
- // to null_os. Consult DiagnosticOutputChannelListener for the list of
- // channels.
- if(options::err() == getManagedOstream()){
- Options::current().base.err = &null_os;
- }
-
- if(Debug.getStreamPointer() == getManagedOstream()) {
- Debug.setStream(&null_os);
- }
- if(Warning.getStreamPointer() == getManagedOstream()){
- Warning.setStream(&null_os);
- }
- if (CVC5Message.getStreamPointer() == getManagedOstream())
- {
- CVC5Message.setStream(&null_os);
- }
- if(Notice.getStreamPointer() == getManagedOstream()){
- Notice.setStream(&null_os);
- }
- if(Chat.getStreamPointer() == getManagedOstream()){
- Chat.setStream(&null_os);
- }
- if(Trace.getStreamPointer() == getManagedOstream()){
- Trace.setStream(&null_os);
- }
-}
-
-
-std::string ManagedDiagnosticOutputChannel::defaultSource() const {
- return options::diagnosticChannelName();
-}
-void ManagedDiagnosticOutputChannel::initialize(std::ostream* outStream) {
- DebugOstreamUpdate debugOstreamUpdate;
- debugOstreamUpdate.apply(outStream);
- WarningOstreamUpdate warningOstreamUpdate;
- warningOstreamUpdate.apply(outStream);
- MessageOstreamUpdate messageOstreamUpdate;
- messageOstreamUpdate.apply(outStream);
- NoticeOstreamUpdate noticeOstreamUpdate;
- noticeOstreamUpdate.apply(outStream);
- ChatOstreamUpdate chatOstreamUpdate;
- chatOstreamUpdate.apply(outStream);
- TraceOstreamUpdate traceOstreamUpdate;
- traceOstreamUpdate.apply(outStream);
- OptionsErrOstreamUpdate optionsErrOstreamUpdate;
- optionsErrOstreamUpdate.apply(outStream);
-}
-
-void ManagedDiagnosticOutputChannel::addSpecialCases(OstreamOpener* opener)
- const {
- opener->addSpecialCase("stdout", &std::cout);
- opener->addSpecialCase("stderr", &std::cerr);
-}
-
-} // namespace cvc5
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback