CConsoleHandler.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 which wraps the native console. It can print text based on
  19. /// the chosen color
  20. class DLL_EXPORT CConsoleHandler
  21. {
  22. public:
  23. boost::function<void(const std::string &)> *cb; //function to be called when message is received
  24. int curLvl; //logging level
  25. boost::thread *thread;
  26. int run();
  27. void setColor(int level); //sets color of text appropriate for given logging level
  28. CConsoleHandler(); //c-tor
  29. ~CConsoleHandler(); //d-tor
  30. void start(); //starts listening thread
  31. void end(); //kills listening thread
  32. template<typename T> void print(const T &data, int level)
  33. {
  34. setColor(level);
  35. std::cout << data << std::flush;
  36. setColor(-1);
  37. }
  38. };
  39. #endif // __CCONSOLEHANDLER_H__