log_stream.hpp
Go to the documentation of this file.
00001 
00008 /*****************************************************************************
00009 ** Ifdefs
00010 *****************************************************************************/
00011 
00012 #ifndef ECL_STREAMS_LOG_STREAM_HPP_
00013 #define ECL_STREAMS_LOG_STREAM_HPP_
00014 
00015 /*****************************************************************************
00016 ** Includes
00017 *****************************************************************************/
00018 
00019 #include <map>
00020 #include <string>
00021 #include <ecl/config/macros.hpp>
00022 #include <ecl/devices/shared_file.hpp>
00023 #include <ecl/exceptions/standard_exception.hpp>
00024 #include <ecl/time/timestamp.hpp>
00025 #include "text_stream.hpp"
00026 
00027 /*****************************************************************************
00028 ** Macros
00029 *****************************************************************************/
00030 
00042 #define LOG(logStream,mode) \
00043   if ( !logStream.isModeEnabled(mode) ) {} \
00044   else logStream.log(mode)   // << rest of stream input will fill out here
00045 
00055 #define FLUSH(logStream) \
00056   if ( !logStream.isEnabled() ) {} \
00057   else { logStream.flush(); }
00058 
00059 /*****************************************************************************
00060 ** Namespaces
00061 *****************************************************************************/
00062 
00063 namespace ecl {
00064 
00065 /*****************************************************************************
00066 ** Interface [LogStream]
00067 *****************************************************************************/
00109 class ECL_PUBLIC LogStream : public TextStream<SharedFile> {
00110 public:
00117         LogStream() {};
00129         LogStream(const std::string &file_name, const WriteMode &mode = New) ecl_throw_decl(StandardException) :
00130                 write_header(true),
00131                 write_stamp(true)
00132         {
00133                 ecl_try {
00134                         if ( !this->device().open(file_name, mode) ) {
00135                                 error = this->device().error();
00136                         }
00137                 } ecl_catch(StandardException &e) {
00138                         ecl_throw(StandardException(LOC,e));
00139                 }
00140         }
00141 
00142         virtual ~LogStream() {};
00143 
00150     void enableHeader();
00156     void disableHeader();
00163     void enableTimeStamp();
00170     void disableTimeStamp();
00171 
00179     void enableMode(int mode, const std::string header = "");
00186     void disableMode(int mode);
00193     bool isEnabled();
00200     bool isModeEnabled(int mode);
00213     LogStream& log(int mode);
00214 
00215     using TextStream<SharedFile>::operator<<;
00216 
00217 private:
00218     bool write_header;
00219     bool write_stamp;
00220     std::map<int,std::string> modes;
00221     TimeStamp timestamp;
00222 
00223 };
00224 
00225 } // namespace ecl
00226 
00227 #endif /* ECL_STREAMS_LOG_STREAM_HPP_ */


ecl_streams
Author(s): Daniel Stonier (d.stonier@gmail.com)
autogenerated on Thu Jan 2 2014 11:12:54