NLMISC::CMemDisplayer Class Reference

#include <mem_displayer.h>

Inheritance diagram for NLMISC::CMemDisplayer:

NLMISC::IDisplayer NLMISC::CLightMemDisplayer

Detailed Description

Display into a string vector
Author:
Benjamin Legros

Nevrax France

Date:
2001

Definition at line 45 of file mem_displayer.h.

Public Member Functions

void clear ()
 CMemDisplayer (const char *displayerName="")
 Constructor.

void display (const CLog::TDisplayInfo &args, const char *message)
 Display the string where it does.

const std::deque< std::string > & lockStrings ()
void setParam (uint32 maxStrings=50)
 Set Parameter of the displayer if not set at the ctor time.

void unlockStrings ()
void write (std::string &str)
void write (CLog *log=NULL, bool quiet=true)
 Write N last line into a displayer (InfoLog by default).


Static Public Member Functions

const char * dateToComputerString (time_t date)
 Convert date to "784551148" string (time in second from 1975).

const char * dateToHumanString (time_t date)
 Convert date to "2000/01/14 10:05:17" string.

const char * dateToHumanString ()
 Convert the current date to human string.

const char * logTypeToString (CLog::TLogType logType, bool longFormat=false)
 Convert log type to string.


Data Fields

std::string DisplayerName
 This is the idenfiant for a displayer, it is used to fond or remove a displayer.


Protected Member Functions

virtual void doDisplay (const CLog::TDisplayInfo &args, const char *message)
 Put the string into the file.


Static Protected Member Functions

const char * HeaderString ()

Protected Attributes

bool _CanUseStrings
uint32 _MaxStrings
bool _NeedHeader
std::deque< std::string > _Strings


Constructor & Destructor Documentation

NLMISC::CMemDisplayer::CMemDisplayer const char *  displayerName = ""  ) 
 

Constructor.

Definition at line 318 of file mem_displayer.cpp.

References setParam().

00318                                                        : IDisplayer (displayerName), _NeedHeader(true), _MaxStrings(50), _CanUseStrings(true)
00319 {
00320         setParam (50);
00321 }


Member Function Documentation

void NLMISC::CMemDisplayer::clear void   )  [inline]
 

Definition at line 62 of file mem_displayer.h.

References _CanUseStrings, and _Strings.

Referenced by NLNET::IService::main(), NLNET::serviceGetView(), and NLNET::updateAdmin().

00062 { if (_CanUseStrings) _Strings.clear (); }

const char * NLMISC::IDisplayer::dateToComputerString time_t  date  )  [static, inherited]
 

Convert date to "784551148" string (time in second from 1975).

Definition at line 103 of file displayer.cpp.

References NLMISC::smprintf().

00104 {
00105         static char cstime[25];
00106         smprintf (cstime, 25, "%ld", &date);
00107         return cstime;
00108 }

const char * NLMISC::IDisplayer::dateToHumanString time_t  date  )  [static, inherited]
 

Convert date to "2000/01/14 10:05:17" string.

Definition at line 92 of file displayer.cpp.

References uint32.

00093 {
00094         static char cstime[25];
00095         struct tm *tms = localtime(&date);
00096         if (tms)
00097                 strftime (cstime, 25, "%Y/%m/%d %H:%M:%S", tms);
00098         else
00099                 sprintf(cstime, "bad date %d", (uint32)date);
00100         return cstime;
00101 }

const char * NLMISC::IDisplayer::dateToHumanString  )  [static, inherited]
 

Convert the current date to human string.

Definition at line 85 of file displayer.cpp.

Referenced by NLNET::CNetDisplayer::doDisplay(), doDisplay(), NLMISC::CMsgBoxDisplayer::doDisplay(), NLMISC::CFileDisplayer::doDisplay(), and NLMISC::IDisplayer::HeaderString().

00086 {
00087         time_t date;
00088         time (&date);
00089         return dateToHumanString (date);
00090 }

void NLMISC::IDisplayer::display const CLog::TDisplayInfo args,
const char *  message
[inherited]
 

Display the string where it does.

Definition at line 132 of file displayer.cpp.

References NLMISC::IDisplayer::doDisplay().

00133 {
00134         _Mutex->enter();
00135         try
00136         {
00137                 doDisplay( args, message );
00138         }
00139         catch (Exception &)
00140         {
00141                 // silence
00142         }
00143         _Mutex->leave();
00144 }

