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 #include "macros.hpp"
00027 
00028 /*****************************************************************************
00029 ** Macros
00030 *****************************************************************************/
00031 
00043 #define LOG(logStream,mode) \
00044   if ( !logStream.isModeEnabled(mode) ) {} \
00045   else logStream.log(mode)   // << rest of stream input will fill out here
00046 
00056 #define FLUSH(logStream) \
00057   if ( !logStream.isEnabled() ) {} \
00058   else { logStream.flush(); }
00059 
00060 /*****************************************************************************
00061 ** Namespaces
00062 *****************************************************************************/
00063 
00064 namespace ecl {
00065 
00066 /*****************************************************************************
00067 ** Interface [LogStream]
00068 *****************************************************************************/
00110 class ecl_streams_PUBLIC LogStream : public TextStream<SharedFile> {
00111 public:
00118         LogStream() {};
00130         LogStream(const std::string &file_name, const WriteMode &mode = New) ecl_throw_decl(StandardException) :
00131                 write_header(true),
00132                 write_stamp(true)
00133         {
00134                 ecl_try {
00135                         if ( !this->device().open(file_name, mode) ) {
00136                                 error = this->device().error();
00137                         }
00138                 } ecl_catch(StandardException &e) {
00139                         ecl_throw(StandardException(LOC,e));
00140                 }
00141         }
00142 
00143         virtual ~LogStream() {};
00144 
00151     void enableHeader();
00157     void disableHeader();
00164     void enableTimeStamp();
00171     void disableTimeStamp();
00172 
00180     void enableMode(int mode, const std::string header = "");
00187     void disableMode(int mode);
00194     bool isEnabled();
00201     bool isModeEnabled(int mode);
00214     LogStream& log(int mode);
00215 
00216     using TextStream<SharedFile>::operator<<;
00217 
00218 private:
00219     bool write_header;
00220     bool write_stamp;
00221     std::map<int,std::string> modes;
00222     TimeStamp timestamp;
00223 
00224 };
00225 
00226 } // namespace ecl
00227 
00228 #endif /* ECL_STREAMS_LOG_STREAM_HPP_ */


ecl_streams
Author(s): Daniel Stonier
autogenerated on Sun Oct 5 2014 23:36:00