Browse Source

Add browser history class

pull/2/head
Nubben 5 years ago
parent
commit
09d556abb9
  1. 33
      src/BrowsingHistory.cpp
  2. 20
      src/BrowsingHistory.h

33
src/BrowsingHistory.cpp

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
#include "BrowsingHistory.h"
BrowsingHistory::BrowsingHistory() :
history(),
currentPosition(0) {}
void BrowsingHistory::addEntry(URL url) {
if (!history.empty()) {
++currentPosition;
}
if (currentPosition < history.size()) {
history.erase(history.begin() + currentPosition, history.end());
}
history.push_back(url);
}
URL const& BrowsingHistory::goForward() {
if (currentPosition < history.size()) {
++currentPosition;
}
return history[currentPosition];
}
URL const& BrowsingHistory::goBack() {
if (currentPosition > 0) {
--currentPosition;
}
return history[currentPosition];
}
std::vector<URL> const& BrowsingHistory::getHistory() const {
return history;
}

20
src/BrowsingHistory.h

@ -0,0 +1,20 @@ @@ -0,0 +1,20 @@
#ifndef BROWSINGHISTORY_H
#define BROWSINGHISTORY_H
#include <vector>
#include "URL.h"
class BrowsingHistory {
public:
BrowsingHistory();
void addEntry(URL url);
URL const& goForward();
URL const& goBack();
std::vector<URL> const& getHistory() const;
private:
std::vector<URL> history;
unsigned int currentPosition;
};
#endif
Loading…
Cancel
Save