appkit  1.5.1
RoadNarrows Robotics Application Kit
rnr::LogBook Class Reference

Classes

struct  BookMark
 Log bookmark structure. More...
 
struct  Entry
 Log entry structure. More...
 

Public Types

typedef std::vector< EntryEntryList
 entry list type
 
typedef EntryList::iterator EntryListIter
 entry list iterator
 
typedef EntryList::const_iterator EntryListCIter
 entry const list iterator
 
typedef std::vector< BookMarkBookMarkList
 bookmark list type
 
typedef BookMarkList::iterator BookMarkListIter
 bookmark list iterator
 
typedef BookMarkList::const_iterator BookMarkListCIter
 bookmark const list iter
 

Public Member Functions

 LogBook (const std::string strName="Log Book", size_t uMaxEntries=MaxEntriesDft, size_t uMaxEntryLen=MaxEntryLenDft)
 Default initialization constructor. More...
 
 LogBook (const LogBook &src)
 Copy constructor. More...
 
virtual ~LogBook ()
 Destructor.
 
LogBookoperator= (const LogBook &rhs)
 Assignment operator. More...
 
LogBookoperator<< (bool val)
 
LogBookoperator<< (char val)
 
LogBookoperator<< (int val)
 
LogBookoperator<< (unsigned int val)
 
LogBookoperator<< (long val)
 
LogBookoperator<< (unsigned long val)
 
LogBookoperator<< (long long val)
 
LogBookoperator<< (unsigned long long val)
 
LogBookoperator<< (float val)
 
LogBookoperator<< (double val)
 
LogBookoperator<< (long double val)
 
LogBookoperator<< (const char *val)
 
LogBookoperator<< (void *val)
 
LogBookoperator<< (const std::string &val)
 
LogBookoperator<< (const LogBook &log)
 
LogBookoperator<< (LogBook &(*pf)(LogBook &))
 
LogBookoperator<< (std::ostream &(*pf)(std::ostream &))
 
LogBookoperator<< (std::ios &(*pf)(std::ios &))
 
LogBookoperator<< (std::ios_base &(*pf)(std::ios_base &))
 
size_t logEntry (const std::string strText, const std::string strMark="")
 Log the given entry into the log book. More...
 
size_t logPending ()
 Log any pending entry into the log book. More...
 
void setPendingText (const std::string strText)
 Set the pending log text. More...
 
void setPendingBookMark (const std::string strMark)
 Set the pending bookmark. More...
 
void setPending (const std::string strText, const std::string strMark)
 Set the pending log text and associated bookmark. More...
 
void erasePendingText ()
 Erase the pending log text.
 
void erasePendingBookMark ()
 Erase the pending log bookmark.
 
void erasePending ()
 Erase the pending log text and associated bookmark.
 
size_t eraseToMark (const std::string strMark, int whence)
 Erases all entries from the log book up to the bookmark. More...
 
size_t eraseEntries (size_t uNumEntries, int whence)
 Erases a given number of entries from the log book. More...
 
void clear ()
 Clear the log book and bookmarks, along with any pending entry.
 
const Entryat (const std::string &strMark) const
 Get the entry at the bookmark. More...
 
const Entryat (const size_t index) const
 Get the entry at the index. More...
 
const Entryat (const size_t index, int whence) const
 Get the entry at relative index from whence. More...
 
const Entryoperator[] (const size_t index) const
 Log book array index operator. More...
 
const Entryoperator[] (const std::string &strMark) const
 Log book array mark operator. More...
 
const EntrylastEntry () const
 Get the last (latest) log entry. More...
 
const std::string & textAt (const std::string &strMark) const
 Get the entry text at the bookmark. More...
 
const std::string & textAt (const size_t index) const
 Get the entry text at the index. More...
 
const std::string & textAt (const size_t index, int whence) const
 Get the entry text at relative index from whence. More...
 
const std::string & lastText () const
 Get the last (latest) log entry text. More...
 
size_t getBookMarks (BookMarkList &list, int whence) const
 Get a sorted list of bookmark labels. More...
 
bool hasBookMark (const std::string &strMark) const
 Test if bookmark exists in log book. More...
 
const std::string & getName () const
 Get the name of the log book. More...
 
void setName (const std::string &strName)
 Set the name of the log book. More...
 
const size_t max_size () const
 Return the maximum number entries the log book can hold. More...
 
size_t size () const
 Return the number of logged entries in the log book. More...
 
void resize (size_t uMaxEntries)
 Resize maximum size of log book. More...
 
size_t numOfTotalEver () const
 Return the total number of entries ever added during log book's life. More...
 
unsigned getFlags () const
 Get the current formatting flags. More...
 
unsigned setFlags (const unsigned uFlags)
 Set the current formatting flags. More...
 
unsigned orFlags (const unsigned uFlags)
 Or new flags into the current formatting flags. More...
 
unsigned compAndFlags (const unsigned uFlags)
 Apply one's Complement and And into the current formatting flags. More...
 
void clearFlags ()
 Clear alll current formatting flags.
 
std::string makeBookMarkLabel ()
 Generate a unique bookmark label. More...
 
std::ostream & printLog (std::ostream &os) const
 Print the entire log book to the output stream. More...
 
std::ostream & printToMark (std::ostream &os, const std::string strMark, int endpt) const
 Print the log book entires between the bookmark and the specified end point to the output stream. More...
 

Static Public Attributes

static const size_t MaxEntriesDft = 100
 max num entries default
 
static const size_t MaxEntryLenDft = 0x2000
 max entry length (8192)
 
static const int OLDEST = 0
 oldest entries
 
static const int NEWEST = 1
 newest, most recent entries
 
