Restructure displayer to have reusable stringify

--HG--
branch : qt5
hg/feature/qt5
kaetemi 10 years ago
parent 95c54682b5
commit f3a1fb0b83

@ -68,8 +68,7 @@ bool CWindowDisplayer::update ()
vector<string> copy; vector<string> copy;
{ {
CSynchronized<std::vector<std::string> >::CAccessor access (&_CommandsToExecute); CSynchronized<std::vector<std::string> >::CAccessor access (&_CommandsToExecute);
copy = access.value(); copy.swap(access.value());
access.value().clear ();
} }
// execute all commands in the main thread // execute all commands in the main thread
@ -116,21 +115,15 @@ void CWindowDisplayer::create (string windowNameEx, bool iconified, sint x, sint
_Thread->start (); _Thread->start ();
} }
void CWindowDisplayer::doDisplay (const NLMISC::CLog::TDisplayInfo &args, const char *message) std::string CWindowDisplayer::stringifyMessage(const NLMISC::CLog::TDisplayInfo &args, const char *message, bool needSlashR)
{ {
bool needSpace = false; bool needSpace = false;
//stringstream ss; //stringstream ss;
string str; string str;
uint32 color = 0xFF000000;
if (args.LogType != CLog::LOG_NO) if (args.LogType != CLog::LOG_NO)
{ {
str += logTypeToString(args.LogType); str += CWindowDisplayer::logTypeToString(args.LogType);
if (args.LogType == CLog::LOG_ERROR || args.LogType == CLog::LOG_ASSERT) color = 0x00FF0000;
else if (args.LogType == CLog::LOG_WARNING) color = 0x00800000;
else if (args.LogType == CLog::LOG_DEBUG) color = 0x00808080;
else color = 0;
needSpace = true; needSpace = true;
} }
@ -200,6 +193,23 @@ void CWindowDisplayer::doDisplay (const NLMISC::CLog::TDisplayInfo &args, const
} }
str += pos; str += pos;
return str;
}
void CWindowDisplayer::doDisplay (const NLMISC::CLog::TDisplayInfo &args, const char *message)
{
uint32 color = 0xFF000000;
if (args.LogType != CLog::LOG_NO)
{
if (args.LogType == CLog::LOG_ERROR || args.LogType == CLog::LOG_ASSERT) color = 0x00FF0000;
else if (args.LogType == CLog::LOG_WARNING) color = 0x00800000;
else if (args.LogType == CLog::LOG_DEBUG) color = 0x00808080;
else color = 0;
}
std::string str = stringifyMessage(args, message, needSlashR);
{ {
CSynchronized<std::list<std::pair<uint32, std::string> > >::CAccessor access (&_Buffer); CSynchronized<std::list<std::pair<uint32, std::string> > >::CAccessor access (&_Buffer);
if (_HistorySize > 0 && access.value().size() >= (uint)_HistorySize) if (_HistorySize > 0 && access.value().size() >= (uint)_HistorySize)

Loading…
Cancel
Save