2009-04-16 14:14:13 +03:00
|
|
|
#ifndef __CCONSOLEHANDLER_H__
|
|
|
|
#define __CCONSOLEHANDLER_H__
|
|
|
|
|
2009-04-15 17:03:31 +03:00
|
|
|
/*
|
|
|
|
* CConsoleHandler.h, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
2009-04-16 14:14:13 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace boost
|
|
|
|
{
|
|
|
|
template<typename signature>
|
|
|
|
class function;
|
2009-06-23 11:14:49 +03:00
|
|
|
class thread;
|
2009-04-16 14:14:13 +03:00
|
|
|
}
|
2009-06-23 11:14:49 +03:00
|
|
|
|
2011-02-22 13:52:36 +02:00
|
|
|
/// Class which wraps the native console. It can print text based on
|
|
|
|
/// the chosen color
|
2009-04-16 14:14:13 +03:00
|
|
|
class DLL_EXPORT CConsoleHandler
|
|
|
|
{
|
|
|
|
public:
|
2009-05-07 20:20:41 +03:00
|
|
|
boost::function<void(const std::string &)> *cb; //function to be called when message is received
|
|
|
|
int curLvl; //logging level
|
2009-06-23 11:14:49 +03:00
|
|
|
boost::thread *thread;
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
int run();
|
2009-05-07 20:20:41 +03:00
|
|
|
void setColor(int level); //sets color of text appropriate for given logging level
|
2009-06-23 11:14:49 +03:00
|
|
|
|
2009-05-07 20:20:41 +03:00
|
|
|
CConsoleHandler(); //c-tor
|
|
|
|
~CConsoleHandler(); //d-tor
|
2009-06-23 11:14:49 +03:00
|
|
|
void start(); //starts listening thread
|
|
|
|
void end(); //kills listening thread
|
|
|
|
|
2009-04-16 14:14:13 +03:00
|
|
|
template<typename T> void print(const T &data, int level)
|
|
|
|
{
|
|
|
|
setColor(level);
|
|
|
|
std::cout << data << std::flush;
|
|
|
|
setColor(-1);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // __CCONSOLEHANDLER_H__
|