Open Source Tomb Raider Engine
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

Log.h 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. 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. std::cout << printBuffer.str().substr(0, printBuffer.str().length() - 1) << std::endl;
  26. printBuffer.str("");
  27. }
  28. return (*this);
  29. }
  30. Log& operator<< (const glm::vec2& v) {
  31. return (*this) << v.x << " " << v.y;
  32. }
  33. Log& operator<< (const glm::i32vec2& v) {
  34. return (*this) << v.x << " " << v.y;
  35. }
  36. Log& operator<< (const glm::vec3& v) {
  37. return (*this) << v.x << " " << v.y << " " << v.z;
  38. }
  39. private:
  40. std::vector<std::string> mHistory;
  41. std::ostringstream printBuffer;
  42. };
  43. Log& getLog();
  44. #endif