| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #pragma once |
|
|
| #ifdef WITH_THREADS |
| #include <boost/thread/mutex.hpp> |
| #endif |
|
|
| #ifdef BOOST_HAS_PTHREADS |
| #include <pthread.h> |
| #endif |
|
|
| #include <iostream> |
| #include <unordered_map> |
| #include <ostream> |
| #include <fstream> |
| #include <string> |
| #include "util/exception.hh" |
|
|
| namespace Moses2 |
| { |
| |
| |
| |
| class OutputCollector |
| { |
| public: |
| OutputCollector(std::ostream* outStream = &std::cout, |
| std::ostream* debugStream = &std::cerr); |
|
|
| OutputCollector(std::string xout, std::string xerr = ""); |
|
|
| ~OutputCollector(); |
|
|
| void HoldOutputStream() { |
| m_isHoldingOutputStream = true; |
| } |
|
|
| void HoldDebugStream() { |
| m_isHoldingDebugStream = true; |
| } |
|
|
| bool OutputIsCout() const { |
| return (m_outStream == &std::cout); |
| } |
|
|
| |
| |
| |
| void Write(int sourceId, const std::string& output, const std::string& debug = |
| ""); |
|
|
| private: |
| std::unordered_map<int, std::string> m_outputs; |
| std::unordered_map<int, std::string> m_debugs; |
| int m_nextOutput; |
| std::ostream* m_outStream; |
| std::ostream* m_debugStream; |
| bool m_isHoldingOutputStream; |
| bool m_isHoldingDebugStream; |
| #ifdef WITH_THREADS |
| boost::mutex m_mutex; |
| #endif |
|
|
| public: |
| void SetOutputStream(std::ostream* outStream) { |
| m_outStream = outStream; |
| } |
|
|
| }; |
|
|
| } |
|
|
|
|