FougTools  0.7.0dev-046fb6a
Handy tools for C++, Qt and OpenCascade
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
log.h
Go to the documentation of this file.
1 /****************************************************************************
2 ** FougTools
3 ** Copyright Fougue (30 Mar. 2015)
4 ** contact@fougue.pro
5 **
6 ** This software is a computer program whose purpose is to provide utility
7 ** tools for the C++ language and the Qt toolkit.
8 **
9 ** This software is governed by the CeCILL-C license under French law and
10 ** abiding by the rules of distribution of free software. You can use,
11 ** modify and/ or redistribute the software under the terms of the CeCILL-C
12 ** license as circulated by CEA, CNRS and INRIA at the following URL
13 ** "http://www.cecill.info".
14 ****************************************************************************/
15 
16 #pragma once
17 
18 #include "core.h"
19 #include <QtCore/QObject>
20 #include <QtCore/QString>
21 #include <QtCore/QTextStream>
22 
23 namespace qtcore {
24 
25 // --
26 // -- class Log
27 // --
29 {
30 public:
32  {
37  FatalMessage
38  };
39 
40  Log();
41  Log(MessageType msgType);
42  Log(const Log& other);
43  ~Log();
44 
45  Log& space();
46  Log& operator<<(bool);
47  Log& operator<<(char);
48  Log& operator<<(short);
49  Log& operator<<(unsigned short);
50  Log& operator<<(int);
51  Log& operator<<(unsigned int);
52  Log& operator<<(long);
53  Log& operator<<(unsigned long);
54  Log& operator<<(qlonglong);
55  Log& operator<<(qulonglong);
56  Log& operator<<(float);
57  Log& operator<<(double);
58  Log& operator<<(const char*);
59  Log& operator<<(const QString&);
60 
61  template <typename T>
62  Log& operator<<(const T* ptr);
63 
64  static void registerMetaTypes();
65 
66 private:
67  Log& operator=(const Log& other); // disabled
68 
69  struct Stream;
70  Stream* m_stream;
71 };
72 
78 
79 // --
80 // -- class AbstractLogHandler
81 // --
83 {
84 public:
86  virtual ~AbstractLogHandler();
87  virtual void handle(Log::MessageType msgType, const QString& msg) = 0;
88  void setAutoDetach(bool b);
89 private:
90  bool m_autoDetach;
91 };
94 
95 // --
96 // -- class LogDispatcher
97 // --
99  public QObject,
100  public AbstractLogHandler
101 {
102  Q_OBJECT
103 public:
104  LogDispatcher(QObject* parent = NULL);
105  void handle(Log::MessageType msgType, const QString& msg);
106 signals:
107  void log(qtcore::Log::MessageType msgType, const QString& msg);
108 };
109 
110 // --
111 // -- Implementation
112 // --
113 
114 template <typename T>
115 Log& Log::operator<<(const T* ptr)
116 {
117  return *this << QString("0x%1").arg(reinterpret_cast<std::size_t>(ptr), 0, 16);
118 }
119 
120 } // namespace qtcore
QTTOOLS_CORE_EXPORT void attachGlobalLogHandler(AbstractLogHandler *handler)
QTTOOLS_CORE_EXPORT Log infoLog()
Definition: log.h:33
MessageType
Types of logging message, with increasing severity.
Definition: log.h:31
Dispatches a logging message as a Qt signal.
Definition: log.h:98
#define QTTOOLS_CORE_EXPORT
Definition: core.h:27
Definition: grid_numbering.cpp:19
QTTOOLS_CORE_EXPORT Log criticalLog()
Log & operator<<(bool)
Write the boolean t to the log stream and return a reference to the stream.
Definition: log.cpp:141
QTTOOLS_CORE_EXPORT Log debugLog()
TEXT_STREAM & operator<<(TEXT_STREAM &os, const FixedArray< T, S > &coords)
Definition: fixed_array.h:201
Provides an easy-to-use output stream for logging.
Definition: log.h:28
Definition: log.h:34
QTTOOLS_CORE_EXPORT Log fatalLog()
Definition: log.h:36
QTTOOLS_CORE_EXPORT void detachGlobalLogHandler(AbstractLogHandler *handler)
QTTOOLS_CORE_EXPORT Log warningLog()
Abstract base class of all logging message handlers.
Definition: log.h:82
Definition: log.h:35