Make statusmanager a template type instead of a macro
MODIFY
src/mainwindow.h
src/mainwindow.h
@@ -10,10 +10,6 @@ QT_FORWARD_DECLARE_CLASS(QStackedWidget)
QT_FORWARD_DECLARE_CLASS(QActionGroup)
namespace Ripes {
-
-StatusManager(General);
-StatusManager(ProcessorInfo);
-
namespace Ui {
class MainWindow;
}

MODIFY
src/processorhandler.h
src/processorhandler.h
namespace Ripes {
-StatusManager(Processor);
-
/**
* @brief The ProcessorHandler class
* Manages construction and destruction of a VSRTL processor design, when selecting between processors.

MODIFY
src/statusmanager.h
src/statusmanager.h
@@ -15,33 +15,49 @@ signals:
void statusChanged(const QString&);
void clear();
};
-} // namespace Ripes
+
+// Helper class to create StatusManagerBase singletons based on a statically defined string.
+#define UniqueType(name) \
+ struct NamedTypeUniquer__##name {};
+
+template <typename T>
+class StatusManagerBase {
+public:
+ static StatusManagerBase& get() {
+ static StatusManagerBase s;
+ return s;
+ }
+
+ static void setStatus(const QString& s) { get().emitter.setStatus(s); }
+ static void setStatusTimed(const QString& s, int ms = 2000) {
+ setStatus(s);
+ get().m_timer.start(ms);
+ }
+ static void clearStatus() { get().emitter.clearStatus(); }
+ StatusEmitter emitter;
+
+private:
+ StatusManagerBase() {
+ m_timer.setSingleShot(true);
+ m_timer.connect(&m_timer, &QTimer::timeout, [this] { this->clearStatus(); });
+ }
+ QTimer m_timer;
+};
/**
* @brief StatusManager
* Defines a singleton class which may be used to send or clear a message to a specific label within the main window
- * status bar.
+ * status bar. Each status manager is a singleton based on the status manager name.
*/
#define StatusManager(name) \
- class name##StatusManager { \
- public: \
- static name##StatusManager& get() { \
- static name##StatusManager s; \
- return s; \
- } \
- \
- static void setStatus(const QString& s) { get().emitter.setStatus(s); } \
- static void setStatusTimed(const QString& s, int ms) { \
- setStatus(s); \
- get().m_timer.start(ms); \
- } \
- static void clearStatus() { get().emitter.clearStatus(); } \
- StatusEmitter emitter; \
- \
- private: \
- name##StatusManager() { \
- m_timer.setSingleShot(true); \
- m_timer.connect(&m_timer, &QTimer::timeout, [this] { this->clearStatus(); }); \
- } \
- QTimer m_timer; \
- };
+ using name##TypeUniquer = UniqueType(name); \
+ using name##StatusManager = StatusManagerBase<name##TypeUniquer>;
+
+// Declarations for the status managers used in Ripes.
+StatusManager(General);
+StatusManager(ProcessorInfo);
+StatusManager(Processor);
+StatusManager(SystemIO);
+StatusManager(Syscall);
+
+} // namespace Ripes

MODIFY
src/syscall/ripes_syscall.h
src/syscall/ripes_syscall.h
@@ -62,13 +62,6 @@ protected:
const std::map<ArgIdx, QString> m_returnDescriptions;
};
-/**
- * @brief SyscallStatusManager
- * Any syscall status messages may be posted to the following class. This class is connected to a status bar widget
- * in the mainwindow and subsequently displays all messages to the user.
- */
-StatusManager(Syscall);
-
/**
* @brief The SyscallManager class
*

MODIFY
src/syscall/systemio.h
src/syscall/systemio.h
namespace Ripes {
-StatusManager(SystemIO);
-
/*
Copyright (c) 2003-2013, Pete Sanderson and Kenneth Vollmar

Make statusmanager a template type instead of a macro