Jpp  15.0.2
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JCommunicator.hh
Go to the documentation of this file.
1 #ifndef __JEEP__JCOMMUNICATOR__
2 #define __JEEP__JCOMMUNICATOR__
3 
4 #include <iostream>
5 
6 #include "JLang/JNullStream.hh"
7 
8 
9 /**
10  * \file
11  * Switching on/off of standard and error output streams.
12  * \author mdejong
13  */
14 namespace JEEP {}
15 namespace JPP { using namespace JEEP; }
16 
17 namespace JEEP {
18 
19 
20  /**
21  * Auxiliary class to control standard input and output.
22  */
23  class JCommunicator {
24  public:
25  /**
26  * Default constructor.
27  */
29  verbose_(true)
30  {}
31 
32 
33  /**
34  * Constructor.
35  *
36  * \param verbose disable I/O if false; else enable
37  */
38  JCommunicator(const bool verbose) :
39  verbose_(verbose)
40  {}
41 
42 
43  /**
44  * Get verbose mode.
45  *
46  * \return if true I/O enabled; else disabled
47  */
48  bool getVerbose() const
49  {
50  return verbose_;
51  }
52 
53 
54  /**
55  * Set verbose mode.
56  *
57  * \param verbose disable I/O if false; else enable
58  */
59  void setVerbose(const bool verbose = true)
60  {
61  verbose_ = verbose;
62  }
63 
64 
65  /**
66  * Get current input stream.
67  * This method returns the given input stream if the verbose option is set,
68  * else a streamer that does not read any input.
69  *
70  * \param in input stream
71  * \return input stream
72  */
73  std::istream& getInputStream(std::istream& in = std::cin) const
74  {
75  return (verbose_ ? in : JLANG::null);
76  }
77 
78 
79  /**
80  * Get current output stream.
81  * This method returns the given output stream if the verbose option is set,
82  * else a streamer that does not write any output.
83  *
84  * \param out output stream
85  * \return output stream
86  */
87  std::ostream& getOutputStream(std::ostream& out = std::cout) const
88  {
89  return (verbose_ ? out : JLANG::null);
90  }
91 
92 
93  /**
94  * Get current error stream.
95  * This method returns the given error stream if the verbose option is set,
96  * else a streamer that does not write any output.
97  *
98  * \param out error stream
99  * \return error stream
100  */
101  std::ostream& getErrorStream(std::ostream& out = std::cerr) const
102  {
103  //return (verbose_ ? out : JLANG::null);
104  return out;
105  }
106 
107 
108  protected:
109  bool verbose_;
110  };
111 
112 }
113 
114 #endif
std::ostream & getOutputStream(std::ostream &out=std::cout) const
Get current output stream.
void setVerbose(const bool verbose=true)
Set verbose mode.
int verbose
Definition: elog.cc:70
JCommunicator()
Default constructor.
Auxiliary class to control standard input and output.
std::ostream & getErrorStream(std::ostream &out=std::cerr) const
Get current error stream.
bool getVerbose() const
Get verbose mode.
std::istream & getInputStream(std::istream &in=std::cin) const
Get current input stream.
static JNullStream null
Null I/O stream.
Definition: JNullStream.hh:51
then fatal Wrong number of arguments fi set_variable DETECTOR $argv[1] set_variable INPUT_FILE $argv[2] eval JPrintDetector a $DETECTOR O IDENTIFIER eval JPrintDetector a $DETECTOR O SUMMARY source JAcoustics sh $DETECTOR_ID CHECK_EXIT_CODE typeset A TRIPODS get_tripods $WORKDIR tripod txt TRIPODS for EMITTER in
Definition: JCanberra.sh:41
JCommunicator(const bool verbose)
Constructor.