DUDS
Distributed Update of Data from Something
PathStringGenerator.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2020 Jeff Jackowski
9  */
10 #include <boost/exception/exception.hpp>
11 #include <boost/exception/info.hpp>
12 #include <exception>
13 #include <duds/ui/Path.hpp>
14 
15 namespace duds { namespace ui {
16 
23 virtual std::exception, virtual boost::exception { };
24 
29 typedef boost::error_info<struct Info_StringLength, std::string::size_type>
31 
36 typedef boost::error_info<struct Info_PathMaxLength, unsigned int>
38 
43 typedef boost::error_info<struct Info_PathMaxTitleLength, unsigned int>
45 
50 typedef boost::error_info<struct Info_PathMinTitleLength, unsigned int>
52 
120  std::string sep;
124  std::string ellip;
128  std::string preCur;
132  std::string postCur;
136  unsigned int maxLen = -1;
140  unsigned int maxPages = -1;
145  unsigned int maxPageLen = -1;
150  unsigned int minPageLen = 4;
155  bool showFwd = true;
160  bool wholeCurrent = false;
164  bool abruptSplit = false;
190  std::string::size_type titleLength(
191  const std::string &title,
192  int &total,
193  unsigned int max
194  ) const;
200  struct TrucatedTitle {
204  const std::string *title;
208  std::string::size_type len;
209  TrucatedTitle() = default;
210  TrucatedTitle(const std::string &t) :
211  title(&t),
212  len(t.size())
213  { }
214  TrucatedTitle(const std::string &t, std::string::size_type l) :
215  title(&t),
216  len(l)
217  { }
218  };
225  void decTitleLen(const TrucatedTitle &tt, int &total) const;
235  static int averageLength(int numtitles, int totalLen, int currLen);
236 public:
240  PathStringGenerator() = default;
248  const std::string &separator,
249  unsigned int mlen = -1
250  ) : sep(separator), maxLen(mlen) { }
264  const std::string &separator,
265  const std::string &ellipsis,
266  unsigned int mlen = -1,
267  unsigned int mtitle = -1
268  );
272  const std::string &separator() const {
273  return sep;
274  }
278  void separator(const std::string &s) {
279  sep = s;
280  }
285  const std::string &ellipsis() const {
286  return ellip;
287  }
296  void ellipsis(const std::string &e);
300  const std::string &currentHeader() const {
301  return preCur;
302  }
311  void currentHeader(const std::string &h);
315  const std::string &currentFooter() const {
316  return postCur;
317  }
326  void currentFooter(const std::string &f);
330  unsigned int maxLength() const {
331  return maxLen;
332  }
340  void maxLength(unsigned int max);
345  unsigned int maxTitles() const {
346  return maxPages;
347  }
353  void maxTitles(unsigned int max) {
354  maxPages = max;
355  }
361  unsigned int maxTitleLength() const {
362  return maxPageLen;
363  }
376  void maxTitleLength(unsigned int max);
382  unsigned int minTitleLength() const {
383  return minPageLen;
384  }
395  void minTitleLength(unsigned int min);
400  bool showForwardPage() const {
401  return showFwd;
402  }
409  void showForwardPage(bool show = true) {
410  showFwd = show;
411  }
419  bool showWholeCurrentPage() const {
420  return wholeCurrent;
421  }
431  void showWholeCurrentPage(bool show = true) {
432  wholeCurrent = show;
433  }
444  std::string generate(const Path &path) const;
445 };
446 
447 } }
const std::string * title
The title string.
void showForwardPage(bool show=true)
Changes if the page in the forward direction may be included in the output path string.
unsigned int maxTitleLength() const
Returns the maximum length allocated to a page title in the output path string.
std::string preCur
Marker string that preceds the current page title.
unsigned int maxTitles() const
Returns the maximum number of page titles that may be included in the output path string...
boost::error_info< struct Info_StringLength, std::string::size_type > StringLength
Error attribute used by PathStringGenerator to denote a string length that is important in the contex...
const std::string & ellipsis() const
Returns the string appended to the end of page titles that are shortened to fit.
void showWholeCurrentPage(bool show=true)
Changes if the length of the current page title is bound by the maximum output length (true) or by th...
unsigned int maxLength() const
Returns the maximum length of the generated path strings.
const std::string & currentHeader() const
Returns the string prepended to the current page title.
PathStringGenerator(const std::string &separator, unsigned int mlen=-1)
Makes a PathStringGenerator with the given title separator and maximum path length.
std::string ellip
Last character(s) to use when part of a title is not shown.
std::string::size_type len
The length of the title.
boost::error_info< struct Info_PathMaxTitleLength, unsigned int > PathMaxTitleLength
Error attribute used by PathStringGenerator to hold the maximum length of page titles in its output...
Produces a string showing the path through pages as tracked by a Path object.
std::string postCur
Marker string that follows the current page title.
std::string sep
Separator between page titles.
bool showForwardPage() const
True if the page in the forward direction may be included in the output path string.
void maxTitles(unsigned int max)
Changes the maximum number of page titles that may be included in the output path string...
TrucatedTitle(const std::string &t, std::string::size_type l)
const std::string & currentFooter() const
Returns the string appended to the end of the current page title.
boost::error_info< struct Info_PathMaxLength, unsigned int > PathMaxLength
Error attribute used by PathStringGenerator to hold the maximum length of its string output...
Error that signifies a PathStringGenerator object was given a parameter value that conflicts with ano...
unsigned int minTitleLength() const
Returns the minimum length for a shortened page title in the output path string.
const std::string & separator() const
Returns the string used to separate the titles.
bool showWholeCurrentPage() const
True when the length of the current page title is not bound by the maximum title length (maxTitleLeng...
boost::error_info< struct Info_PathMinTitleLength, unsigned int > PathMinTitleLength
Error attribute used by PathStringGenerator to hold the minimum length of page titles in its output...
An internal data structure used to track the titles to include in the path string and the length of e...
void separator(const std::string &s)
Changes the string used to separate the titles.
Stores a list of pages the user has visited in the order of the visits.
Definition: Path.hpp:23