static const unsigned FlagNone = 0x0000
 no flags
 
static const unsigned FlagONum = 0x0001
 output log entry number
 
static const unsigned FlagOTime = 0x0002
 output log entry time
 
static const unsigned FlagOMark = 0x0004
 output log entry bookmarks
 
static const unsigned FlagOAllF = 0x0007
 output all entry fields
 
static const unsigned FlagORev = 0x0008
 output log reverse order
 
static const unsigned FlagDebug = 0x1000
 debug
 

Protected Types

typedef std::deque< EntryBookDeq
 book type
 
typedef BookDeq::iterator BookIter
 book iterator
 
typedef BookDeq::const_iterator BookCIter
 book const iterator
 
typedef BookDeq::reverse_iterator BookRIter
 reverse book iter
 
typedef BookDeq::const_reverse_iterator BookCRIter
 const rev book iter
 

Protected Member Functions

void limitSize ()
 Limit size of log book to defined limit.
 
void ssflush ()
 Flush the pending text stream. More...
 
bool checkLen (size_t uEstLen=1)
 Check the length of the pending entry. More...
 
BookIter findMark (const std::string &strMark)
 Find position it log book of the bookmarked entry. More...
 
BookCIter findMark (const std::string &strMark) const
 Find position it log book of the bookmarked entry. More...
 
void sortMarks (BookMarkList &sorted) const
 Sort bookmarks from oldest to newest. More...
 
void rsortMarks (BookMarkList &sorted) const
 Reverse sort bookmarks from newest to oldest. More...
 
void copy (const LogBook &src)
 Copy log book verbatim to this log book. More...
 
void prt (std::ostream &os, size_t index0, size_t index1) const
 Print log book from index 0 to index 1, inclusive. More...
 
void rprt (std::ostream &os, size_t index0, size_t index1) const
 Reverse print log book from index 1 to index 0, inclusive. More...
 

Protected Attributes

std::string m_strName
 name of log
 
size_t m_uMaxEntries
 maximum number of log entries
 
size_t m_uMaxEntryLen
 maximum entry length
 
size_t m_uTotalEver
 total entries added during lifetime
 
unsigned m_uFlags
 formatting flags
 
bool m_bWarnThrottle
 do [not] throttle warnings
 
std::string m_strMark
 pending bookmark label
 
std::stringstream m_ssText
 pending text stream
 
BookDeq m_book
 the log book
 

Friends

std::ostream & operator<< (std::ostream &os, const LogBook &log)
 Stream insertion operator. More...
 

Detailed Description

Definition at line 79 of file LogBook.h.

Constructor & Destructor Documentation

LogBook::LogBook ( const std::string  strName = "Log Book",
size_t  uMaxEntries = MaxEntriesDft,
size_t  uMaxEntryLen = MaxEntryLenDft 
)

Default initialization constructor.

Parameters
strNameName of log book.
uMaxEntriesMaximum number of entries in log book.
uMaxEntryLenMaximum entry length.

Definition at line 148 of file LogBook.cxx.

References FlagONum, m_bWarnThrottle, m_uFlags, and m_uTotalEver.

150  :
151  m_strName(strName),
152  m_uMaxEntries(uMaxEntries),
153  m_uMaxEntryLen(uMaxEntryLen)
154 
155 {
156  m_uTotalEver = 0;
157  m_uFlags = FlagONum;
158  m_bWarnThrottle = false;
159 }
size_t m_uMaxEntries
maximum number of log entries
Definition: LogBook.h:761
static const unsigned FlagONum
output log entry number
Definition: LogBook.h:98
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
bool m_bWarnThrottle
do [not] throttle warnings
Definition: LogBook.h:765
std::string m_strName
name of log
Definition: LogBook.h:760
size_t m_uTotalEver
total entries added during lifetime
Definition: LogBook.h:763
size_t m_uMaxEntryLen
maximum entry length
Definition: LogBook.h:762
LogBook::LogBook ( const LogBook src)

Copy constructor.

Parameters
srcSource object.

Definition at line 161 of file LogBook.cxx.

References copy().

162 {
163  copy(src);
164 }
void copy(const LogBook &src)
Copy log book verbatim to this log book.
Definition: LogBook.cxx:911

Member Function Documentation

const Entry& rnr::LogBook::at ( const std::string &  strMark) const

Get the entry at the bookmark.

Parameters
strMarkBookmark label.
Returns
If the entry exists, reference to log entry is returned. Otherwise, a "no entry" entry is returned (test with Entry::empty()).

Referenced by clear(), operator[](), and textAt().

const LogBook::Entry & LogBook::at ( const size_t  index) const

Get the entry at the index.

Parameters
indexLog book absolute index.
Returns
If the entry exists, reference to log entry is returned. Otherwise, a "no entry" entry is returned (test with Entry::empty()).

Definition at line 544 of file LogBook.cxx.

References m_book, and size().

545 {
546  if( index < size() )
547  {
548  return m_book[index];
549  }
550  else
551  {
552  return noentry;
553  }
554 }
BookDeq m_book
the log book
Definition: LogBook.h:768
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
const LogBook::Entry & LogBook::at ( const size_t  index,
int  whence 
) const

Get the entry at relative index from whence.

Parameters
indexRelative log book index.
whenceWhence directive (OLDEST or NEWEST).
Returns
If the entry exists, reference to log entry is returned. Otherwise, a "no entry" entry is returned (test with Entry::empty()).

Definition at line 556 of file LogBook.cxx.

References m_book, NEWEST, and size().

