all repos — mgba @ 0cd28060e07c587ab10901ce815563a9e998f297

mGBA Game Boy Advance Emulator

src/platform/qt/LogController.h (view raw)

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#ifndef QGBA_LOG_CONTROLLER
 7#define QGBA_LOG_CONTROLLER
 8
 9#include <QObject>
10#include <QStringList>
11
12extern "C" {
13#include "gba/gba.h"
14}
15
16namespace QGBA {
17
18class LogController : public QObject {
19Q_OBJECT
20
21private:
22	class Stream {
23	public:
24		Stream(LogController* controller, int level);
25		~Stream();
26
27		Stream& operator<<(const QString&);
28
29	private:
30		int m_level;
31		LogController* m_log;
32
33		QStringList m_queue;
34	};
35
36public:
37	LogController(int levels, QObject* parent = nullptr);
38
39	int levels() const { return m_logLevel; }
40
41	Stream operator()(int level);
42
43	static LogController* global();
44	static QString toString(int level);
45
46signals:
47	void logPosted(int level, const QString& log);
48	void levelsSet(int levels);
49	void levelsEnabled(int levels);
50	void levelsDisabled(int levels);
51
52public slots:
53	void postLog(int level, const QString& string);
54	void setLevels(int levels);
55	void enableLevels(int levels);
56	void disableLevels(int levels);
57
58private:
59	int m_logLevel;
60
61	static LogController s_global;
62};
63
64#define LOG(L) (*LogController::global())(GBA_LOG_ ## L)
65
66}
67
68#endif