Open Source Tomb Raider Engine
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Log.h 1.1KB

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