557 {
558  size_t i;
559 
560  if( index < size() )
561  {
562  i = whence == NEWEST? size() - index - 1: index;
563  return m_book[i];
564  }
565  else
566  {
567  return noentry;
568  }
569 }
BookDeq m_book
the log book
Definition: LogBook.h:768
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
static const int NEWEST
newest, most recent entries
Definition: LogBook.h:92
bool LogBook::checkLen ( size_t  uEstLen = 1)
protected

Check the length of the pending entry.

Parameters
uEstLenEstimated length of the new object text to be added.
Returns
Returns true if pending entry within bounds, false otherwise.

Definition at line 804 of file LogBook.cxx.

References findMark(), m_book, m_bWarnThrottle, m_ssText, and m_uMaxEntryLen.

Referenced by operator=().

805 {
806  if( m_ssText.str().size()+uEstLen < m_uMaxEntryLen )
807  {
808  return true;
809  }
810  else
811  {
812  if( !m_bWarnThrottle )
813  {
814  LOGWARN("Pending entry exceeds max entry length %zu.", m_uMaxEntryLen);
815  m_bWarnThrottle = true;
816  }
817  return false;
818  }
819 }
std::stringstream m_ssText
pending text stream
Definition: LogBook.h:767
bool m_bWarnThrottle
do [not] throttle warnings
Definition: LogBook.h:765
size_t m_uMaxEntryLen
maximum entry length
Definition: LogBook.h:762
unsigned rnr::LogBook::compAndFlags ( const unsigned  uFlags)
inline

Apply one's Complement and And into the current formatting flags.

Parameters
uFlagsFlags to unset.
Returns
New bit list of or'ed flags.

Definition at line 656 of file LogBook.h.

References m_uFlags.

657  {
658  m_uFlags &= ~uFlags;
659  return m_uFlags;
660  }
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
void LogBook::copy ( const LogBook src)
protected

Copy log book verbatim to this log book.

Parameters
srcSource log book.

Definition at line 911 of file LogBook.cxx.

References m_book, m_strName, m_uFlags, m_uMaxEntries, m_uMaxEntryLen, and m_uTotalEver.

Referenced by LogBook(), and operator=().

912 {
913  m_strName = src.m_strName;
917  m_uFlags = src.m_uFlags;
918  m_book = src.m_book;
919 }
BookDeq m_book
the log book
Definition: LogBook.h:768
size_t m_uMaxEntries
maximum number of log entries
Definition: LogBook.h:761
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
std::string m_strName
name of log
Definition: LogBook.h:760
size_t m_uTotalEver
total entries added during lifetime
Definition: LogBook.h:763
size_t m_uMaxEntryLen
maximum entry length
Definition: LogBook.h:762
size_t LogBook::eraseEntries ( size_t  uNumEntries,
int  whence 
)

Erases a given number of entries from the log book.

If whence is OLDEST, then the entries are erased starting from the oldest entry.

If whence is NEWEST, then the entries are erased starting from the most recent entry.

Parameters
uNumEntriesNumber of entries to delete. If >= number of entries, then the book is erased.
whenceWhence directive (OLDEST or NEWEST).
Returns
Returns the new number of entries in the log book.

Definition at line 483 of file LogBook.cxx.

References m_book, NEWEST, OLDEST, and size().

Referenced by limitSize().

484 {
485  BookIter first, last;
486 
487  if( uNumEntries > size() )
488  {
489  uNumEntries = size();
490  }
491 
492  switch( whence )
493  {
494  case OLDEST:
495  first = m_book.begin();
496  last = first + uNumEntries;
497  m_book.erase(first, last);
498  break;
499  case NEWEST:
500  last = m_book.end();
501  first = last - uNumEntries;
502  m_book.erase(first, last);
503  break;
504  default:
505  LOGERROR("Unknown whence = %d", whence);
506  break;
507  }
508 
509  return size();
510 }
BookDeq m_book
the log book
Definition: LogBook.h:768
BookDeq::iterator BookIter
book iterator
Definition: LogBook.h:752
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
static const int NEWEST
newest, most recent entries
Definition: LogBook.h:92
static const int OLDEST
oldest entries
Definition: LogBook.h:91
size_t LogBook::eraseToMark ( const std::string  strMark,
int  whence 
)

Erases all entries from the log book up to the bookmark.

If whence is OLDEST, then the entries erased are from the oldest entries up to, but not including, the first encounter of the bookmarked entry.

If whence is NEWEST, then the entries erased are from the most recent logged entry up to and including the first encounter of the bookmarked entry.

If the bookmark is not found, then no entries are erased.

Parameters
strMarkBookmark search label.
whenceWhence directive (OLDEST or NEWEST).
Returns
Returns the new number of entries in the log book.

Definition at line 457 of file LogBook.cxx.

References findMark(), m_book, NEWEST, OLDEST, and size().

458 {
459  BookIter pos;
460 
461  // no bookmark found
462  if( (pos = findMark(strMark)) == m_book.end() )
463  {
464  return size();
465  }
466 
467  switch( whence )
468  {
469  case NEWEST:
470  m_book.erase(pos, m_book.end());
471  break;
472  case OLDEST:
473  m_book.erase(m_book.begin(), pos);
474  break;
475  default:
476  LOGERROR("Unknown whence = %d", whence);
477  break;
478  }
479 
480  return size();
481 }
BookDeq m_book
the log book
Definition: LogBook.h:768
BookDeq::iterator BookIter
book iterator
Definition: LogBook.h:752
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
BookIter findMark(const std::string &strMark)
Find position it log book of the bookmarked entry.
static const int NEWEST
newest, most recent entries
Definition: LogBook.h:92
static const int OLDEST
oldest entries
Definition: LogBook.h:91
BookIter rnr::LogBook::findMark ( const std::string &  strMark)
protected

