appkit  1.5.1
RoadNarrows Robotics Application Kit
LogBook.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // Package: RoadNarrows Robotics Application Tool Kit
4 //
5 // Link: https://github.com/roadnarrows-robotics/rnr-sdk
6 //
7 // Library: librnr_appkit
8 //
9 // File: LogBook.h
10 //
11 /*! \file
12  *
13  * \brief LogBook class interface.
14  *
15  * \author Robin Knight (robin.knight@roadnarrows.com)
16  *
17  * \par Copyright
18  * \h_copy 2017-2017. RoadNarrows LLC.\n
19  * http://www.roadnarrows.com\n
20  * All Rights Reserved
21  *
22  * \par License
23  * MIT
24  *
25  * @EulaBegin@
26  * Permission is hereby granted, without written agreement and without
27  * license or royalty fees, to use, copy, modify, and distribute this
28  * software and its documentation for any purpose, provided that
29  * (1) The above copyright notice and the following two paragraphs
30  * appear in all copies of the source code and (2) redistributions
31  * including binaries reproduces these notices in the supporting
32  * documentation. Substantial modifications to this software may be
33  * copyrighted by their authors and need not follow the licensing terms
34  * described here, provided that the new terms are clearly indicated in
35  * all files where they apply.
36  * \n\n
37  * IN NO EVENT SHALL THE AUTHOR, ROADNARROWS LLC, OR ANY MEMBERS/EMPLOYEES
38  * OF ROADNARROW LLC OR DISTRIBUTORS OF THIS SOFTWARE BE LIABLE TO ANY
39  * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
40  * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
41  * EVEN IF THE AUTHORS OR ANY OF THE ABOVE PARTIES HAVE BEEN ADVISED OF
42  * THE POSSIBILITY OF SUCH DAMAGE.
43  * \n\n
44  * THE AUTHOR AND ROADNARROWS LLC SPECIFICALLY DISCLAIM ANY WARRANTIES,
45  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
46  * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
47  * "AS IS" BASIS, AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO
48  * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
49  * @EulaEnd@
50  */
51 ////////////////////////////////////////////////////////////////////////////////
52 
53 #ifndef _RNR_LOG_BOOK_H
54 #define _RNR_LOG_BOOK_H
55 
56 #include <sys/types.h>
57 #include <sys/time.h>
58 #include <unistd.h>
59 #include <stdlib.h>
60 #include <stdio.h>
61 #include <time.h>
62 
63 #include <iostream>
64 #include <iomanip>
65 #include <sstream>
66 #include <string>
67 #include <deque>
68 #include <map>
69 #include <vector>
70 
71 #include "rnr/rnrconfig.h"
72 #include "rnr/log.h"
73 
74 /*!
75  * \brief RoadNarrows Robotics
76  */
77 namespace rnr
78 {
79  class LogBook
80  {
81  public:
82  //
83  // Defaults
84  //
85  static const size_t MaxEntriesDft = 100; ///< max num entries default
86  static const size_t MaxEntryLenDft = 0x2000; ///< max entry length (8192)
87 
88  //
89  // Whence it came
90  //
91  static const int OLDEST = 0; ///< oldest entries
92  static const int NEWEST = 1; ///< newest, most recent entries
93 
94  //
95  // Formatting+ flags
96  //
97  static const unsigned FlagNone = 0x0000; ///< no flags
98  static const unsigned FlagONum = 0x0001; ///< output log entry number
99  static const unsigned FlagOTime = 0x0002; ///< output log entry time
100  static const unsigned FlagOMark = 0x0004; ///< output log entry bookmarks
101  static const unsigned FlagOAllF = 0x0007; ///< output all entry fields
102  static const unsigned FlagORev = 0x0008; ///< output log reverse order
103  static const unsigned FlagDebug = 0x1000; ///< debug
104 
105  /*!
106  * \brief Log entry structure.
107  */
108  struct Entry
109  {
110  timespec m_timestamp; ///< entry timestamp
111  std::string m_strMark; ///< entry bookmark, empty if no mark
112  std::string m_strText; ///< entry text, empty if no text
113 
114  /*!
115  * \brief Default contructor.
116  */
117  Entry();
118 
119  /*!
120  * \brief Initialization contructor.
121  *
122  * \param strMark Entry bookmark.
123  * \param strText Entry text.
124  */
125  Entry(const std::string &strMark, const std::string &strText);
126 
127  /*!
128  * \brief Copy contructor.
129  *
130  * \param src Source object.
131  */
132  Entry(const Entry &src);
133 
134  /*!
135  * \brief Destructor.
136  */
137  virtual ~Entry();
138 
139  /*!
140  * \brief Assignment operator.
141  *
142  * \param rhs Right-hand side object.
143  *
144  * \return *this
145  */
146  Entry &operator=(const Entry &rhs);
147 
148  /*!
149  * \brief Test if entry is empty ("no entry" entry).
150  *
151  * \return Returns true or false.
152  */
153  bool empty();
154  };
155 
156  //
157  // Some useful Entry types
158  //
159  typedef std::vector<Entry> EntryList; ///< entry list type
160  typedef EntryList::iterator EntryListIter; ///< entry list iterator
161  typedef EntryList::const_iterator EntryListCIter;
162  ///< entry const list iterator
163 
164  /*!
165  * \brief Log bookmark structure.
166  */
167  struct BookMark
168  {
169  std::string m_strMark;
170  size_t m_index;
171 
172  /*!
173  * \brief Default contructor.
174  */
175  BookMark();
176 
177  /*!
178  * \brief Copy contructor.
179  *
180  * \param src Source object.
181  */
182  BookMark(const BookMark &src);
183 
184  /*!
185  * \brief Assignment operator.
186  *
187  * \param rhs Right-hand side object.
188  *
189  * \return *this
190  */
191  BookMark &operator=(const BookMark &rhs);
192  };
193 
194  //
195  // Some useful BookMark types
196  //
197  typedef std::vector<BookMark> BookMarkList; ///< bookmark list type
198  typedef BookMarkList::iterator BookMarkListIter;
199  ///< bookmark list iterator
200  typedef BookMarkList::const_iterator BookMarkListCIter;
201  ///< bookmark const list iter
202 
203  /*!
204  * \brief Convenience macro to bookmark log using function name.
205  */
206 #define BOOKMARKFUNC() bookmark(__func__)
207 
208  /*!
209  * \brief Default initialization constructor.
210  *
211  * \param strName Name of log book.
212  * \param uMaxEntries Maximum number of entries in log book.
213  * \param uMaxEntryLen Maximum entry length.
214  */
215  LogBook(const std::string strName = "Log Book",
216  size_t uMaxEntries = MaxEntriesDft,
217  size_t uMaxEntryLen = MaxEntryLenDft);
218 
219 
220  /*!
221  * \brief Copy constructor.
222  *
223  * \param src Source object.
224  */
225  LogBook(const LogBook &src);
226 
227  /*!
228  * \brief Destructor.
229  */
230  virtual ~LogBook();
231 
232  /*!
233  * \brief Assignment operator.
234  *
235  * \param rhs Right-hand side object.
236  *
237  * \return *this
238  */
239  LogBook &operator=(const LogBook &rhs);
240 
241  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
242  // LogBook Insertion Operators
243  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
244 
245  //
246  // Arithmetic
247  //
248  LogBook &operator<<(bool val);
249  LogBook &operator<<(char val);
250  LogBook &operator<<(int val);
251  LogBook &operator<<(unsigned int val);
252  LogBook &operator<<(long val);
253  LogBook &operator<<(unsigned long val);
254  LogBook &operator<<(long long val);
255  LogBook &operator<<(unsigned long long val);
256  LogBook &operator<<(float val);
257  LogBook &operator<<(double val);
258  LogBook &operator<<(long double val);
259 
260  //
261  // Pointers
262  //
263  LogBook &operator<<(const char *val);
264  LogBook &operator<<(void *val);
265 
266  //
267  // Speical classes
268  //
269  LogBook &operator<<(const std::string &val);
270  LogBook &operator<<(const LogBook &log); // append
271 
272  //
273  // LogBook special stream manipulators
274  //
275  LogBook &operator<<(LogBook& (*pf)(LogBook&));
276 
277  //
278  // LogBook standard ostream manipulators
279  //
280  LogBook &operator<<(std::ostream& (*pf)(std::ostream&));
281  LogBook &operator<<(std::ios& (*pf)(std::ios&));
282  LogBook &operator<<(std::ios_base& (*pf)(std::ios_base&));
283 
284  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
285  // LogBook Editing, Access, and Utilities
286  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
287 
288  /*!
289  * \brief Log the given entry into the log book.
290  *
291  * Any pending log entry remains untouched.
292  *
293  * \note The alternative method to log an entry is to use the LogBook
294  * insertion stream operators.
295  *
296  * \param strText Log entry text.
297  * \param strMark Associated log entry bookmark. If empty (""), then no
298  * bookmark added.
299  *
300  * \return Returns the new number of entries in the log book.
301  */
302  size_t logEntry(const std::string strText, const std::string strMark = "");
303 
304  /*!
305  * \brief Log any pending entry into the log book.
306  *
307  * The pending entry and associated bookmark are recorded into log. The
308  * pending data are then erased.
309  *
310  * \note The alternative method to log an entry is to use the LogBook
311  * insertion stream operators.
312  *
313  * \return Returns the new number of entries in the log book.
314  */
315  size_t logPending();
316 
317  /*!
318  * \brief Set the pending log text.
319  *
320  * Any previously pending, unlogged text will be lost.
321  *
322  * \note The alternative method to log an entry is to use the LogBook
323  * insertion stream operators.
324  *
325  * \param strText Log entry text.
326  */
327  void setPendingText(const std::string strText);
328 
329  /*!
330  * \brief Set the pending bookmark.
331  *
332  * The pending bookmark is associated with the pending log entry. Any
333  * previous pending, unlogged bookmark will be lost.
334  *
335  * \note The alternative (and preferred) method to set the pending mark is
336  * to use the LogBook insertion stream operators.
337  *
338  * \param strMark Pending bookmark label.
339  */
340  void setPendingBookMark(const std::string strMark);
341 
342  /*!
343  * \brief Set the pending log text and associated bookmark.
344  *
345  * \param strText Log entry text.
346  * \param strMark Associated log entry bookmark label.
347  */
348  void setPending(const std::string strText, const std::string strMark);
349 
350  /*!
351  * \brief Erase the pending log text.
352  */
353  void erasePendingText();
354 
355  /*!
356  * \brief Erase the pending log bookmark.
357  */
358  void erasePendingBookMark();
359 
360  /*!
361  * \brief Erase the pending log text and associated bookmark.
362  */
363  void erasePending();
364 
365  /*!
366  * \brief Erases all entries from the log book up to the bookmark.
367  *
368  * If whence is OLDEST, then the entries erased are from the oldest entries
369  * up to, but not including, the first encounter of the bookmarked entry.
370  *
371  * If whence is NEWEST, then the entries erased are from the most recent
372  * logged entry up to and including the first encounter of the bookmarked
373  * entry.
374  *
375  * If the bookmark is not found, then no entries are erased.
376  *
377  * \param strMark Bookmark search label.
378  * \param whence Whence directive (OLDEST or NEWEST).
379  *
380  * \return Returns the new number of entries in the log book.
381  */
382  size_t eraseToMark(const std::string strMark, int whence);
383 
384  /*!
385  * \brief Erases a given number of entries from the log book.
386  *
387  * If whence is OLDEST, then the entries are erased starting from the
388  * oldest entry.
389  *
390  * If whence is NEWEST, then the entries are erased starting from the
391  * most recent entry.
392  *
393  * \param uNumEntries Number of entries to delete. If >= number of
394  * entries, then the book is erased.
395  * \param whence Whence directive (OLDEST or NEWEST).
396  *
397  * \return Returns the new number of entries in the log book.
398  */
399  size_t eraseEntries(size_t uNumEntries, int whence);
400 
401  /*!
402  * \brief Clear the log book and bookmarks, along with any pending entry.
403  */
404  void clear();
405 
406  /*!
407  * \brief Get the entry at the bookmark.
408  *
409  * \param strMark Bookmark label.
410  *
411  * \return
412  * If the entry exists, reference to log entry is returned.
413  * Otherwise, a "no entry" entry is returned (test with Entry::empty()).
414  */
415  const Entry &at(const std::string &strMark) const;
416 
417  /*!
418  * \brief Get the entry at the index.
419  *
420  * \param index Log book absolute index.
421  *
422  * \return
423  * If the entry exists, reference to log entry is returned.
424  * Otherwise, a "no entry" entry is returned (test with Entry::empty()).
425  */
426  const Entry &at(const size_t index) const;
427 
428  /*!
429  * \brief Get the entry at relative index from whence.
430  *
431  * \param index Relative log book index.
432  * \param whence Whence directive (OLDEST or NEWEST).
433  *
434  * \return
435  * If the entry exists, reference to log entry is returned.
436  * Otherwise, a "no entry" entry is returned (test with Entry::empty()).
437  */
438  const Entry &at(const size_t index, int whence) const;
439 
440  /*!
441  * \brief Log book array index operator.
442  *
443  * Get the entry at the index.
444  *
445  * \param index Log book absolute index.
446  *
447  * \return
448  * If the entry exists, reference to log entry is returned.
449  * Otherwise, a "no entry" entry is returned (test with Entry::empty()).
450  */
451  const Entry &operator[](const size_t index) const;
452 
453  /*!
454  * \brief Log book array mark operator.
455  *
456  * \param strMark Bookmark label.
457  *
458  * \return
459  * If the entry exists, reference to log entry is returned.
460  * Otherwise, a "no entry" entry is returned (test with Entry::empty()).
461  */
462  const Entry &operator[](const std::string &strMark) const;
463 
464  /*!
465  * \brief Get the last (latest) log entry.
466  *
467  * \return
468  * If the entry exists, reference to the last log entry is returned.
469  * Otherwise, a "no entry" entry is returned (test with Entry::empty()).
470  */
471  const Entry &lastEntry() const;
472 
473  /*!
474  * \brief Get the entry text at the bookmark.
475  *
476  * \param strMark Bookmark label.
477  *
478  * \return
479  * If the entry exists, reference to the log entry text is returned.
480  * Otherwise, an empty string is returned.
481  */
482  const std::string &textAt(const std::string &strMark) const
483  {
484  return at(strMark).m_strText;
485  }
486 
487  /*!
488  * \brief Get the entry text at the index.
489  *
490  * \param index Log book absolute index.
491  *
492  * \return
493  * If the entry exists, reference to the log entry text is returned.
494  * Otherwise, an empty string is returned.
495  */
496  const std::string &textAt(const size_t index) const
497  {
498  return at(index).m_strText;
499  }
500 
501  /*!
502  * \brief Get the entry text at relative index from whence.
503  *
504  * \param index Relative log book index.
505  * \param whence Whence directive (OLDEST or NEWEST).
506  *
507  * \return
508  * If the entry exists, reference to the log entry text is returned.
509  * Otherwise, an empty string is returned.
510  */
511  const std::string &textAt(const size_t index, int whence) const
512  {
513  return at(index, whence).m_strText;
514  }
515 
516  /*!
517  * \brief Get the last (latest) log entry text.
518  *
519  * \return
520  * If the entry exists, reference to the last log entry is returned.
521  * Otherwise, a "no entry" entry is returned (test with Entry::empty()).
522  */
523  const std::string &lastText() const
524  {
525  return lastEntry().m_strText;
526  }
527 
528  /*!
529  * \brief Get a sorted list of bookmark labels.
530  *
531  * If whence is OLDEST, then sort from oldest to newest.
532  * If whence is NEWEST, then sort from most recent to oldest.
533  *
534  * \param [out] list List of sorted bookmark labels.
535  * \param whence Whence directive (OLDEST or NEWEST).
536  *
537  * \return Number of bookmarks in list.
538  */
539  size_t getBookMarks(BookMarkList &list, int whence) const;
540 
541  /*!
542  * \brief Test if bookmark exists in log book.
543  *
544  * \param strMark Bookmark label.
545  *
546  * \return Returns true or false.
547  */
548  bool hasBookMark(const std::string &strMark) const
549  {
550  return findMark(strMark) != m_book.end();
551  }
552 
553  /*!
554  * \brief Get the name of the log book.
555  *
556  * \return String.
557  */
558  const std::string &getName() const
559  {
560  return m_strName;
561  }
562 
563  /*!
564  * \brief Set the name of the log book.
565  *
566  * \param strName String.
567  */
568  void setName(const std::string &strName)
569  {
570  m_strName = strName;
571  }
572 
573  /*!
574  * \brief Return the maximum number entries the log book can hold.
575  *
576  * \return Size.
577  */
578  const size_t max_size() const
579  {
580  return m_uMaxEntries;
581  }
582 
583  /*!
584  * \brief Return the number of logged entries in the log book.
585  *
586  * \return Number of entries.
587  */
588  size_t size() const
589  {
590  return (size_t)m_book.size();
591  }
592 
593  /*!
594  * \brief Resize maximum size of log book.
595  *
596  * If the new size is smaller, then entries may be deleted.
597  *
598  * \param uMaxEntries Maximum number of entries in log book.
599  */
600  void resize(size_t uMaxEntries);
601 
602  /*!
603  * \brief Return the total number of entries ever added during log book's
604  * life.
605  *
606  * \return Total number.
607  */
608  size_t numOfTotalEver() const
609  {
610  return m_uTotalEver;
611  }
612 
613  /*!
614  * \brief Get the current formatting flags.
615  *
616  * \return Bit list of or'ed flags.
617  */
618  unsigned getFlags() const
619  {
620  return m_uFlags;
621  }
622 
623  /*!
624  * \brief Set the current formatting flags.
625  *
626  * \param uFlags Flags to set.
627  *
628  * \return New bit list of or'ed flags.
629  */
630  unsigned setFlags(const unsigned uFlags)
631  {
632  m_uFlags = uFlags;
633  return m_uFlags;
634  }
635 
636  /*!
637  * \brief Or new flags into the current formatting flags.
638  *
639  * \param uFlags Flags to or into bit list of flags.
640  *
641  * \return New bit list of or'ed flags.
642  */
643  unsigned orFlags(const unsigned uFlags)
644  {
645  m_uFlags |= uFlags;
646  return m_uFlags;
647  }
648 
649  /*!
650  * \brief Apply one's Complement and And into the current formatting flags.
651  *
652  * \param uFlags Flags to unset.
653  *
654  * \return New bit list of or'ed flags.
655  */
656  unsigned compAndFlags(const unsigned uFlags)
657  {
658  m_uFlags &= ~uFlags;
659  return m_uFlags;
660  }
661 
662  /*!
663  * \brief Clear alll current formatting flags.
664  */
665  void clearFlags()
666  {
667  m_uFlags = FlagNone;
668  }
669 
670  /*!
671  * \brief Generate a unique bookmark label.
672  *
673  * \return Label string.
674  */
675  std::string makeBookMarkLabel();
676 
677 
678  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
679  // LogBook Output Stream Operators
680  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
681 
682  /*!
683  * \brief Print the entire log book to the output stream.
684  *
685  * The output is controlled by the current formatting flag bits.
686  *
687  * \verbatim
688  * LogBook
689  * entry_0 | ^ <-- oldest end point
690  * entry_1 | |
691  * ... | |
692  * entry_n-1 v | <-- newest end point
693  * \ \
694  * \ \
695  * \ reverse order
696  * \
697  * forward order
698  * \endverbatim
699  *
700  * \param os Output stream.
701  *
702  * \return Reference to output stream.
703  */
704  std::ostream &printLog(std::ostream &os) const;
705 
706  /*!
707  * \brief Print the log book entires between the bookmark and the specified
708  * end point to the output stream.
709  *
710  * The output is controlled by the current formatting flag bits.
711  *
712  * If the opposite end point to the mark is the oldest entry, then the
713  * bookmark entry is excluded. Otherwise it is included.
714  *
715  * \verbatim
716  * LogBook
717  * entry_0 | ^ <-- oldest end point
718  * entry_1 | |
719  * ... | |
720  * entry_k-1 v | <-- sans mark end point
721  *
722  * entry_k | ^ <-- mark end point
723  * entry_k+1 | |
724  * ... | |
725  * entry_n-1 v | <-- newest end point
726  * \ \
727  * \ \
728  * \ reverse order
729  * \
730  * forward order
731  * \endverbatim
732  *
733  * \param os Output stream.
734  * \param strMark Bookmark search label.
735  * \param endpt Opposite end point to mark (OLDEST or NEWEST).
736  *
737  * \return Reference to output stream.
738  */
739  std::ostream &printToMark(std::ostream &os,
740  const std::string strMark,
741  int endpt) const;
742 
743  //std::ostream &printEntriesEarlierThan(std::ostream &os, int t);
744 
745  friend std::ostream &operator<<(std::ostream &os, const LogBook &log);
746 
747  protected:
748  //
749  // Convenience Types
750  //
751  typedef std::deque<Entry> BookDeq; ///< book type
752  typedef BookDeq::iterator BookIter; ///< book iterator
753  typedef BookDeq::const_iterator BookCIter; ///< book const iterator
754  typedef BookDeq::reverse_iterator BookRIter; ///< reverse book iter
755  typedef BookDeq::const_reverse_iterator BookCRIter; ///< const rev book iter
756 
757  //
758  // Data
759  //
760  std::string m_strName; ///< name of log
761  size_t m_uMaxEntries; ///< maximum number of log entries
762  size_t m_uMaxEntryLen; ///< maximum entry length
763  size_t m_uTotalEver; ///< total entries added during lifetime
764  unsigned m_uFlags; ///< formatting flags
765  bool m_bWarnThrottle; ///< do [not] throttle warnings
766  std::string m_strMark; ///< pending bookmark label
767  std::stringstream m_ssText; ///< pending text stream
768  BookDeq m_book; ///< the log book
769 
770  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
771  // Support
772  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
773 
774  /*!
775  * \brief Limit size of log book to defined limit.
776  */
777  void limitSize();
778 
779  /*!
780  * \brief Flush the pending text stream.
781  *
782  * The bytes go to a better place, not the log.
783  */
784  void ssflush();
785 
786  /*!
787  * \brief Check the length of the pending entry.
788  *
789  * \param uEstLen Estimated length of the new object text to be added.
790  *
791  * \return Returns true if pending entry within bounds, false otherwise.
792  */
793  bool checkLen(size_t uEstLen = 1);
794 
795  /*!
796  * \brief Find position it log book of the bookmarked entry.
797  *
798  * The search starts at the oldest entry.
799  *
800  * \param strMark Bookmark search label.
801  *
802  * \return
803  * If the bookmark entry is found, the position is returned.
804  * Otherwise, book end() is returned.
805  */
806  BookIter findMark(const std::string &strMark);
807 
808  /*!
809  * \brief Find position it log book of the bookmarked entry.
810  *
811  * Constant version.
812  *
813  * The search starts at the oldest entry.
814  *
815  * \param strMark Bookmark search label.
816  *
817  * \return
818  * If the bookmark entry is found, the position is returned.
819  * Otherwise, book end() is returned.
820  */
821  BookCIter findMark(const std::string &strMark) const;
822 
823  /*!
824  * \brief Sort bookmarks from oldest to newest.
825  *
826  * \param [out] sorted List of sorted bookmarks.
827  */
828  void sortMarks(BookMarkList &sorted) const;
829 
830  /*!
831  * \brief Reverse sort bookmarks from newest to oldest.
832  *
833  * \param [out] sorted List of sorted bookmarks.
834  */
835  void rsortMarks(BookMarkList &sorted) const;
836 
837  /*!
838  * \brief Copy log book verbatim to this log book.
839  *
840  * \param src Source log book.
841  */
842  void copy(const LogBook &src);
843 
844  /*!
845  * \brief Print log book from index 0 to index 1, inclusive.
846  *
847  * The output is controlled by the current formatting flag bits.
848  *
849  * \param os Output stream.
850  * \param index0 Starting log book index.
851  * \param index1 Ending log book index.
852  */
853  void prt(std::ostream &os, size_t index0, size_t index1) const;
854 
855  /*!
856  * \brief Reverse print log book from index 1 to index 0, inclusive.
857  *
858  * The output is controlled by the current formatting flag bits.
859  *
860  * \param os Output stream.
861  * \param index0 Starting log book index.
862  * \param index1 Ending log book index.
863  */
864  void rprt(std::ostream &os, size_t index0, size_t index1) const;
865 
866  }; // class LogBook
867 
868 
869  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
870  // Output Stream Manipulators
871  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
872 
873  /*!
874  * \brief Stream insertion operator.
875  *
876  * The entire log book is inserted. Formatting is controlled by the current
877  * flags settings.
878  *
879  * \param os Output stream.
880  * \param log Log book.
881  *
882  * \return Reference to output stream.
883  */
884  extern std::ostream &operator<<(std::ostream &os, const LogBook &log);
885 
886 
887  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
888  // LogBook Stream Manipulators
889  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
890 
891  /*!
892  * \brief LogBook end-of-entry stream manipulator.
893  *
894  * The pending entry is copied into the log and then flushed of data, ready
895  * to begin recording new entry.
896  *
897  * ~~~~~~{.cxx}
898  * LogBook log;
899  *
900  * log << eoe;
901  * log << 5 << " was my happiest age." << eoe;
902  * ~~~~~~
903  *
904  * \param log LogBook reference.
905  *
906  * \return Returns reference to LogBook.
907  */
908  extern LogBook &eoe(LogBook &log);
909 
910  /*!
911  * \brief LogBook bookmark stream manipulator.
912  *
913  * Bookmark the pending entry. The bookmark string is auto-generated.
914  * The bookmark follows the the pending entry as it is logged and aged.
915  *
916  * ~~~~~~{.cxx}
917  * LogBook log;
918  *
919  * log << bookmark;
920  * log << "black birds are cawing" << eoe;
921  * log << bookmark << " remember this to never forget." << eoe;
922  * ~~~~~~
923  *
924  * \param log LogBook reference.
925  *
926  * \return Returns reference to LogBook.
927  */
928  extern LogBook &bookmark(LogBook &log);
929 
930  /*!
931  * \brief LogBook parametric bookmark stream manipulator structure.
932  */
933  struct lbmanip_bm_
934  {
935  std::string m_strMark; ///< bookmark label
936  };
937 
938  /*!
939  * \brief LogBook bookmark parametric manipulator function.
940  *
941  * \param str Bookmark label.
942  *
943  * \return Parametric structure.
944  */
945  extern lbmanip_bm_ bookmark(const std::string str);
946 
947  /*!
948  * \brief LogBook bookmark parametric manipulator stream operators.
949  *
950  * Bookmark the pending entry. The bookmark follows the the pending entry as
951  * it is logged and aged.
952  *
953  * ~~~~~~{.cxx}
954  * LogBook log;
955  *
956  * log << bookmark("GTO") << "Muscle cars of yore." << eoe;
957  * ~~~~~~
958  *
959  * \param log LogBook reference.
960  * \param f Bookmark parametric type.
961  *
962  * \return Returns reference to LogBook.
963  */
964  extern LogBook &operator<<(LogBook &log, lbmanip_bm_ f);
965 
966  /*!
967  * \brief LogBook parametric formatting flags manipulator structure.
968  */
969  struct lbmanip_fg_
970  {
971  unsigned m_uFlags;
972  };
973 
974  /*!
975  * \brief LogBook formatting flags parametric manipulator function.
976  *
977  * \param str Bookmark label.
978  *
979  * \return Parametric structure.
980  */
981  extern lbmanip_fg_ setflags(const unsigned flags);
982 
983  /*!
984  * \brief LogBook formatting flags parametric manipulator stream operators.
985  *
986  * Modify formatting behavior with flags.
987  *
988  * ~~~~~~{.cxx}
989  * LogBook log;
990  *
991  * // log data
992  *
993  * unsigned flags = LogBook::FlagONum | LogBook::FlagOMark;
994  *
995  * log << setflags(flags);
996  * std::cout << log;
997  * ~~~~~~
998  *
999  * \param log LogBook reference.
1000  * \param f Flags parametric type.
1001  *
1002  * \return Returns reference to LogBook.
1003  */
1004  extern LogBook &operator<<(LogBook &log, lbmanip_fg_ f);
1005 
1006 } // namespace rnr
1007 
1008 #endif // _RNR_LOG_BOOK_H
unsigned setFlags(const unsigned uFlags)
Set the current formatting flags.
Definition: LogBook.h:630
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...
Definition: LogBook.cxx:646
static const size_t MaxEntryLenDft
max entry length (8192)
Definition: LogBook.h:86
void clearFlags()
Clear alll current formatting flags.
Definition: LogBook.h:665
std::string makeBookMarkLabel()
Generate a unique bookmark label.
Definition: LogBook.cxx:612
size_t eraseEntries(size_t uNumEntries, int whence)
Erases a given number of entries from the log book.
Definition: LogBook.cxx:483
BookDeq m_book
the log book
Definition: LogBook.h:768
std::ostream & printLog(std::ostream &os) const
Print the entire log book to the output stream.
Definition: LogBook.cxx:630
void erasePending()
Erase the pending log text and associated bookmark.
Definition: LogBook.cxx:451
size_t eraseToMark(const std::string strMark, int whence)
Erases all entries from the log book up to the bookmark.
Definition: LogBook.cxx:457
std::deque< Entry > BookDeq
book type
Definition: LogBook.h:751
unsigned compAndFlags(const unsigned uFlags)
Apply one&#39;s Complement and And into the current formatting flags.
Definition: LogBook.h:656
void ssflush()
Flush the pending text stream.
Definition: LogBook.cxx:797
bool checkLen(size_t uEstLen=1)
Check the length of the pending entry.
Definition: LogBook.cxx:804
static const unsigned FlagDebug
debug
Definition: LogBook.h:103
lbmanip_fg_ setflags(const unsigned flags)
LogBook formatting flags parametric manipulator function.
Definition: LogBook.cxx:952
BookDeq::const_reverse_iterator BookCRIter
const rev book iter
Definition: LogBook.h:755
void limitSize()
Limit size of log book to defined limit.
Definition: LogBook.cxx:789
const std::string & textAt(const size_t index, int whence) const
Get the entry text at relative index from whence.
Definition: LogBook.h:511
void clear()
Clear the log book and bookmarks, along with any pending entry.
Definition: LogBook.cxx:521
size_t m_uMaxEntries
maximum number of log entries
Definition: LogBook.h:761
static const unsigned FlagOAllF
output all entry fields
Definition: LogBook.h:101
void setName(const std::string &strName)
Set the name of the log book.
Definition: LogBook.h:568
BookDeq::iterator BookIter
book iterator
Definition: LogBook.h:752
static const unsigned FlagONum
output log entry number
Definition: LogBook.h:98
Log entry structure.
Definition: LogBook.h:108
std::string m_strText
entry text, empty if no text
Definition: LogBook.h:112
size_t getBookMarks(BookMarkList &list, int whence) const
Get a sorted list of bookmark labels.
Definition: LogBook.cxx:594
LogBook(const std::string strName="Log Book", size_t uMaxEntries=MaxEntriesDft, size_t uMaxEntryLen=MaxEntryLenDft)
Default initialization constructor.
Definition: LogBook.cxx:148
size_t numOfTotalEver() const
Return the total number of entries ever added during log book&#39;s life.
Definition: LogBook.h:608
std::string m_strMark
bookmark label
Definition: LogBook.h:935
const Entry & lastEntry() const
Get the last (latest) log entry.
Definition: LogBook.cxx:581
Log bookmark structure.
Definition: LogBook.h:167
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
BookDeq::reverse_iterator BookRIter
reverse book iter
Definition: LogBook.h:754
std::string m_strMark
entry bookmark, empty if no mark
Definition: LogBook.h:111
const Entry & at(const std::string &strMark) const
Get the entry at the bookmark.
unsigned orFlags(const unsigned uFlags)
Or new flags into the current formatting flags.
Definition: LogBook.h:643
BookMarkList::const_iterator BookMarkListCIter
bookmark const list iter
Definition: LogBook.h:200
const std::string & textAt(const size_t index) const
Get the entry text at the index.
Definition: LogBook.h:496
static const size_t MaxEntriesDft
max num entries default
Definition: LogBook.h:85
void setPendingBookMark(const std::string strMark)
Set the pending bookmark.
Definition: LogBook.cxx:430
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
const std::string & getName() const
Get the name of the log book.
Definition: LogBook.h:558
void rsortMarks(BookMarkList &sorted) const
Reverse sort bookmarks from newest to oldest.
Definition: LogBook.cxx:881
static const unsigned FlagORev
output log reverse order
Definition: LogBook.h:102
void erasePendingBookMark()
Erase the pending log bookmark.
Definition: LogBook.cxx:446
void setPending(const std::string strText, const std::string strMark)
Set the pending log text and associated bookmark.
Definition: LogBook.cxx:435
const Entry & operator[](const size_t index) const
Log book array index operator.
Definition: LogBook.cxx:571
static const unsigned FlagOMark
output log entry bookmarks
Definition: LogBook.h:100
LogBook & eoe(LogBook &log)
LogBook end-of-entry stream manipulator.
Definition: LogBook.cxx:926
BookMarkList::iterator BookMarkListIter
bookmark list iterator
Definition: LogBook.h:198
unsigned getFlags() const
Get the current formatting flags.
Definition: LogBook.h:618
BookIter findMark(const std::string &strMark)
Find position it log book of the bookmarked entry.
std::stringstream m_ssText
pending text stream
Definition: LogBook.h:767
const size_t max_size() const
Return the maximum number entries the log book can hold.
Definition: LogBook.h:578
unsigned m_uFlags
formatting flags
Definition: LogBook.h:764
BookDeq::const_iterator BookCIter
book const iterator
Definition: LogBook.h:753
LogBook parametric formatting flags manipulator structure.
Definition: LogBook.h:969
void copy(const LogBook &src)
Copy log book verbatim to this log book.
Definition: LogBook.cxx:911
LogBook & bookmark(LogBook &log)
LogBook bookmark stream manipulator.
Definition: LogBook.cxx:932
LogBook parametric bookmark stream manipulator structure.
Definition: LogBook.h:933
static const int NEWEST
newest, most recent entries
Definition: LogBook.h:92
void erasePendingText()
Erase the pending log text.
Definition: LogBook.cxx:441
bool empty()
Test if entry is empty ("no entry" entry).
Definition: LogBook.cxx:117
size_t logPending()
Log any pending entry into the log book.
Definition: LogBook.cxx:392
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
virtual ~LogBook()
Destructor.
Definition: LogBook.cxx:166
std::vector< BookMark > BookMarkList
bookmark list type
Definition: LogBook.h:197
std::string m_strMark
pending bookmark label
Definition: LogBook.h:766
timespec m_timestamp
entry timestamp
Definition: LogBook.h:110
Entry & operator=(const Entry &rhs)
Assignment operator.
Definition: LogBook.cxx:106
Entry()
Default contructor.
Definition: LogBook.cxx:89
bool hasBookMark(const std::string &strMark) const
Test if bookmark exists in log book.
Definition: LogBook.h:548
size_t logEntry(const std::string strText, const std::string strMark="")
Log the given entry into the log book.
Definition: LogBook.cxx:370
EntryList::const_iterator EntryListCIter
entry const list iterator
Definition: LogBook.h:161
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
const std::string & textAt(const std::string &strMark) const
Get the entry text at the bookmark.
Definition: LogBook.h:482
bool m_bWarnThrottle
do [not] throttle warnings
Definition: LogBook.h:765
virtual ~Entry()
Destructor.
Definition: LogBook.cxx:113
std::vector< Entry > EntryList
entry list type
Definition: LogBook.h:159
std::string m_strName
name of log
Definition: LogBook.h:760
const std::string & lastText() const
Get the last (latest) log entry text.
Definition: LogBook.h:523
static const unsigned FlagNone
no flags
Definition: LogBook.h:97
void setPendingText(const std::string strText)
Set the pending log text.
Definition: LogBook.cxx:423
size_t m_uTotalEver
total entries added during lifetime
Definition: LogBook.h:763
void resize(size_t uMaxEntries)
Resize maximum size of log book.
Definition: LogBook.cxx:512
RoadNarrows Robotics.
Definition: Camera.h:74
EntryList::iterator EntryListIter
entry list iterator
Definition: LogBook.h:160
size_t m_uMaxEntryLen
maximum entry length
Definition: LogBook.h:762