#ifndef __JEEP__JCOMMUNICATOR__ #define __JEEP__JCOMMUNICATOR__ #include #include "JLang/JNullStream.hh" /** * \file * Switching on/off of standard and error output streams. * \author mdejong */ namespace JEEP {} namespace JPP { using namespace JEEP; } namespace JEEP { /** * Auxiliary class to control standard input and output. */ class JCommunicator { public: /** * Default constructor. */ JCommunicator() : verbose_(true) {} /** * Constructor. * * \param verbose disable I/O if false; else enable */ JCommunicator(const bool verbose) : verbose_(verbose) {} /** * Get verbose mode. * * \return if true I/O enabled; else disabled */ bool getVerbose() const { return verbose_; } /** * Set verbose mode. * * \param verbose disable I/O if false; else enable */ void setVerbose(const bool verbose = true) { verbose_ = verbose; } /** * Get current input stream. * This method returns the given input stream if the verbose option is set, * else a streamer that does not read any input. * * \param in input stream * \return input stream */ std::istream& getInputStream(std::istream& in = std::cin) const { return (verbose_ ? in : JLANG::null); } /** * Get current output stream. * This method returns the given output stream if the verbose option is set, * else a streamer that does not write any output. * * \param out output stream * \return output stream */ std::ostream& getOutputStream(std::ostream& out = std::cout) const { return (verbose_ ? out : JLANG::null); } /** * Get current error stream. * This method returns the given error stream if the verbose option is set, * else a streamer that does not write any output. * * \param out error stream * \return error stream */ std::ostream& getErrorStream(std::ostream& out = std::cerr) const { //return (verbose_ ? out : JLANG::null); return out; } protected: bool verbose_; }; } #endif