Jpp  18.5.0
the software that should make you happy
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
JMessageStream.hh
Go to the documentation of this file.
1 #ifndef __JLOGGER__JMESSAGESTREAM__
2 #define __JLOGGER__JMESSAGESTREAM__
3 
4 #include <ostream>
5 #include <sstream>
6 
8 
9 
10 /**
11  * \file
12  * Message reporting compatible with STL output stream operations.
13  * \author mdejong
14  */
15 namespace JLOGGER {}
16 namespace JPP { using namespace JLOGGER; }
17 
18 namespace JLOGGER {
19 
20  /**
21  * Message streamer.
22  *
23  * This class can be used in the same way as the STL ostream operator.\n
24  * The actual message is reported on detruction of the object, e.g:
25  *
26  * JStreamLogger logger(std::cout);
27  *
28  * JDebugStream (logger) << "This is a debug message " << hex << 15;
29  *
30  * will produce on the terminal:
31  *
32  * <tt>"... This is a debug message f"</tt>
33  *
34  * where <tt>...</tt> stands for the message prefix (see class JMessageLogger).
35  * The list of available message streamer classes includes:
36  *
37  * - JDebugStream
38  * - JWarningStream
39  * - JErrorStream
40  * - JNoticeStream
41  * - JStatusStream
42  */
44  public std::ostringstream
45  {
46  public:
47  /**
48  * Appends value to internal buffer.
49  *
50  * \param value value
51  * \return this JMessageStream
52  */
53  template<class T>
54  JMessageStream& operator<<(const T& value)
55  {
56  static_cast<std::ostringstream&>(*this) << value;
57 
58  return *this;
59  }
60 
61 
62  /**
63  * Type definition of I/O operator.
64  */
65  typedef std::ostream& (*io_manip) (std::ostream&);
66 
67 
68  /**
69  * Append I/O manipulator.
70  *
71  * \param manip I/O manipulator
72  * \return this JMessageStream
73  */
75  {
76  static_cast<std::ostringstream&>(*this) << manip;
77 
78  return *this;
79  }
80 
81  protected:
82  /**
83  * Constructor.
84  *
85  * \param __logger message logger
86  * \param __typeout logger method
87  */
89  void (JMessageLogger::*__typeout)(const std::string&)) :
90  std::ostringstream(),
91  logger (__logger),
92  typeout(__typeout)
93  {}
94 
95 
96  /**
97  * Report message.
98  */
100  {
101  (logger.*typeout)(this->str());
102  }
103 
104 
107  };
108 
109 
110  /**
111  * Level specific message streamers.
112  */
118 }
119 
120 #endif
~JMessageStream()
Report message.
void status(const JMessage_t &message)
void notice(const JMessage_t &message)
JStatusStream(JMessageLogger &logger)
Message streamer.
JWarningStream(JMessageLogger &logger)
JMessageStream & operator<<(io_manip manip)
Append I/O manipulator.
do set_variable OUTPUT_DIRECTORY $WORKDIR T
void(JMessageLogger::* typeout)(const std::string &)
then awk string
JMessageStream & operator<<(const T &value)
Appends value to internal buffer.
Level specific message streamers.
void warning(const JMessage_t &message)
General purpose message reporting.
JErrorStream(JMessageLogger &logger)
JDebugStream(JMessageLogger &logger)
std::ostream &(* io_manip)(std::ostream &)
Type definition of I/O operator.
JNoticeStream(JMessageLogger &logger)
JMessageLogger & logger
void error(const JMessage_t &message)
JMessageStream(JMessageLogger &__logger, void(JMessageLogger::*__typeout)(const std::string &))
Constructor.
void debug(const JMessage_t &message)