Gui: implement temporary blocker for console observer
This commit is contained in:
@@ -70,6 +70,44 @@ private:
|
||||
void Log (const char *sErr);
|
||||
};
|
||||
|
||||
/** The ILoggerBlocker class
|
||||
* This class allows to temporary block then automatically restore arbitrary message types
|
||||
* on a particular console observer.
|
||||
*/
|
||||
class BaseExport ILoggerBlocker
|
||||
{
|
||||
public:
|
||||
// Constructor that will block message types passed as parameter. By default, all types are blocked.
|
||||
inline explicit ILoggerBlocker(const char* co, ConsoleMsgFlags msgTypes =
|
||||
ConsoleSingleton::MsgType_Txt | ConsoleSingleton::MsgType_Log | ConsoleSingleton::MsgType_Wrn | ConsoleSingleton::MsgType_Err);
|
||||
// Disable copy & move constructors
|
||||
ILoggerBlocker(ILoggerBlocker const&) = delete;
|
||||
ILoggerBlocker(ILoggerBlocker const &&) = delete;
|
||||
// Disable assignment & move-assignment operator
|
||||
ILoggerBlocker& operator=(ILoggerBlocker const&) = delete;
|
||||
ILoggerBlocker& operator=(ILoggerBlocker const&&) = delete;
|
||||
// Destructor that will restore message type settings.
|
||||
inline ~ILoggerBlocker();
|
||||
private:
|
||||
ConsoleMsgFlags msgTypesBlocked = 0; // Stores message types blocked by the blocker
|
||||
const char* conObs; // Stores console observer name that blocker acts on
|
||||
};
|
||||
|
||||
ILoggerBlocker::ILoggerBlocker(const char* co, ConsoleMsgFlags msgTypes):
|
||||
conObs(co)
|
||||
{
|
||||
msgTypesBlocked = Console().SetEnabledMsgType(conObs, msgTypes, false);
|
||||
}
|
||||
|
||||
ILoggerBlocker::~ILoggerBlocker()
|
||||
{
|
||||
auto debug = Console().SetEnabledMsgType(conObs, msgTypesBlocked, true);
|
||||
#ifdef FC_DEBUG
|
||||
if (debug != msgTypesBlocked)
|
||||
Console().Warning("Enabled message types have been changed while ILoggerBlocker was set\n");
|
||||
#endif
|
||||
}
|
||||
|
||||
class BaseExport RedirectStdOutput : public std::streambuf
|
||||
{
|
||||
public:
|
||||
|
||||
Reference in New Issue
Block a user