Find position it log book of the bookmarked entry.

The search starts at the oldest entry.

Parameters
strMarkBookmark search label.
Returns
If the bookmark entry is found, the position is returned. Otherwise, book end() is returned.

Referenced by checkLen(), clear(), eraseToMark(), hasBookMark(), and printToMark().

BookCIter rnr::LogBook::findMark ( const std::string &  strMark) const
protected

Find position it log book of the bookmarked entry.

Constant version.

The search starts at the oldest entry.

Parameters
strMarkBookmark search label.
Returns
If the bookmark entry is found, the position is returned. Otherwise, book end() is returned.
size_t LogBook::getBookMarks ( BookMarkList list,
int  whence 
) const

Get a sorted list of bookmark labels.

If whence is OLDEST, then sort from oldest to newest. If whence is NEWEST, then sort from most recent to oldest.

Parameters
[out]listList of sorted bookmark labels.
whenceWhence directive (OLDEST or NEWEST).
Returns
Number of bookmarks in list.

Definition at line 594 of file LogBook.cxx.

References NEWEST, OLDEST, rsortMarks(), and sortMarks().

Referenced by lastText(), and mainInit().

595 {
596  switch( whence )
597  {
598  case OLDEST:
599  sortMarks(list);
600  break;
601  case NEWEST:
602  rsortMarks(list);
603  break;
604  default:
605  LOGERROR("Unknown whence = %d", whence);
606  list.clear();
607  }
608 
609  return list.size();
610 }
void rsortMarks(BookMarkList &sorted) const
Reverse sort bookmarks from newest to oldest.
Definition: LogBook.cxx:881
static const int NEWEST
newest, most recent entries
Definition: LogBook.h:92
static const int OLDEST
oldest entries
Definition: LogBook.h:91
void sortMarks(BookMarkList &sorted) const
Sort bookmarks from oldest to newest.
Definition: LogBook.cxx:851
unsigned rnr::LogBook::getFlags ( ) const
inline

Get the current formatting flags.

Returns
Bit list of or'ed flags.

Definition at line 618 of file LogBook.h.

References m_uFlags.

Referenced by mainInit().

619  {
620  return m_uFlags;
621  }
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
const std::string& rnr::LogBook::getName ( ) const
inline

Get the name of the log book.

Returns
String.

Definition at line 558 of file LogBook.h.

References m_strName.

Referenced by mainInit().

559  {
560  return m_strName;
561  }
std::string m_strName
name of log
Definition: LogBook.h:760
bool rnr::LogBook::hasBookMark ( const std::string &  strMark) const
inline

Test if bookmark exists in log book.

Parameters
strMarkBookmark label.
Returns
Returns true or false.

Definition at line 548 of file LogBook.h.

References findMark(), and m_book.

549  {
550  return findMark(strMark) != m_book.end();
551  }
BookDeq m_book
the log book
Definition: LogBook.h:768
BookIter findMark(const std::string &strMark)
Find position it log book of the bookmarked entry.
const LogBook::Entry & LogBook::lastEntry ( ) const

Get the last (latest) log entry.

Returns
If the entry exists, reference to the last log entry is returned. Otherwise, a "no entry" entry is returned (test with Entry::empty()).

Definition at line 581 of file LogBook.cxx.

References m_book, and size().

Referenced by lastText().

582 {
583  if( size() > 0 )
584  {
585  return m_book[size()-1];
586  }
587  else
588  {
589  return noentry;
590  }
591 }
BookDeq m_book
the log book
Definition: LogBook.h:768
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
const std::string& rnr::LogBook::lastText ( ) const
inline

Get the last (latest) log entry text.

Returns
If the entry exists, reference to the last log entry is returned. Otherwise, a "no entry" entry is returned (test with Entry::empty()).

Definition at line 523 of file LogBook.h.

References getBookMarks(), lastEntry(), and rnr::LogBook::Entry::m_strText.

Referenced by rnr::cmd::CommandLine::getErrorStr().

524  {
525  return lastEntry().m_strText;
526  }
std::string m_strText
entry text, empty if no text
Definition: LogBook.h:112
const Entry & lastEntry() const
Get the last (latest) log entry.
Definition: LogBook.cxx:581
size_t LogBook::logEntry ( const std::string  strText,
const std::string  strMark = "" 
)

Log the given entry into the log book.

Any pending log entry remains untouched.

Note
The alternative method to log an entry is to use the LogBook insertion stream operators.
Parameters
strTextLog entry text.
strMarkAssociated log entry bookmark. If empty (""), then no bookmark added.
Returns
Returns the new number of entries in the log book.

Definition at line 370 of file LogBook.cxx.

References FlagDebug, limitSize(), m_book, m_uFlags, m_uTotalEver, and size().

371 {
372  if( m_uFlags & FlagDebug )
373  {
374  cerr << "DBG: " << __func__ << "("
375  << "mark=\"" << strMark << "\", "
376  << "text=\"" << strText << "\")" <<endl;
377  }
378 
379  Entry entry(strMark, strText);
380 
381  // add log entry to log book
382  m_book.push_back(entry);
383 
384  ++m_uTotalEver;
385 
386  // limit log's size
387  limitSize();
388 
389  return size();
390 }
BookDeq m_book
the log book
Definition: LogBook.h:768
static const unsigned FlagDebug
debug
Definition: LogBook.h:103
void limitSize()
Limit size of log book to defined limit.
Definition: LogBook.cxx:789
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
size_t m_uTotalEver
total entries added during lifetime
Definition: LogBook.h:763
size_t LogBook::logPending ( )

