log_stream.hpp
Go to the documentation of this file.
1 
8 /*****************************************************************************
9 ** Ifdefs
10 *****************************************************************************/
11 
12 #ifndef ECL_STREAMS_LOG_STREAM_HPP_
13 #define ECL_STREAMS_LOG_STREAM_HPP_
14 
15 /*****************************************************************************
16 ** Includes
17 *****************************************************************************/
18 
19 #include <map>
20 #include <string>
21 #include <ecl/config/macros.hpp>
22 #include <ecl/devices/shared_file.hpp>
23 #include <ecl/exceptions/standard_exception.hpp>
24 #include <ecl/time/timestamp.hpp>
25 #include "text_stream.hpp"
26 #include "macros.hpp"
27 
28 /*****************************************************************************
29 ** Macros
30 *****************************************************************************/
31 
43 #define LOG(logStream,mode) \
44  if ( !logStream.isModeEnabled(mode) ) {} \
45  else logStream.log(mode) // << rest of stream input will fill out here
46 
56 #define FLUSH(logStream) \
57  if ( !logStream.isEnabled() ) {} \
58  else { logStream.flush(); }
59 
60 /*****************************************************************************
61 ** Namespaces
62 *****************************************************************************/
63 
64 namespace ecl {
65 
66 /*****************************************************************************
67 ** Interface [LogStream]
68 *****************************************************************************/
110 class ecl_streams_PUBLIC LogStream : public TextStream<SharedFile> {
111 public:
118  LogStream() {};
130  LogStream(const std::string &file_name, const WriteMode &mode = New) ecl_throw_decl(StandardException) :
131  write_header(true),
132  write_stamp(true)
133  {
134  ecl_try {
135  if ( !this->device().open(file_name, mode) ) {
136  error = this->device().error();
137  }
138  } ecl_catch(StandardException &e) {
139  ecl_throw(StandardException(LOC,e));
140  }
141  }
142 
143  virtual ~LogStream() {};
144 
151  void enableHeader();
157  void disableHeader();
164  void enableTimeStamp();
171  void disableTimeStamp();
172 
180  void enableMode(int mode, const std::string header = "");
187  void disableMode(int mode);
194  bool isEnabled();
201  bool isModeEnabled(int mode);
214  LogStream& log(int mode);
215 
216  using TextStream<SharedFile>::operator<<;
217 
218 private:
219  bool write_header;
220  bool write_stamp;
221  std::map<int,std::string> modes;
222  TimeStamp timestamp;
223 
224 };
225 
226 } // namespace ecl
227 
228 #endif /* ECL_STREAMS_LOG_STREAM_HPP_ */
WriteMode
#define ecl_throw(exception)
Standard ecl throw exception throw.
#define ecl_streams_PUBLIC
#define ecl_throw_decl(exception)
Standard ecl throw exception declaration.
#define LOC
Stringify the line of code you are at.
#define ecl_catch(exception)
The catch part of a try-catch macro matching ecl_throw calls.
#define ecl_try
The try part of a try-catch macro matching ecl_throw calls.


xbot_node
Author(s): Roc, wangpeng@droid.ac.cn
autogenerated on Sat Oct 10 2020 03:28:13