void NLMISC::CMemDisplayer::doDisplay const CLog::TDisplayInfo args,
const char *  message
[protected, virtual]
 

Put the string into the file.

Implements NLMISC::IDisplayer.

Reimplemented in NLMISC::CLightMemDisplayer.

Definition at line 330 of file mem_displayer.cpp.

References _CanUseStrings, _MaxStrings, _Strings, NLMISC::CLog::TDisplayInfo::Date, NLMISC::IDisplayer::dateToHumanString(), NLMISC::CLog::TDisplayInfo::Filename, NLMISC::IDisplayer::HeaderString(), NLMISC::CLog::TDisplayInfo::Line, NLMISC::CLog::TDisplayInfo::LogType, NLMISC::IDisplayer::logTypeToString(), NLMISC::CLog::TDisplayInfo::ProcessName, NLMISC::CLog::TDisplayInfo::ThreadId, and NLMISC::toString().

00331 {
00332 //      stringstream    ss;
00333         string str;
00334         bool                    needSpace = false;
00335 
00336         if (!_CanUseStrings) return;
00337 
00338         if (_NeedHeader)
00339         {
00340                 str += HeaderString();
00341                 _NeedHeader = false;
00342         }
00343 
00344         if (args.Date != 0)
00345         {
00346                 str += dateToHumanString(args.Date);
00347                 needSpace = true;
00348         }
00349 
00350         if (!args.ProcessName.empty())
00351         {
00352                 if (needSpace) { str += " "; needSpace = false; }
00353                 str += args.ProcessName;
00354                 needSpace = true;
00355         }
00356 
00357         if (args.LogType != CLog::LOG_NO)
00358         {
00359                 if (needSpace) { str += " "; needSpace = false; }
00360                 str += logTypeToString(args.LogType);
00361                 needSpace = true;
00362         }
00363 
00364         // Write thread identifier
00365         if ( args.ThreadId != 0 )
00366         {
00367                 if (needSpace) { str += " "; needSpace = false; }
00368                 str += NLMISC::toString("%5u", args.ThreadId);
00369                 needSpace = true;
00370         }
00371 
00372         if (args.Filename != NULL)
00373         {
00374                 if (needSpace) { str += " "; needSpace = false; }
00375                 str += CFile::getFilename(args.Filename);
00376                 needSpace = true;
00377         }
00378 
00379         if (args.Line != -1)
00380         {
00381                 if (needSpace) { str += " "; needSpace = false; }
00382                 str += NLMISC::toString(args.Line);
00383                 needSpace = true;
00384         }
00385         
00386         if (needSpace) { str += " : "; needSpace = false; }
00387 
00388         str += message;
00389 
00390         // clear old line
00391         while (_Strings.size () > _MaxStrings)
00392         {
00393                 _Strings.pop_front ();
00394         }
00395 
00396         _Strings.push_back (str);
00397 }

const char * NLMISC::IDisplayer::HeaderString  )  [static, protected, inherited]
 

Definition at line 110 of file displayer.cpp.

References NLMISC::IDisplayer::dateToHumanString(), and NLMISC::smprintf().

Referenced by doDisplay(), and NLMISC::CFileDisplayer::doDisplay().

00111 {
00112         static char header[1024];
00113         smprintf(header, 1024, "\nLog Starting [%s]\n", dateToHumanString());
00114         return header;
00115 }

const std::deque<std::string>& NLMISC::CMemDisplayer::lockStrings  )  [inline]
 

Definition at line 58 of file mem_displayer.h.

References _CanUseStrings, and _Strings.

Referenced by NLNET::IService::main(), NLMISC::NLMISC_COMMAND(), NLNET::serviceGetView(), and NLNET::updateAdmin().

00058 { _CanUseStrings = false; return _Strings; }

const char * NLMISC::IDisplayer::logTypeToString CLog::TLogType  logType,
bool  longFormat = false
[static, inherited]
 

Convert log type to string.

Definition at line 77 of file displayer.cpp.

References NLMISC::LogTypeToString.

Referenced by NLMISC::CWindowDisplayer::doDisplay(), NLNET::CNetDisplayer::doDisplay(), doDisplay(), NLMISC::CMsgBoxDisplayer::doDisplay(), NLMISC::CFileDisplayer::doDisplay(), and NLMISC::CStdDisplayer::doDisplay().