Log any pending entry into the log book.

The pending entry and associated bookmark are recorded into log. The pending data are then erased.

Note
The alternative method to log an entry is to use the LogBook insertion stream operators.
Returns
Returns the new number of entries in the log book.

Definition at line 392 of file LogBook.cxx.

References erasePending(), FlagDebug, limitSize(), m_book, m_ssText, m_strMark, m_uFlags, m_uTotalEver, and size().

Referenced by rnr::eoe().

393 {
394  // no pending entry
395  if( m_ssText.str().empty() )
396  {
397  return size();
398  }
399 
400  if( m_uFlags & FlagDebug )
401  {
402  cerr << "DBG: " << __func__ << "() "
403  << "mark=\"" << m_strMark << "\", "
404  << "text=\"" << m_ssText.str() << "\"" <<endl;
405  }
406 
407  Entry entry(m_strMark, m_ssText.str());
408 
409  // add pending log entry to log book
410  m_book.push_back(entry);
411 
412  // erase pending
413  erasePending();
414 
415  ++m_uTotalEver;
416 
417  // limit log's size
418  limitSize();
419 
420  return size();
421 }
BookDeq m_book
the log book
Definition: LogBook.h:768
void erasePending()
Erase the pending log text and associated bookmark.
Definition: LogBook.cxx:451
static const unsigned FlagDebug
debug
Definition: LogBook.h:103
void limitSize()
Limit size of log book to defined limit.
Definition: LogBook.cxx:789
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
std::stringstream m_ssText
pending text stream
Definition: LogBook.h:767
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
std::string m_strMark
pending bookmark label
Definition: LogBook.h:766
size_t m_uTotalEver
total entries added during lifetime
Definition: LogBook.h:763
std::string LogBook::makeBookMarkLabel ( )

Generate a unique bookmark label.

Returns
Label string.

Definition at line 612 of file LogBook.cxx.

References m_uTotalEver, rnr::operator<<(), and printLog().

Referenced by rnr::bookmark(), and clearFlags().

613 {
614  stringstream ss;
615 
616  ss << "_bookmark." << m_uTotalEver << "_";
617 
618  return ss.str();
619 }
size_t m_uTotalEver
total entries added during lifetime
Definition: LogBook.h:763
const size_t rnr::LogBook::max_size ( ) const
inline

Return the maximum number entries the log book can hold.

Returns
Size.

Definition at line 578 of file LogBook.h.

References m_uMaxEntries.

Referenced by mainInit().

579  {
580  return m_uMaxEntries;
581  }
size_t m_uMaxEntries
maximum number of log entries
Definition: LogBook.h:761
size_t rnr::LogBook::numOfTotalEver ( ) const
inline

Return the total number of entries ever added during log book's life.

Returns
Total number.

Definition at line 608 of file LogBook.h.

References m_uTotalEver.

Referenced by mainInit().

609  {
610  return m_uTotalEver;
611  }
size_t m_uTotalEver
total entries added during lifetime
Definition: LogBook.h:763
LogBook & LogBook::operator= ( const LogBook rhs)

Assignment operator.

Parameters
rhsRight-hand side object.
Returns
*this

Definition at line 170 of file LogBook.cxx.

References checkLen(), copy(), limitSize(), m_book, m_ssText, m_uTotalEver, and size().

171 {
172  copy(rhs);
173  return *this;
174 }
void copy(const LogBook &src)
Copy log book verbatim to this log book.
Definition: LogBook.cxx:911
const LogBook::Entry & LogBook::operator[] ( const size_t  index) const

Log book array index operator.

Get the entry at the index.

Parameters
indexLog book absolute index.
Returns
If the entry exists, reference to log entry is returned. Otherwise, a "no entry" entry is returned (test with Entry::empty()).

Definition at line 571 of file LogBook.cxx.

References at().

572 {
573  return at(index);
574 }
const Entry & at(const std::string &strMark) const
Get the entry at the bookmark.
const Entry& rnr::LogBook::operator[] ( const std::string &  strMark) const

Log book array mark operator.

Parameters
strMarkBookmark label.
Returns
If the entry exists, reference to log entry is returned. Otherwise, a "no entry" entry is returned (test with Entry::empty()).
unsigned rnr::LogBook::orFlags ( const unsigned  uFlags)
inline

Or new flags into the current formatting flags.

Parameters
uFlagsFlags to or into bit list of flags.
Returns
New bit list of or'ed flags.

Definition at line 643 of file LogBook.h.

References m_uFlags.

Referenced by mainInit().

644  {
645  m_uFlags |= uFlags;
646  return m_uFlags;
647  }
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
ostream & LogBook::printLog ( std::ostream &  os) const

Print the entire log book to the output stream.

The output is controlled by the current formatting flag bits.

* LogBook
* entry_0    | ^   <-- oldest end point
* entry_1    | |
*   ...      | |
* entry_n-1  v |   <-- newest end point
*             \ \
*              \ \
*               \ reverse order
*                \
*                 forward order
* 
Parameters
osOutput stream.
Returns
Reference to output stream.

Definition at line 630 of file LogBook.cxx.

References FlagORev, m_uFlags, prt(), rprt(), and size().

Referenced by rnr::cmd::CommandLine::backtrace(), clearFlags(), and makeBookMarkLabel().

