134 lines
1.9 KiB
C++
134 lines
1.9 KiB
C++
|
/*
|
||
|
* This file is a part of Winix
|
||
|
* and is not publicly distributed
|
||
|
*
|
||
|
* Copyright (c) 2011, Tomasz Sowa
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
*/
|
||
|
|
||
|
#include "core/slog.h"
|
||
|
#include "templates.h"
|
||
|
|
||
|
|
||
|
|
||
|
namespace TemplatesFunctions
|
||
|
{
|
||
|
static size_t slog_index = 0;
|
||
|
static LogManipulators slog_last_type;
|
||
|
|
||
|
|
||
|
|
||
|
bool slog_is()
|
||
|
{
|
||
|
if( !cur->session )
|
||
|
return false;
|
||
|
|
||
|
return slog_index < cur->session->log_buffer.Size();
|
||
|
}
|
||
|
|
||
|
|
||
|
void slog_skipline()
|
||
|
{
|
||
|
if( !cur->session )
|
||
|
return;
|
||
|
|
||
|
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||
|
|
||
|
while( slog_index < buf.Size() && buf[slog_index]!=10 )
|
||
|
slog_index += 1;
|
||
|
|
||
|
if( slog_index < buf.Size() )
|
||
|
slog_index += 1; // skipping the '\n'
|
||
|
}
|
||
|
|
||
|
|
||
|
void slog_settype()
|
||
|
{
|
||
|
if( !slog_is() )
|
||
|
return;
|
||
|
|
||
|
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||
|
slog_last_type = static_cast<LogManipulators>(buf[slog_index]);
|
||
|
|
||
|
switch( slog_last_type )
|
||
|
{
|
||
|
case loginfo:
|
||
|
case logwarning:
|
||
|
case logerror:
|
||
|
slog_index += 1;
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
slog_last_type = loginfo;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
void slog_tab(Info & i)
|
||
|
{
|
||
|
if( i.iter == 0 )
|
||
|
slog_index = 0;
|
||
|
else
|
||
|
slog_skipline();
|
||
|
|
||
|
// the type is written as the first character (after '\n' or at the beginning of the string)
|
||
|
slog_settype();
|
||
|
|
||
|
i.res = slog_is();
|
||
|
|
||
|
if( cur->session && !i.res )
|
||
|
cur->session->log_buffer.Clear(); // the session log has been printed
|
||
|
}
|
||
|
|
||
|
|
||
|
void slog_tab_is_info(Info & i)
|
||
|
{
|
||
|
if( !slog_is() )
|
||
|
return;
|
||
|
|
||
|
i.res = (slog_last_type == loginfo);
|
||
|
}
|
||
|
|
||
|
|
||
|
void slog_tab_is_warning(Info & i)
|
||
|
{
|
||
|
if( !slog_is() )
|
||
|
return;
|
||
|
|
||
|
i.res = (slog_last_type == logwarning);
|
||
|
}
|
||
|
|
||
|
|
||
|
void slog_tab_is_error(Info & i)
|
||
|
{
|
||
|
if( !slog_is() )
|
||
|
return;
|
||
|
|
||
|
i.res = (slog_last_type == logerror);
|
||
|
}
|
||
|
|
||
|
|
||
|
void slog_tab_print(Info & i)
|
||
|
{
|
||
|
if( !slog_is() )
|
||
|
return;
|
||
|
|
||
|
TextStream<std::wstring> & buf = cur->session->log_buffer;
|
||
|
|
||
|
while( slog_index < buf.Size() && buf[slog_index]!=10 )
|
||
|
{
|
||
|
i.out << buf[slog_index];
|
||
|
slog_index += 1;
|
||
|
}
|
||
|
|
||
|
// don't skip the last '\n' here
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
} // namespace TemplatesFunctions
|
||
|
|