22 #ifndef NDN_CXX_IMS_IN_MEMORY_STORAGE_HPP
23 #define NDN_CXX_IMS_IN_MEMORY_STORAGE_HPP
30 #include <boost/multi_index_container.hpp>
31 #include <boost/multi_index/identity.hpp>
32 #include <boost/multi_index/mem_fun.hpp>
33 #include <boost/multi_index/member.hpp>
34 #include <boost/multi_index/ordered_index.hpp>
35 #include <boost/multi_index/sequenced_index.hpp>
47 using Cache = boost::multi_index_container<
49 boost::multi_index::indexed_by<
51 boost::multi_index::ordered_unique<
52 boost::multi_index::tag<byFullName>,
64 class const_iterator :
public boost::forward_iterator_helper<const_iterator, const Data>
68 Cache::index<byFullName>::type::iterator it) noexcept
87 return lhs.m_it == rhs.m_it;
93 Cache::index<byFullName>::type::iterator m_it;
99 class Error :
public std::runtime_error
103 : std::runtime_error(
"Cannot reduce the capacity of the in-memory storage!")
121 size_t limit = std::numeric_limits<size_t>::max());
160 shared_ptr<const Data>
173 shared_ptr<const Data>
188 erase(
const Name& prefix,
const bool isPrefix =
true);
271 return size() >= m_capacity;
293 freeEntry(Cache::iterator it);
312 selectChild(
const Interest& interest,
313 Cache::index<byFullName>::type::iterator startingPoint)
const;
320 Cache::index<byFullName>::type::iterator
321 findNextFresh(Cache::index<byFullName>::type::iterator startingPoint)
const;
335 size_t m_capacity = 0;
337 size_t m_nPackets = 0;
339 std::stack<InMemoryStorageEntry*> m_freeEntries;
341 unique_ptr<Scheduler> m_scheduler;
Represents a Data packet.
Represents an in-memory storage entry.
const Name & getFullName() const
Returns the full name (including implicit digest) of the Data packet stored in the in-memory storage ...
Represents an error might be thrown during reduce the current capacity of the in-memory storage throu...
Represents a const_iterator for the in-memory storage.
const_iterator(const Data *ptr, const Cache *cache, Cache::index< byFullName >::type::iterator it) noexcept
const_iterator & operator++()
reference operator*() const noexcept
friend bool operator==(const const_iterator &lhs, const const_iterator &rhs) noexcept
Represents in-memory storage.
static constexpr time::milliseconds INFINITE_WINDOW
InMemoryStorage(size_t limit=std::numeric_limits< size_t >::max())
Create a InMemoryStorage with up to limit entries.
boost::multi_index_container< InMemoryStorageEntry *, boost::multi_index::indexed_by< boost::multi_index::ordered_unique< boost::multi_index::tag< byFullName >, boost::multi_index::const_mem_fun< InMemoryStorageEntry, const Name &, &InMemoryStorageEntry::getFullName >, std::less< Name > > > > Cache
void erase(const Name &prefix, const bool isPrefix=true)
Deletes in-memory storage entry by prefix by default.
virtual void afterAccess(InMemoryStorageEntry *entry)
Update the entry when the entry is returned by the find() function according to derived class impleme...
void insert(const Data &data, const time::milliseconds &mustBeFreshProcessingWindow=INFINITE_WINDOW)
Inserts a Data packet.
InMemoryStorage::const_iterator end() const
Returns end iterator of the in-memory storage ordering by name with digest.
void printCache(std::ostream &os) const
Prints contents of the in-memory storage.
virtual void beforeErase(InMemoryStorageEntry *entry)
Update the entry or other data structures before a entry is successfully erased according to derived ...
shared_ptr< const Data > find(const Interest &interest)
Finds the best match Data for an Interest.
virtual bool evictItem()=0
Removes one Data packet from in-memory storage based on derived class implemented replacement policy.
bool isFull() const
Returns true if the in-memory storage uses up the current capacity, false otherwise.
size_t getCapacity() const
Returns current capacity of in-memory storage (in packets).
InMemoryStorage::const_iterator begin() const
Returns begin iterator of the in-memory storage ordering by name with digest.
void eraseImpl(const Name &name)
Deletes in-memory storage entries by the Name with implicit digest.
virtual void afterInsert(InMemoryStorageEntry *entry)
Update the entry or other data structures after a entry is successfully inserted according to derived...
void setCapacity(size_t nMaxPackets)
Sets current capacity of in-memory storage (in packets).
virtual ~InMemoryStorage()
Represents an Interest packet.
Represents an absolute name.
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PROTECTED
#define NDN_CXX_PUBLIC_WITH_TESTS_ELSE_PRIVATE
::boost::chrono::milliseconds milliseconds