| 98 | using ConstantIdentifierPrivate = IdentifierPrivate<false>; |
| 99 | |
| 100 | struct IdentifierItemRequest |
| 101 | { |
| 102 | IdentifierItemRequest(const DynamicIdentifierPrivate& identifier) |
| 103 | : m_identifier(identifier) |
| 104 | { |
| 105 | identifier.hash(); //Make sure the hash is valid by calling this |
| 106 | } |
| 107 | |
| 108 | enum { |
| 109 | AverageSize = sizeof(IdentifierPrivate<false> ) + 4 |
| 110 | }; |
| 111 | |
| 112 | //Should return the hash-value associated with this request(For example the hash of a string) |
| 113 | uint hash() const |
| 114 | { |
| 115 | return m_identifier.hash(); |
| 116 | } |
| 117 | |
| 118 | //Should return the size of an item created with createItem |
| 119 | uint itemSize() const |
| 120 | { |
| 121 | return m_identifier.itemSize(); |
| 122 | } |
| 123 | //Should create an item where the information of the requested item is permanently stored. The pointer |
| 124 | //@param item equals an allocated range with the size of itemSize(). |
| 125 | void createItem(ConstantIdentifierPrivate* item) const |
| 126 | { |
| 127 | new (item) ConstantIdentifierPrivate(m_identifier); |
| 128 | } |
| 129 | |
| 130 | static bool persistent(const ConstantIdentifierPrivate* item) |
| 131 | { |
| 132 | return ( bool )item->m_refCount; |
| 133 | } |
| 134 | |
| 135 | static void destroy(ConstantIdentifierPrivate* item, AbstractItemRepository&) |
| 136 | { |
| 137 | item->~ConstantIdentifierPrivate(); |
| 138 | } |
| 139 | |
| 140 | //Should return whether the here requested item equals the given item |
| 141 | bool equals(const ConstantIdentifierPrivate* item) const |
| 142 | { |
| 143 | return item->m_hash == m_identifier.m_hash |
| 144 | && item->m_unique == m_identifier.m_unique |
| 145 | && item->m_identifier == m_identifier.m_identifier |
| 146 | && m_identifier.listsEqual(*item); |
| 147 | } |
| 148 | |
| 149 | const DynamicIdentifierPrivate& m_identifier; |
| 150 | }; |
| 151 | |
| 152 | using IdentifierRepository = ItemRepository<ConstantIdentifierPrivate, IdentifierItemRequest, true, QRecursiveMutex>; |
| 153 | using IdentifierRepositoryManager = RepositoryManager<IdentifierRepository, false>; |