CConsoleHandler.h 1022 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #ifndef __CCONSOLEHANDLER_H__
  2. #define __CCONSOLEHANDLER_H__
  3. /*
  4. * CConsoleHandler.h, part of VCMI engine
  5. *
  6. * Authors: listed in file AUTHORS in main folder
  7. *
  8. * License: GNU General Public License v2.0 or later
  9. * Full text of license available in license.txt file, in main folder
  10. *
  11. */
  12. namespace boost
  13. {
  14. template<typename signature>
  15. class function;
  16. class thread;
  17. }
  18. class DLL_EXPORT CConsoleHandler
  19. {
  20. public:
  21. boost::function<void(const std::string &)> *cb; //function to be called when message is received
  22. int curLvl; //logging level
  23. boost::thread *thread;
  24. int run();
  25. void setColor(int level); //sets color of text appropriate for given logging level
  26. CConsoleHandler(); //c-tor
  27. ~CConsoleHandler(); //d-tor
  28. void start(); //starts listening thread
  29. void end(); //kills listening thread
  30. template<typename T> void print(const T &data, int level)
  31. {
  32. setColor(level);
  33. std::cout << data << std::flush;
  34. setColor(-1);
  35. }
  36. };
  37. #endif // __CCONSOLEHANDLER_H__