denisq

log.h

Jul 20th, 2014
29
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * log.h
  3.  *
  4.  * Copyright (C) 2011 Christoph Pfister <christophpfister@gmail.com>
  5.  *
  6.  * This program is free software; you can redistribute it and/or modify
  7.  * it under the terms of the GNU General Public License as published by
  8.  * the Free Software Foundation; either version 2 of the License, or
  9.  * (at your option) any later version.
  10.  *
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License along
  17.  * with this program; if not, write to the Free Software Foundation, Inc.,
  18.  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  19.  */
  20.  
  21. #ifndef LOG_H
  22. #define LOG_H
  23.  
  24. #include <QString>
  25.  
  26. class LogPrivate;
  27.  
  28. class Log
  29. {
  30. public:
  31.     Log(const char *message)
  32.     {
  33.         begin(message);
  34.     }
  35.  
  36.     ~Log()
  37.     {
  38.         end();
  39.     }
  40.  
  41.     static QString getLog();
  42.  
  43.     Log &operator<<(qint32 value)
  44.     {
  45.         append(qint64(value));
  46.         return (*this);
  47.     }
  48.  
  49.     Log &operator<<(quint32 value)
  50.     {
  51.         append(quint64(value));
  52.         return (*this);
  53.     }
  54.  
  55.     Log &operator<<(qint64 value)
  56.     {
  57.         append(value);
  58.         return (*this);
  59.     }
  60.  
  61.     Log &operator<<(quint64 value)
  62.     {
  63.         append(value);
  64.         return (*this);
  65.     }
  66.  
  67.     Log &operator<<(const QString &string)
  68.     {
  69.         append(string);
  70.         return (*this);
  71.     }
  72.  
  73. private:
  74.     Q_DISABLE_COPY(Log)
  75.  
  76.     static void begin(const char *message);
  77.     static void append(qint64 value);
  78.     static void append(quint64 value);
  79.     static void append(const QString &string);
  80.     static void end();
  81.  
  82.     static QBasicAtomicPointer<LogPrivate> data;
  83. };
  84.  
  85. #endif /* LOG_H */
RAW Paste Data