Cachemere
Modular Caching Library for C++
item.h
1 #ifndef CACHEMERE_ITEM_H
2 #define CACHEMERE_ITEM_H
3 
4 #include <cstring>
5 #include <utility>
6 
7 namespace cachemere {
8 
10 template<typename Value> struct Item {
11  Item(size_t key_size, Value value, size_t value_size)
12  : m_key_size{key_size},
13  m_value{std::move(value)},
14  m_value_size{value_size},
15  m_total_size{key_size + value_size}
16  {
17  }
18  Item(Item&& other) noexcept = default;
19  Item(const Item& other) = delete;
20  Item& operator=(const Item&) = delete;
21  Item& operator=(Item&&) noexcept = default;
22 
23  size_t m_key_size;
24 
25  Value m_value;
26  size_t m_value_size;
27 
28  size_t m_total_size;
29 };
30 
31 template<typename Value> void swap(Item<Value>& a, Item<Value>& b) noexcept
32 {
33  using std::swap;
34 
35  swap(a.m_key_size, b.m_key_size);
36  swap(a.m_value, b.m_value);
37  swap(a.m_value_size, b.m_value_size);
38  swap(a.m_total_size, b.m_total_size);
39 }
40 
41 } // namespace cachemere
42 
43 #endif
cachemere::Item::m_value_size
size_t m_value_size
The size of the item.
Definition: item.h:26
cachemere::Item::m_value
Value m_value
The item stored in cache.
Definition: item.h:25
cachemere::Item
A wrapper for items stored in the cache.
Definition: item.h:10
cachemere::Item::m_key_size
size_t m_key_size
The size of the key.
Definition: item.h:23
cachemere
Root namespace.
Definition: cache.h:35
cachemere::Item::m_total_size
size_t m_total_size
The total size of the item (m_key_size + m_value_size)
Definition: item.h:28