Open Source Tomb Raider Engine
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

Log.h 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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/vec2.hpp>
  13. #include <glm/vec3.hpp>
  14. #include <glm/gtc/type_precision.hpp>
  15. class Log {
  16. public:
  17. const static char endl = '\n';
  18. Log();
  19. unsigned long size();
  20. std::string get(unsigned long i);
  21. template<typename T>
  22. Log& operator<< (const T t) {
  23. printBuffer << t;
  24. if (printBuffer.str().back() == endl) {
  25. mHistory.push_back(printBuffer.str().substr(0, printBuffer.str().length() - 1));
  26. #ifdef DEBUG
  27. std::cout << printBuffer.str().substr(0, printBuffer.str().length() - 1) << std::endl;
  28. #endif
  29. printBuffer.str("");
  30. }
  31. return (*this);
  32. }
  33. Log& operator<< (const glm::vec2& v) {
  34. return (*this) << v.x << " " << v.y;
  35. }
  36. Log& operator<< (const glm::i32vec2& v) {
  37. return (*this) << v.x << " " << v.y;
  38. }
  39. Log& operator<< (const glm::vec3& v) {
  40. return (*this) << v.x << " " << v.y << " " << v.z;
  41. }
  42. private:
  43. std::vector<std::string> mHistory;
  44. std::ostringstream printBuffer;
  45. };
  46. Log& getLog();
  47. #endif