7#ifndef PACKET_STORAGE_H
8#define PACKET_STORAGE_H
10#include <boost/noncopyable.hpp>
11#include <boost/shared_ptr.hpp>
49 typedef typename std::list<PacketPtr> PacketContainer;
51 typedef typename PacketContainer::iterator PacketContainerIterator;
62 storage_.push_back(packet);
63 if (storage_.size() == 1) {
64 current_pointer_ = storage_.begin();
77 void clear(
const uint64_t num = 0) {
79 PacketContainerIterator last = storage_.begin();
80 std::advance(last, num >
size() ?
size() : num);
81 current_pointer_ = storage_.erase(storage_.begin(), last);
84 current_pointer_ = storage_.begin();
92 return (storage_.empty());
103 if (storage_.empty()) {
105 }
else if (current_pointer_ == storage_.end()) {
106 current_pointer_ = storage_.begin();
109 current_pointer_ = storage_.erase(current_pointer_);
126 current_pointer_ = storage_.begin();
128 std::advance(current_pointer_, rand() % (
size() - 1));
131 current_pointer_ = storage_.erase(current_pointer_);
139 return (storage_.size());
144 std::list<PacketPtr> storage_;
145 PacketContainerIterator current_pointer_;
Represents a list of packets with a sequential and random access to list elements.
void append(const PacketPtr &packet)
Appends the new packet object to the collection.
uint64_t size() const
Returns number of packets in the storage.
void clear(const uint64_t num=0)
Removes packets from the storage.
bool empty() const
Checks if the storage has no packets.
PacketPtr getNext()
Returns next packet from the storage.
boost::shared_ptr< T > PacketPtr
A type which represents the pointer to a packet.
PacketPtr getRandom()
Returns random packet from the storage.
PacketStorage()
Constructor.
Defines the logger used by the top-level component of kea-lfc.