00078 {
00079         if (logType < CLog::LOG_NO || logType > CLog::LOG_UNKNOWN)
00080                 return "<NotDefined>";
00081 
00082         return LogTypeToString[longFormat?1:0][logType];
00083 }

void NLMISC::CMemDisplayer::setParam uint32  maxStrings = 50  ) 
 

Set Parameter of the displayer if not set at the ctor time.

Definition at line 323 of file mem_displayer.cpp.

References _MaxStrings, and uint32.

Referenced by CMemDisplayer(), and NLNET::serviceGetView().

00324 {
00325         _MaxStrings = maxStrings;
00326 }

void NLMISC::CMemDisplayer::unlockStrings  )  [inline]
 

Definition at line 60 of file mem_displayer.h.

References _CanUseStrings.

Referenced by NLNET::IService::main(), NLMISC::NLMISC_COMMAND(), NLNET::serviceGetView(), and NLNET::updateAdmin().

00060 { _CanUseStrings = true; }

void NLMISC::CMemDisplayer::write std::string &  str  ) 
 

Definition at line 426 of file mem_displayer.cpp.

References _Strings.

00427 {
00428         for (deque<string>::iterator it = _Strings.begin(); it != _Strings.end(); it++)
00429         {
00430                 str += (*it);
00431         }
00432 }

void NLMISC::CMemDisplayer::write CLog log = NULL,
bool  quiet = true
 

Write N last line into a displayer (InfoLog by default).

Definition at line 399 of file mem_displayer.cpp.

References _Strings, NLMISC::displayCallStack(), NLMISC::CLog::forceDisplayRaw(), and NLMISC::InfoLog.

Referenced by NLMISC::getCallStackAndLog(), and NLMISC::NLMISC_COMMAND().

00400 {
00401         if (log == NULL)
00402                 log = InfoLog;
00403 
00404         if ( ! quiet )
00405         {
00406                 log->forceDisplayRaw ("------------------------------------------------------------------------------\n");
00407                 log->forceDisplayRaw ("----------------------------------------- display MemDisplayer history -------\n");
00408                 log->forceDisplayRaw ("------------------------------------------------------------------------------\n");
00409         }
00410         for (deque<string>::iterator it = _Strings.begin(); it != _Strings.end(); it++)
00411         {
00412                 log->forceDisplayRaw ((*it).c_str());
00413         }
00414         if ( ! quiet )
00415         {
00416                 log->forceDisplayRaw ("------------------------------------------------------------------------------\n");
00417                 log->forceDisplayRaw ("----------------------------------------- display MemDisplayer callstack -----\n");
00418                 log->forceDisplayRaw ("------------------------------------------------------------------------------\n");
00419                 displayCallStack(log);
00420                 log->forceDisplayRaw ("------------------------------------------------------------------------------\n");
00421                 log->forceDisplayRaw ("----------------------------------------- end of MemDisplayer display --------\n");
00422                 log->forceDisplayRaw ("------------------------------------------------------------------------------\n");
00423         }
00424 }


Field Documentation

bool NLMISC::CMemDisplayer::_CanUseStrings [protected]
 

Definition at line 72 of file mem_displayer.h.

Referenced by clear(), doDisplay(), lockStrings(), and unlockStrings().

uint32 NLMISC::CMemDisplayer::_MaxStrings [protected]
 

Definition at line 70 of file mem_displayer.h.

Referenced by doDisplay(), and setParam().

bool NLMISC::CMemDisplayer::_NeedHeader [protected]
 

Definition at line 68 of file mem_displayer.h.

std::deque<std::string> NLMISC::CMemDisplayer::_Strings [protected]
 

Definition at line 74 of file mem_displayer.h.

Referenced by clear(), doDisplay(), lockStrings(), and write().

std::string NLMISC::IDisplayer::DisplayerName [inherited]
 

This is the idenfiant for a displayer, it is used to fond or remove a displayer.

Definition at line 63 of file displayer.h.

Referenced by NLMISC::IDisplayer::IDisplayer().


The documentation for this class was generated from the following files:
Generated on Tue Mar 16 13:22:05 2004 for NeL by doxygen 1.3.6