CConsoleHandler.h 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. #ifndef __CCONSOLEHANDLER_H__
  2. #define __CCONSOLEHANDLER_H__
  3. #ifndef _WIN32
  4. #define WORD std::string
  5. #endif
  6. #ifndef _WIN32
  7. #define _kill_thread(a,b) pthread_cancel(a);
  8. #else
  9. #define _kill_thread(a,b) TerminateThread(a,b);
  10. #endif
  11. /*
  12. * CConsoleHandler.h, part of VCMI engine
  13. *
  14. * Authors: listed in file AUTHORS in main folder
  15. *
  16. * License: GNU General Public License v2.0 or later
  17. * Full text of license available in license.txt file, in main folder
  18. *
  19. */
  20. namespace boost
  21. {
  22. template<typename signature>
  23. class function;
  24. }
  25. class DLL_EXPORT CConsoleHandler
  26. {
  27. public:
  28. boost::function<void(const std::string &)> *cb;
  29. int curLvl;
  30. int run();
  31. void setColor(int level);
  32. CConsoleHandler();
  33. ~CConsoleHandler();
  34. #ifndef _WIN32
  35. static void killConsole(pthread_t hThread); //for windows only, use native handle to the thread
  36. #else
  37. static void killConsole(void *hThread); //for windows only, use native handle to the thread
  38. #endif
  39. template<typename T> void print(const T &data, int level)
  40. {
  41. setColor(level);
  42. std::cout << data << std::flush;
  43. setColor(-1);
  44. }
  45. };
  46. #endif // __CCONSOLEHANDLER_H__