Open Source Tomb Raider Engine
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

Log.h 1.7KB

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