DUDS
Distributed Update of Data from Something
Path.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) 2019 Jeff Jackowski
9  */
10 #ifndef PATH_HPP
11 #define PATH_HPP
12 
13 #include <duds/ui/Page.hpp>
14 #include <vector>
15 
16 namespace duds { namespace ui {
17 
23 class Path {
24 public:
28  typedef std::vector<PageSptr> PageStack;
29 private:
33  PageStack pages;
37  int spot;
38 public:
42  Path() : spot(-1) { };
47  Path(const PageSptr &first);
54  void push(const PageSptr &page);
62  void push(PageSptr &&page);
72  bool move(int steps);
79  bool back() {
80  return move(-1);
81  }
88  bool forward() {
89  return move(1);
90  }
96  bool atStart() const {
97  return spot == 0;
98  }
104  bool atEnd() const {
105  return !pages.empty() && (spot == pages.size() - 1);
106  }
110  void clear();
115  void clearPastCurrent();
119  bool empty() const {
120  return pages.empty();
121  }
125  PageStack::size_type size() const {
126  return pages.size();
127  }
133  const PageSptr &currentPage() const {
134  return pages.at(spot);
135  }
139  PageStack::const_iterator begin() const {
140  return pages.cbegin();
141  }
145  PageStack::const_reverse_iterator rbegin() const {
146  return pages.crbegin();
147  }
151  PageStack::const_iterator end() const {
152  return pages.cend();
153  }
157  PageStack::const_reverse_iterator rend() const {
158  return pages.crend();
159  }
164  PageStack::const_iterator current() const {
165  return pages.cbegin() + spot;
166  }
171  PageStack::const_reverse_iterator rcurrent() const {
172  return pages.crend() - spot - 1;
173  }
174 };
175 
176 } }
177 
178 #endif // #ifndef PATH_HPP
bool move(int steps)
Changes the current page by the given amount.
Definition: Path.cpp:47
PageStack::const_reverse_iterator rend() const
Reverse iterator to the start of the page stack.
Definition: Path.hpp:157
bool atEnd() const
True if the current page is the end of the page sequence.
Definition: Path.hpp:104
bool atStart() const
True if the current page is the start of the page sequence.
Definition: Path.hpp:96
PageStack::const_reverse_iterator rcurrent() const
Reverse iterator to the current page.
Definition: Path.hpp:171
bool forward()
Changes the current page to the page that was pushed after the current page.
Definition: Path.hpp:88
PageStack::const_iterator begin() const
Iterator to the start of the page stack.
Definition: Path.hpp:139
void push(const PageSptr &page)
Pushes a new page after the current page.
Definition: Path.cpp:19
PageStack::size_type size() const
Returns the number of pages in the page stack.
Definition: Path.hpp:125
bool back()
Changes the current page to the page that was pushed before the current page.
Definition: Path.hpp:79
bool empty() const
Returns true if the page stack is empty.
Definition: Path.hpp:119
const PageSptr & currentPage() const
Returns the current page.
Definition: Path.hpp:133
void clear()
Clears out the stack of all pages.
Definition: Path.cpp:65
PageStack::const_iterator end() const
Iterator to the end of the page stack.
Definition: Path.hpp:151
void clearPastCurrent()
Clears all pages on the stack that are forward of the current page.
Definition: Path.cpp:70
Path()
Constructs a new empty path.
Definition: Path.hpp:42
std::vector< PageSptr > PageStack
The type used to store the page path.
Definition: Path.hpp:28
PageStack::const_iterator current() const
Iterator to the current page.
Definition: Path.hpp:164
PageStack::const_reverse_iterator rbegin() const
Reverse iterator to the end of the page stack.
Definition: Path.hpp:145
std::shared_ptr< Page > PageSptr
A shared pointer to a Page.
Definition: Page.hpp:58
PageStack pages
The pages in path order.
Definition: Path.hpp:33
int spot
Index of the current page.
Definition: Path.hpp:37
Stores a list of pages the user has visited in the order of the visits.
Definition: Path.hpp:23