RecentEntries: Extract range_around().

This commit is contained in:
Jared Boone 2016-09-03 17:09:03 -07:00
parent 42d98c3b45
commit b596d0697c

View File

@ -41,7 +41,6 @@ public:
using ContainerType = std::list<EntryType>;
using const_reference = typename ContainerType::const_reference;
using const_iterator = typename ContainerType::const_iterator;
using RangeType = std::pair<const_iterator, const_iterator>;
EntryType& on_packet(const Key key) {
auto matching_recent = find(key);
@ -80,9 +79,23 @@ public:
return entries.empty();
}
RangeType range_around(
const_iterator item, const size_t count
) const {
private:
ContainerType entries;
const size_t entries_max = 64;
void truncate_entries() {
while(entries.size() > entries_max) {
entries.pop_back();
}
}
};
template<typename ContainerType>
static std::pair<typename ContainerType::const_iterator, typename ContainerType::const_iterator> range_around(
const ContainerType& entries,
typename ContainerType::const_iterator item,
const size_t count
) {
auto start = item;
auto end = item;
size_t i = 0;
@ -102,17 +115,6 @@ public:
return { start, end };
}
private:
ContainerType entries;
const size_t entries_max = 64;
void truncate_entries() {
while(entries.size() > entries_max) {
entries.pop_back();
}
}
};
namespace ui {
using RecentEntriesColumn = std::pair<std::string, size_t>;
@ -162,7 +164,7 @@ public:
selected = std::begin(recent);
}
auto range = recent.range_around(selected, visible_item_count);
auto range = range_around(recent, selected, visible_item_count);
for(auto p = range.first; p != range.second; p++) {
const auto& entry = *p;