2 changed files with 53 additions and 0 deletions
@ -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; |
||||
} |
@ -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…
Reference in new issue