631 {
632  // reverse order: newest to oldest
633  if( m_uFlags & FlagORev )
634  {
635  rprt(os, 0, size() - 1);
636  }
637  // forward order: oldest to newest
638  else
639  {
640  prt(os, 0, size() - 1);
641  }
642 
643  return os;
644 }
void rprt(std::ostream &os, size_t index0, size_t index1) const
Reverse print log book from index 1 to index 0, inclusive.
Definition: LogBook.cxx:734
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
static const unsigned FlagORev
output log reverse order
Definition: LogBook.h:102
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
void prt(std::ostream &os, size_t index0, size_t index1) const
Print log book from index 0 to index 1, inclusive.
Definition: LogBook.cxx:688
ostream & LogBook::printToMark ( std::ostream &  os,
const std::string  strMark,
int  endpt 
) const

Print the log book entires between the bookmark and the specified end point to the output stream.

The output is controlled by the current formatting flag bits.

If the opposite end point to the mark is the oldest entry, then the bookmark entry is excluded. Otherwise it is included.

* LogBook 
* entry_0    | ^   <-- oldest end point
* entry_1    | |
*   ...      | |
* entry_k-1  v |   <-- sans mark end point
*
* entry_k    | ^   <-- mark end point
* entry_k+1  | |
*   ...      | |
* entry_n-1  v |   <-- newest end point
*             \ \
*              \ \
*               \ reverse order
*                \
*                 forward order
* 
Parameters
osOutput stream.
strMarkBookmark search label.
endptOpposite end point to mark (OLDEST or NEWEST).
Returns
Reference to output stream.

Definition at line 646 of file LogBook.cxx.

References findMark(), FlagORev, m_book, m_uFlags, OLDEST, prt(), rprt(), and size().

Referenced by rnr::cmd::CommandLine::backtrace(), and clearFlags().

647 {
648  BookCIter pos;
649  size_t indexMark;
650 
651  // no mark
652  if( (pos = findMark(strMark)) == m_book.end() )
653  {
654  return os;
655  }
656 
657  indexMark = distance(m_book.begin(), pos);
658 
659  // reverse order: newest to oldest
660  if( m_uFlags & FlagORev )
661  {
662  if( endpt == OLDEST )
663  {
664  rprt(os, 0, indexMark-1);
665  }
666  else // NEWEST
667  {
668  rprt(os, indexMark, size()-1);
669  }
670  }
671 
672  // forward order: oldest to newest
673  else
674  {
675  if( endpt == OLDEST )
676  {
677  prt(os, 0, indexMark-1);
678  }
679  else // NEWEST
680  {
681  prt(os, indexMark, size()-1);
682  }
683  }
684 
685  return os;
686 }
BookDeq m_book
the log book
Definition: LogBook.h:768
void rprt(std::ostream &os, size_t index0, size_t index1) const
Reverse print log book from index 1 to index 0, inclusive.
Definition: LogBook.cxx:734
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
static const unsigned FlagORev
output log reverse order
Definition: LogBook.h:102
BookIter findMark(const std::string &strMark)
Find position it log book of the bookmarked entry.
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
BookDeq::const_iterator BookCIter
book const iterator
Definition: LogBook.h:753
void prt(std::ostream &os, size_t index0, size_t index1) const
Print log book from index 0 to index 1, inclusive.
Definition: LogBook.cxx:688
static const int OLDEST
oldest entries
Definition: LogBook.h:91
void LogBook::prt ( std::ostream &  os,
size_t  index0,
size_t  index1 
) const
protected

Print log book from index 0 to index 1, inclusive.

The output is controlled by the current formatting flag bits.

Parameters
osOutput stream.
index0Starting log book index.
index1Ending log book index.

Definition at line 688 of file LogBook.cxx.

References FlagDebug, FlagOMark, FlagONum, FlagOTime, m_book, m_uFlags, and size().

Referenced by printLog(), and printToMark().

689 {
690  BookCIter iter, pos0, pos1;
691  size_t index;
692 
693  if( m_uFlags & FlagDebug )
694  {
695  os << "DBG: " << __func__ << "(" << index0 << ", " << index1 << ")" << endl;
696  }
697 
698  if( size() == 0 )
699  {
700  return;
701  }
702  else if( (index0 > index1) || (index1 >= size()) )
703  {
704  return;
705  }
706 
707  pos0 = m_book.begin() + index0;
708  pos1 = m_book.begin() + index1;
709  index = index0;
710 
711  for(iter = pos0; iter != m_book.end() && iter <= pos1; ++iter)
712  {
713  if( (m_uFlags & FlagOMark) && !iter->m_strMark.empty() )
714  {
715  os << " ~~ " << iter->m_strMark << endl;
716  }
717 
718  if( m_uFlags & FlagONum )
719  {
720  os << setw(3) << index << ". ";
721  }
722 
723  if( m_uFlags & FlagOTime )
724  {
725  os << "[" << iter->m_timestamp << "] ";
726  }
727 
728  os << iter->m_strText << endl;
729 
730  ++index;
731  }
732 }
BookDeq m_book
the log book
Definition: LogBook.h:768
static const unsigned FlagDebug
debug
Definition: LogBook.h:103
static const unsigned FlagONum
output log entry number
Definition: LogBook.h:98
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
static const unsigned FlagOTime
output log entry time
Definition: LogBook.h:99
static const unsigned FlagOMark
output log entry bookmarks
Definition: LogBook.h:100
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
BookDeq::const_iterator BookCIter
book const iterator
Definition: LogBook.h:753
void LogBook::resize ( size_t  uMaxEntries)

Resize maximum size of log book.

If the new size is smaller, then entries may be deleted.

Parameters
uMaxEntriesMaximum number of entries in log book.

Definition at line 512 of file LogBook.cxx.

References limitSize(), and m_uMaxEntries.

Referenced by size().

