From d2a6074b45c7904076422e74c3eb047b87607a90 Mon Sep 17 00:00:00 2001 From: Hieu Hoang Date: Wed, 21 Feb 2024 14:10:32 -0800 Subject: [PATCH] move method body to cpp. Use unordered map --- moses2/legacy/OutputCollector.cpp | 42 +++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 moses2/legacy/OutputCollector.cpp diff --git a/moses2/legacy/OutputCollector.cpp b/moses2/legacy/OutputCollector.cpp new file mode 100755 index 000000000..2d54ec78d --- /dev/null +++ b/moses2/legacy/OutputCollector.cpp @@ -0,0 +1,42 @@ +#include "OutputCollector.h" + +namespace Moses2 +{ + OutputCollector::OutputCollector(std::string xout, std::string xerr = "") : + m_nextOutput(0) { + // TO DO open magic streams instead of regular ofstreams! [UG] + + if (xout == "/dev/stderr") { + m_outStream = &std::cerr; + m_isHoldingOutputStream = false; + } + else if (xout.size() && xout != "/dev/stdout" && xout != "-") { + m_outStream = new std::ofstream(xout.c_str()); + UTIL_THROW_IF2(!m_outStream->good(), + "Failed to open output file" << xout); + m_isHoldingOutputStream = true; + } + else { + m_outStream = &std::cout; + m_isHoldingOutputStream = false; + } + + if (xerr == "/dev/stdout") { + m_debugStream = &std::cout; + m_isHoldingDebugStream = false; + } + else if (xerr.size() && xerr != "/dev/stderr") { + m_debugStream = new std::ofstream(xerr.c_str()); + UTIL_THROW_IF2(!m_debugStream->good(), + "Failed to open debug stream" << xerr); + m_isHoldingDebugStream = true; + } + else { + m_debugStream = &std::cerr; + m_isHoldingDebugStream = false; + } +} + + +} +