Leviathan  0.8.0.0
Leviathan game engine
ComplainOnce.cpp
Go to the documentation of this file.
1 // ------------------------------------ //
2 #include "ComplainOnce.h"
3 
4 #include "Logger.h"
5 using namespace Leviathan;
6 // ------------------------------------ //
8  const std::string& warning, const std::string& message)
9 {
10  Lock lock(ErrorsMutex);
11 
12  // Print only once to log //
13  if(FiredErrors.find(warning) != FiredErrors.end())
14  return false;
15 
16  // Value wasn't there, print //
17  Logger::Get()->Warning(message);
18 
19  FiredErrors.insert(warning);
20  return true;
21 }
22 
24  const std::string& error, const std::string& message)
25 {
26  Lock lock(ErrorsMutex);
27 
28  // Print only once to log //
29  if(FiredErrors.find(error) != FiredErrors.end())
30  return false;
31 
32  // Value wasn't there, print //
33  Logger::Get()->Error(message);
34 
35  FiredErrors.insert(error);
36  return true;
37 }
38 
39 std::unordered_set<std::string> ComplainOnce::FiredErrors;
40 Mutex ComplainOnce::ErrorsMutex;
41 // ------------------------------------ //
DLLEXPORT void Warning(const std::string &data) override
Definition: Logger.cpp:190
std::mutex Mutex
Definition: ThreadSafe.h:14
static DLLEXPORT bool PrintWarningOnce(const std::string &warning, const std::string &message)
Definition: ComplainOnce.cpp:7
static DLLEXPORT Logger * Get()
Definition: Logger.cpp:106
static DLLEXPORT bool PrintErrorOnce(const std::string &error, const std::string &message)
#define DLLEXPORT
Definition: Include.h:115
The access mask controls which registered functions and classes a script sees.
Definition: GameModule.h:12
DLLEXPORT void Error(const std::string &data) override
Definition: Logger.cpp:177
std::unique_lock< std::mutex > Lock
Definition: ThreadSafe.h:16