513 {
514  if( uMaxEntries > 0 )
515  {
516  m_uMaxEntries = uMaxEntries;
517  limitSize();
518  }
519 }
void limitSize()
Limit size of log book to defined limit.
Definition: LogBook.cxx:789
size_t m_uMaxEntries
maximum number of log entries
Definition: LogBook.h:761
void LogBook::rprt ( std::ostream &  os,
size_t  index0,
size_t  index1 
) const
protected

Reverse print log book from index 1 to index 0, inclusive.

The output is controlled by the current formatting flag bits.

Parameters
osOutput stream.
index0Starting log book index.
index1Ending log book index.

Definition at line 734 of file LogBook.cxx.

References FlagDebug, FlagOMark, FlagONum, FlagOTime, m_book, m_uFlags, and size().

Referenced by printLog(), and printToMark().

735 {
736  BookCRIter iter, pos0, pos1;
737  size_t last;
738  size_t index;
739 
740  if( m_uFlags & FlagDebug )
741  {
742  os << "DBG: " << __func__ << "(" << index0 << ", " << index1 << ")" << endl;
743  }
744 
745  if( size() == 0 )
746  {
747  return;
748  }
749  else if( (index0 > index1) || (index1 >= size()) )
750  {
751  return;
752  }
753 
754  last = size() - 1;
755 
756  index = index1;
757 
758  pos0 = m_book.rbegin() + last - index1;
759  pos1 = m_book.rbegin() + last - index0;
760 
761  for(iter = pos0; iter != m_book.rend() && iter <= pos1; ++iter)
762  {
763  if( m_uFlags & FlagONum )
764  {
765  os << setw(3) << index << ". ";
766  }
767 
768  if( m_uFlags & FlagOTime )
769  {
770  os << "[" << iter->m_timestamp << "] ";
771  }
772 
773  os << iter->m_strText << endl;
774 
775  if( (m_uFlags & FlagOMark) && !iter->m_strMark.empty() )
776  {
777  os << " ~~ " << iter->m_strMark << endl;
778  }
779 
780  --index;
781  }
782 }
BookDeq m_book
the log book
Definition: LogBook.h:768
static const unsigned FlagDebug
debug
Definition: LogBook.h:103
BookDeq::const_reverse_iterator BookCRIter
const rev book iter
Definition: LogBook.h:755
static const unsigned FlagONum
output log entry number
Definition: LogBook.h:98
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
static const unsigned FlagOTime
output log entry time
Definition: LogBook.h:99
static const unsigned FlagOMark
output log entry bookmarks
Definition: LogBook.h:100
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
void LogBook::rsortMarks ( BookMarkList sorted) const
protected

Reverse sort bookmarks from newest to oldest.

Parameters
[out]sortedList of sorted bookmarks.

Definition at line 881 of file LogBook.cxx.

References rnr::bookmark(), clear(), FlagDebug, m_book, m_uFlags, and size().

Referenced by getBookMarks().

882 {
883  BookCRIter iter;
884  size_t index;
885  BookMark bookmark;
886 
887  sorted.clear();
888 
889  index = size() - 1;
890 
891  for(iter = m_book.rbegin(); iter != m_book.rend(); ++iter)
892  {
893  if( !iter->m_strMark.empty() )
894  {
895  bookmark.m_strMark = iter->m_strMark;
896  bookmark.m_index = index;
897 
898  if( m_uFlags & FlagDebug )
899  {
900  cerr << "DBG: mark=\"" << bookmark.m_strMark
901  << "\", index=" << bookmark.m_index << endl;
902  }
903 
904  sorted.push_back(bookmark);
905  }
906 
907  --index;
908  }
909 }
BookDeq m_book
the log book
Definition: LogBook.h:768
static const unsigned FlagDebug
debug
Definition: LogBook.h:103
BookDeq::const_reverse_iterator BookCRIter
const rev book iter
Definition: LogBook.h:755
void clear()
Clear the log book and bookmarks, along with any pending entry.
Definition: LogBook.cxx:521
size_t size() const
Return the number of logged entries in the log book.
Definition: LogBook.h:588
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
LogBook & bookmark(LogBook &log)
LogBook bookmark stream manipulator.
Definition: LogBook.cxx:932
unsigned rnr::LogBook::setFlags ( const unsigned  uFlags)
inline

Set the current formatting flags.

Parameters
uFlagsFlags to set.
Returns
New bit list of or'ed flags.

Definition at line 630 of file LogBook.h.

References m_uFlags.

Referenced by mainInit(), and rnr::operator<<().

631  {
632  m_uFlags = uFlags;
633  return m_uFlags;
634  }
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
void rnr::LogBook::setName ( const std::string &  strName)
inline

Set the name of the log book.

Parameters
strNameString.

Definition at line 568 of file LogBook.h.

References m_strName.

Referenced by mainInit().

569  {
570  m_strName = strName;
571  }
std::string m_strName
name of log
Definition: LogBook.h:760
void LogBook::setPending ( const std::string  strText,
const std::string  strMark 
)

Set the pending log text and associated bookmark.

Parameters
strTextLog entry text.
strMarkAssociated log entry bookmark label.

Definition at line 435 of file LogBook.cxx.

References setPendingBookMark(), and setPendingText().

436 {
437  setPendingText(strText);
438  setPendingBookMark(strMark);
439 }
void setPendingBookMark(const std::string strMark)
Set the pending bookmark.
Definition: LogBook.cxx:430
void setPendingText(const std::string strText)
Set the pending log text.
Definition: LogBook.cxx:423
void LogBook::setPendingBookMark ( const std::string  strMark)

Set the pending bookmark.

The pending bookmark is associated with the pending log entry. Any previous pending, unlogged bookmark will be lost.

Note
The alternative (and preferred) method to set the pending mark is to use the LogBook insertion stream operators.
Parameters
strMarkPending bookmark label.

