ThreadStream.h
Go to the documentation of this file.
00001 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
00002 
00003 // -- BEGIN LICENSE BLOCK ----------------------------------------------
00004 // This file is part of FZIs ic_workspace.
00005 //
00006 // This program is free software licensed under the LGPL
00007 // (GNU LESSER GENERAL PUBLIC LICENSE Version 3).
00008 // You can find a copy of this license in LICENSE folder in the top
00009 // directory of the source code.
00010 //
00011 // © Copyright 2014 FZI Forschungszentrum Informatik, Karlsruhe, Germany
00012 //
00013 // -- END LICENSE BLOCK ------------------------------------------------
00014 
00015 //----------------------------------------------------------------------
00027 //----------------------------------------------------------------------
00028 #ifndef ICL_CORE_LOGGING_THREAD_STREAM_H_INCLUDED
00029 #define ICL_CORE_LOGGING_THREAD_STREAM_H_INCLUDED
00030 
00031 #include <list>
00032 #include <set>
00033 
00034 #include "icl_core/BaseTypes.h"
00035 #include "icl_core/os_thread.h"
00036 #include "icl_core_logging/Constants.h"
00037 #include "icl_core_logging/ImportExport.h"
00038 #include "icl_core_logging/LogLevel.h"
00039 
00040 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00041 # include "icl_core/Deprecate.h"
00042 #endif
00043 
00044 #if defined ICL_CORE_QT_SUPPORT
00045 class QString;
00046 #endif
00047 
00048 #ifdef _IC_BUILDER_EIGEN_
00049 #include <Eigen/Core>
00050 #endif
00051 
00052 namespace icl_core {
00053 namespace logging {
00054 
00055 class LogStream;
00056 
00058 class ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream
00059 {
00060   friend class LogStream;
00061 public:
00064   void changeLevel(icl_core::logging::LogLevel level) { m_level = level; }
00065 
00068   icl_core::logging::LogLevel getLogLevel() const { return m_level; }
00069 
00074   void setClassname(const char *classname);
00075 
00080   void setObjectname(const char *objectname);
00081 
00086   void setFilename(const char *filename);
00087 
00092   void setFunction(const char *function);
00093 
00098   void setLine(size_t line);
00099 
00102   void setLineLogLevel(icl_core::logging::LogLevel line_log_level);
00103 
00113   void write(const char *buffer, size_t number_of_bytes, size_t protected_buffer_size=1);
00114 
00120   void printf(const char *fmt, ...);
00121 
00125   void flush();
00126 
00129   typedef ThreadStream& (*ThreadStreamFunc)(ThreadStream&);
00130 
00134   ThreadStream& operator << (ThreadStreamFunc func)
00135   {
00136     return (*func)(*this);
00137   }
00138 
00140 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00141 
00145   ICL_CORE_VC_DEPRECATE_STYLE void ChangeLevel(icl_core::logging::LogLevel level)
00146     ICL_CORE_GCC_DEPRECATE_STYLE;
00147 
00151   ICL_CORE_VC_DEPRECATE_STYLE_USE(ThreadStream::getLogLevel)
00152     icl_core::logging::LogLevel LogLevel() const
00153     ICL_CORE_GCC_DEPRECATE_STYLE_USE(ThreadStream::getLogLevel);
00154 
00158   ICL_CORE_VC_DEPRECATE_STYLE void SetClassname(const char *classname)
00159     ICL_CORE_GCC_DEPRECATE_STYLE;
00160 
00164   ICL_CORE_VC_DEPRECATE_STYLE void SetObjectname(const char *objectname)
00165     ICL_CORE_GCC_DEPRECATE_STYLE;
00166 
00170   ICL_CORE_VC_DEPRECATE_STYLE void SetFilename(const char *filename)
00171     ICL_CORE_GCC_DEPRECATE_STYLE;
00172 
00176   ICL_CORE_VC_DEPRECATE_STYLE void SetFunction(const char *function)
00177     ICL_CORE_GCC_DEPRECATE_STYLE;
00178 
00182   ICL_CORE_VC_DEPRECATE_STYLE void SetLine(size_t line)
00183     ICL_CORE_GCC_DEPRECATE_STYLE;
00184 
00188   ICL_CORE_VC_DEPRECATE_STYLE void SetLineLogLevel(icl_core::logging::LogLevel line_log_level)
00189     ICL_CORE_GCC_DEPRECATE_STYLE;
00190 
00195   ICL_CORE_VC_DEPRECATE_STYLE void Write(const char *buffer, size_t number_of_bytes,
00196                                          size_t protected_buffer_size=1)
00197     ICL_CORE_GCC_DEPRECATE_STYLE;
00198 
00203   ICL_CORE_VC_DEPRECATE_STYLE void Printf(const char *fmt, ...) ICL_CORE_GCC_DEPRECATE_STYLE;
00204 
00209   ICL_CORE_VC_DEPRECATE_STYLE void Flush() ICL_CORE_GCC_DEPRECATE_STYLE;
00210 
00211 #endif
00212 
00213 
00214 private:
00218   ThreadStream(LogStream *parent);
00219 
00220   ~ThreadStream()
00221   { }
00222 
00223   LogStream *m_parent;
00224   icl_core::logging::LogLevel m_level;
00225 
00226   icl_core::logging::LogLevel m_line_log_level;
00227   char m_filename[cDEFAULT_LOG_SIZE + 1];
00228   size_t m_line;
00229   char m_classname[cDEFAULT_LOG_SIZE + 1];
00230   char m_objectname[cDEFAULT_LOG_SIZE + 1];
00231   char m_function[cDEFAULT_LOG_SIZE + 1];
00232   char m_data[cDEFAULT_LOG_SIZE + 1];
00233   size_t m_write_index;
00234   //char *m_write_pointer;
00235 };
00236 
00241 inline ThreadStream& flush(ThreadStream& stream)
00242 {
00243   stream.flush();
00244   return stream;
00245 }
00246 
00249 inline ThreadStream& endl(ThreadStream& stream)
00250 {
00251   stream.write("\n", 1, 0);
00252   return stream << flush;
00253 }
00254 
00255 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, uint8_t value);
00256 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, uint16_t value);
00257 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, uint32_t value);
00258 #if __WORDSIZE != 64
00259 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, unsigned long value);
00260 #endif
00261 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, uint64_t value);
00262 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, int8_t value);
00263 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, int16_t value);
00264 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, int32_t value);
00265 #if __WORDSIZE != 64
00266 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, long value);
00267 #endif
00268 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, int64_t value);
00269 #ifdef _SYSTEM_DARWIN_
00270 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, size_t value);
00271 #endif
00272 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, const char *text);
00273 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, const std::string& text);
00274 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, double value);
00275 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, bool value);
00276 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, void * value);
00277 
00278 #ifndef _SYSTEM_WIN32_
00279 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, const ThreadId& value);
00280 #endif
00281 
00282 #if defined ICL_CORE_QT_SUPPORT
00283 ICL_CORE_LOGGING_IMPORT_EXPORT ThreadStream& operator << (ThreadStream& stream, const QString& value);
00284 #endif
00285 
00286 #ifdef _IC_BUILDER_EIGEN_
00287 template <typename TScalar, int _Rows, int _Cols, int _Options, int _MaxRows, int _MaxCols>
00288 icl_core::logging::ThreadStream&
00289 operator << (icl_core::logging::ThreadStream& stream,
00290              const Eigen::Matrix<TScalar, _Rows, _Cols, _Options, _MaxRows, _MaxCols>& matrix)
00291 {
00292   stream << "[";
00293   for (int col = 0; col < matrix.cols(); ++col)
00294   {
00295     for (int row = 0; row < matrix.rows(); ++row)
00296     {
00297       stream << " " << matrix(row, col);
00298     }
00299     if (col < matrix.cols() - 1)
00300     {
00301       stream << " ;";
00302     }
00303   }
00304   stream << " ]";
00305   return stream;
00306 }
00307 #endif
00308 
00310 #ifdef _IC_BUILDER_DEPRECATED_STYLE_
00311 
00316 inline ThreadStream& Flush(ThreadStream& stream) ICL_CORE_GCC_DEPRECATE_STYLE;
00317 ICL_CORE_VC_DEPRECATE_STYLE inline ThreadStream& Flush(ThreadStream& stream)
00318 {
00319   stream.flush();
00320   return stream;
00321 }
00322 
00326 inline ThreadStream& Endl(ThreadStream& stream) ICL_CORE_GCC_DEPRECATE_STYLE;
00327 ICL_CORE_VC_DEPRECATE_STYLE inline ThreadStream& Endl(ThreadStream& stream)
00328 {
00329   stream.write("\n", 1, 0);
00330   return stream << flush;
00331 }
00332 #endif
00333 
00334 
00335 }
00336 }
00337 
00338 #endif


schunk_svh_driver
Author(s): Georg Heppner
autogenerated on Fri Aug 28 2015 12:59:19