CConsoleHandler.h 938 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #pragma once
  2. /*
  3. * CConsoleHandler.h, part of VCMI engine
  4. *
  5. * Authors: listed in file AUTHORS in main folder
  6. *
  7. * License: GNU General Public License v2.0 or later
  8. * Full text of license available in license.txt file, in main folder
  9. *
  10. */
  11. /// Class which wraps the native console. It can print text based on
  12. /// the chosen color
  13. class DLL_LINKAGE CConsoleHandler
  14. {
  15. public:
  16. boost::function<void(const std::string &)> *cb; //function to be called when message is received
  17. int curLvl; //logging level
  18. boost::thread *thread;
  19. int run();
  20. void setColor(int level); //sets color of text appropriate for given logging level
  21. CConsoleHandler(); //c-tor
  22. ~CConsoleHandler(); //d-tor
  23. void start(); //starts listening thread
  24. void end(); //kills listening thread
  25. template<typename T> void print(const T &data, int lvl)
  26. {
  27. setColor(lvl);
  28. std::cout << data << std::flush;
  29. setColor(-1);
  30. }
  31. };