TDME2  1.9.200
Console.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <memory>
4 #include <string>
5 #include <string_view>
6 #include <vector>
7 
8 #include <tdme/tdme.h>
13 
14 using std::string;
15 using std::string_view;
16 using std::unique_ptr;
17 using std::vector;
18 
21 
22 
23 /**
24  * Console class
25  * @author Andreas Drewke
26  * @versio $Id$
27  */
29 {
30 public:
31 
32  static constexpr int HISTORY_LINECOUNT { 5000 };
33 
34  struct Logger
35  {
36  virtual ~Logger() {}
37  virtual void println(const string_view& str) = 0;
38  virtual void print(const string_view& str) = 0;
39  virtual void println() = 0;
40  };
41 
42  /**
43  * Set logger
44  * @param logger logger
45  */
46  static void setLogger(Logger* logger);
47 
48  /**
49  * Print given string and trailing newline to console
50  * @param str string
51  */
52  static void println(const string_view& str);
53 
54  /**
55  * Print given string
56  * @param str string
57  */
58  static void print(const string_view& str);
59 
60  /**
61  * Print new line to console
62  */
63  static void println();
64 
65  /**
66  * Shutdown console logging and especially writing log to file
67  */
68  static void shutdown();
69 
70 private:
71  class LogWriterThread: public Thread {
72  public:
73  // forbid class copy
75  //
78  void flush();
79  private:
80  void run();
81  };
82 
83  //
86  STATIC_DLL_IMPEXT static vector<string> messages;
88  STATIC_DLL_IMPEXT static unique_ptr<LogWriterThread> logWriterThread;
89 };
Mutex implementation.
Definition: Mutex.h:19
Base class for threads.
Definition: Thread.h:20
void run()
Abstract run() method, should be implemented by subclassed class, will be called after spawn by start...
Definition: Console.cpp:35
Console class.
Definition: Console.h:29
static void println()
Print new line to console.
Definition: Console.cpp:92
static void setLogger(Logger *logger)
Set logger.
Definition: Console.cpp:56
static STATIC_DLL_IMPEXT bool newline
Definition: Console.h:85
static void shutdown()
Shutdown console logging and especially writing log to file.
Definition: Console.cpp:106
static STATIC_DLL_IMPEXT vector< string > messages
Definition: Console.h:86
static STATIC_DLL_IMPEXT Logger * logger
Definition: Console.h:87
static void print(const string_view &str)
Print given string.
Definition: Console.cpp:77
static STATIC_DLL_IMPEXT unique_ptr< LogWriterThread > logWriterThread
Definition: Console.h:88
static constexpr int HISTORY_LINECOUNT
Definition: Console.h:32
static STATIC_DLL_IMPEXT Mutex mutex
Definition: Console.h:84
virtual void println(const string_view &str)=0
virtual void print(const string_view &str)=0
#define STATIC_DLL_IMPEXT
Definition: tdme.h:15
#define FORBID_CLASS_COPY(CLASS)
Definition: tdme.h:6