Definition at line 430 of file LogBook.cxx.

References m_strMark.

Referenced by rnr::bookmark(), rnr::operator<<(), and setPending().

431 {
432  m_strMark = strMark;
433 }
std::string m_strMark
pending bookmark label
Definition: LogBook.h:766
void LogBook::setPendingText ( const std::string  strText)

Set the pending log text.

Any previously pending, unlogged text will be lost.

Note
The alternative method to log an entry is to use the LogBook insertion stream operators.
Parameters
strTextLog entry text.

Definition at line 423 of file LogBook.cxx.

References m_ssText, and ssflush().

Referenced by setPending().

424 {
425  ssflush();
426 
427  m_ssText << strText;
428 }
void ssflush()
Flush the pending text stream.
Definition: LogBook.cxx:797
std::stringstream m_ssText
pending text stream
Definition: LogBook.h:767
size_t rnr::LogBook::size ( ) const
inline

Return the number of logged entries in the log book.

Returns
Number of entries.

Definition at line 588 of file LogBook.h.

References m_book, and resize().

Referenced by at(), eraseEntries(), eraseToMark(), lastEntry(), logEntry(), logPending(), mainInit(), operator=(), printLog(), printToMark(), prt(), rprt(), and rsortMarks().

589  {
590  return (size_t)m_book.size();
591  }
BookDeq m_book
the log book
Definition: LogBook.h:768
void LogBook::sortMarks ( BookMarkList sorted) const
protected

Sort bookmarks from oldest to newest.

Parameters
[out]sortedList of sorted bookmarks.

Definition at line 851 of file LogBook.cxx.

References rnr::bookmark(), clear(), FlagDebug, m_book, and m_uFlags.

Referenced by getBookMarks().

852 {
853  BookCIter iter;
854  size_t index;
855  BookMark bookmark;
856 
857  sorted.clear();
858 
859  index = 0;
860 
861  for(iter = m_book.begin(); iter != m_book.end(); ++iter)
862  {
863  if( !iter->m_strMark.empty() )
864  {
865  bookmark.m_strMark = iter->m_strMark;
866  bookmark.m_index = index;
867 
868  if( m_uFlags & FlagDebug )
869  {
870  cerr << "DBG: mark=\"" << bookmark.m_strMark
871  << "\", index=" << bookmark.m_index << endl;
872  }
873 
874  sorted.push_back(bookmark);
875  }
876 
877  ++index;
878  }
879 }
BookDeq m_book
the log book
Definition: LogBook.h:768
static const unsigned FlagDebug
debug
Definition: LogBook.h:103
void clear()
Clear the log book and bookmarks, along with any pending entry.
Definition: LogBook.cxx:521
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
BookDeq::const_iterator BookCIter
book const iterator
Definition: LogBook.h:753
LogBook & bookmark(LogBook &log)
LogBook bookmark stream manipulator.
Definition: LogBook.cxx:932
void LogBook::ssflush ( )
protected

Flush the pending text stream.

The bytes go to a better place, not the log.

Definition at line 797 of file LogBook.cxx.

References m_bWarnThrottle, and m_ssText.

Referenced by erasePending(), erasePendingText(), and setPendingText().

798 {
799  m_ssText.str(string());
800  m_ssText.clear();
801  m_bWarnThrottle = false;
802 }
std::stringstream m_ssText
pending text stream
Definition: LogBook.h:767
bool m_bWarnThrottle
do [not] throttle warnings
Definition: LogBook.h:765
const std::string& rnr::LogBook::textAt ( const std::string &  strMark) const
inline

Get the entry text at the bookmark.

Parameters
strMarkBookmark label.
Returns
If the entry exists, reference to the log entry text is returned. Otherwise, an empty string is returned.

Definition at line 482 of file LogBook.h.

References at(), and rnr::LogBook::Entry::m_strText.

Referenced by mainInit().

483  {
484  return at(strMark).m_strText;
485  }
std::string m_strText
entry text, empty if no text
Definition: LogBook.h:112
const Entry & at(const std::string &strMark) const
Get the entry at the bookmark.
const std::string& rnr::LogBook::textAt ( const size_t  index) const
inline

Get the entry text at the index.

Parameters
indexLog book absolute index.
Returns
If the entry exists, reference to the log entry text is returned. Otherwise, an empty string is returned.

Definition at line 496 of file LogBook.h.

References at(), and rnr::LogBook::Entry::m_strText.

497  {
498  return at(index).m_strText;
499  }
std::string m_strText
entry text, empty if no text
Definition: LogBook.h:112
const Entry & at(const std::string &strMark) const
Get the entry at the bookmark.
const std::string& rnr::LogBook::textAt ( const size_t  index,
int  whence 
) const
inline

Get the entry text at relative index from whence.

Parameters
indexRelative log book index.
whenceWhence directive (OLDEST or NEWEST).
Returns
If the entry exists, reference to the log entry text is returned. Otherwise, an empty string is returned.

Definition at line 511 of file LogBook.h.

References at(), and rnr::LogBook::Entry::m_strText.

512  {
513  return at(index, whence).m_strText;
514  }
std::string m_strText
entry text, empty if no text
Definition: LogBook.h:112
const Entry & at(const std::string &strMark) const
Get the entry at the bookmark.

Friends And Related Function Documentation

std::ostream& operator<< ( std::ostream &  os,
const LogBook log 
)
friend

Stream insertion operator.

The entire log book is inserted. Formatting is controlled by the current flags settings.

Parameters
osOutput stream.
logLog book.
Returns
Reference to output stream.

The documentation for this class was generated from the following files: