Open Source Tomb Raider Engine
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Log.h 1.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /*!
  2. * \file include/Log.h
  3. * \brief Log
  4. *
  5. * \author xythobuz
  6. */
  7. #ifndef _LOG_H_
  8. #define _LOG_H_
  9. #include <string>
  10. #include <sstream>
  11. #include <vector>
  12. #include <glm/gtc/type_precision.hpp>
  13. class Log {
  14. public:
  15. const static char endl = '\n';
  16. Log();
  17. unsigned long size();
  18. std::string get(unsigned long i);
  19. template<typename T>
  20. Log& operator<< (const T t) {
  21. printBuffer << t;
  22. if (printBuffer.str().back() == endl) {
  23. mHistory.push_back(printBuffer.str().substr(0, printBuffer.str().length() - 1));
  24. #ifdef DEBUG
  25. std::cout << printBuffer.str().substr(0, printBuffer.str().length() - 1) << std::endl;
  26. #endif
  27. printBuffer.str("");
  28. }
  29. return (*this);
  30. }
  31. Log& operator<< (const glm::vec2& v) {
  32. return (*this) << v.x << " " << v.y;
  33. }
  34. Log& operator<< (const glm::i32vec2& v) {
  35. return (*this) << v.x << " " << v.y;
  36. }
  37. Log& operator<< (const glm::vec3& v) {
  38. return (*this) << v.x << " " << v.y << " " << v.z;
  39. }
  40. private:
  41. std::vector<std::string> mHistory;
  42. std::ostringstream printBuffer;
  43. };
  44. Log& getLog();
  45. #endif