OpenRaider  0.1.4-dev
Open Source Tomb Raider Game Engine implementation
Log.h
Go to the documentation of this file.
1 
8 #ifndef _LOG_H_
9 #define _LOG_H_
10 
11 #include <iostream>
12 #include <string>
13 #include <sstream>
14 #include <vector>
15 
16 #include <glm/gtc/type_precision.hpp>
17 
18 #define LOG_USER 0
19 #define LOG_ERROR 1
20 #define LOG_WARNING 2
21 #define LOG_INFO 3
22 #define LOG_DEBUG 4
23 #define LOG_COUNT 5
24 
25 struct LogEntry {
26  public:
27  std::string text;
28  int level;
29  LogEntry(std::string t, int l) : text(t), level(l) { }
30 };
31 
32 class LogLevel;
33 class Log {
34  public:
35  const static char endl = '\n';
36 
37  static LogLevel& get(int level);
38  static unsigned long size() { return wholeLog.size(); }
39  static LogEntry& getEntry(unsigned long i) { return wholeLog.at(i); }
40 
41  private:
43 
44  static std::vector<LogEntry> wholeLog;
45  friend class LogLevel;
46 };
47 
48 class LogLevel {
49  public:
50  LogLevel(int l) : level(l) { printBuffer << std::boolalpha; }
51 
52  LogLevel& operator<< (const glm::vec2& v) {
53  return (*this) << v.x << " " << v.y;
54  }
55 
56  LogLevel& operator<< (const glm::i32vec2& v) {
57  return (*this) << v.x << " " << v.y;
58  }
59 
60  LogLevel& operator<< (const glm::vec3& v) {
61  return (*this) << v.x << " " << v.y << " " << v.z;
62  }
63 
64  template<typename T>
65  LogLevel& operator<< (const T t) {
66  printBuffer << t;
67  if (printBuffer.str().back() == Log::endl) {
68  std::string s = printBuffer.str().substr(0, printBuffer.str().length() - 1);
69  printBuffer.str("");
70  Log::wholeLog.emplace_back(s, level);
71 #ifdef DEBUG
72  std::cout << s << std::endl;
73 #endif
74  }
75  return (*this);
76  }
77 
78  private:
79  int level;
80  std::ostringstream printBuffer;
81 };
82 
83 #endif
84 
static LogEntry & getEntry(unsigned long i)
Definition: Log.h:39
int level
Definition: Log.h:79
static LogLevel logs[LOG_COUNT]
Definition: Log.h:42
std::ostringstream printBuffer
Definition: Log.h:80
#define LOG_COUNT
Definition: Log.h:23
static std::vector< LogEntry > wholeLog
Definition: Log.h:44
static const char endl
Definition: Log.h:35
LogEntry(std::string t, int l)
Definition: Log.h:29
LogLevel & operator<<(const glm::vec2 &v)
Definition: Log.h:52
LogLevel(int l)
Definition: Log.h:50
static unsigned long size()
Definition: Log.h:38
Definition: Log.h:33
int level
Definition: Log.h:28
Definition: Log.h:48
std::string text
Definition: Log.h:27
Definition: Log.h:25