CConsoleHandler.h 900 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. namespace boost
  12. {
  13. template<typename signature>
  14. class function;
  15. }
  16. class DLL_EXPORT CConsoleHandler
  17. {
  18. public:
  19. boost::function<void(const std::string &)> *cb;
  20. int curLvl;
  21. int run();
  22. void setColor(int level);
  23. CConsoleHandler();
  24. ~CConsoleHandler();
  25. #ifndef _WIN32
  26. static void killConsole(pthread_t hThread); //for windows only, use native handle to the thread
  27. #else
  28. static void killConsole(void *hThread); //for windows only, use native handle to the thread
  29. #endif
  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