Doxygen
Loading...
Searching...
No Matches
LinkedMap< T, Hash, KeyEqual, Map > Class Template Reference

Container class representing a vector of objects with keys. More...

#include <src/linkedmap.h>

+ Inheritance diagram for LinkedMap< T, Hash, KeyEqual, Map >:

Public Types

using Ptr = std::unique_ptr<T>
 
using Vec = std::vector<Ptr>
 
using iterator = typename Vec::iterator
 
using const_iterator = typename Vec::const_iterator
 
using reverse_iterator = typename Vec::reverse_iterator
 
using const_reverse_iterator = typename Vec::const_reverse_iterator
 

Public Member Functions

const T * find (const std::string &key) const
 Find an object given the key.
 
const T * find (const QCString &key) const
 Find an object given the key.
 
const T * find (const char *key) const
 Find an object given the key.
 
T * find (const char *key)
 A non-const wrapper for find() const.
 
T * find (const QCString &key)
 A non-const wrapper for find() const.
 
T * find (const std::string &key)
 A non-const wrapper for find() const.
 
template<class... Args>
T * add (const char *k, Args &&... args)
 Adds a new object to the ordered vector if it was not added already.
 
template<class... Args>
T * add (const QCString &k, Args &&... args)
 
T * add (const char *k, Ptr &&ptr)
 Adds an existing object to the ordered vector (unless another object was already added under the same key).
 
T * add (const QCString &k, Ptr &&ptr)
 
template<class... Args>
T * prepend (const char *k, Args &&... args)
 Prepends a new object to the ordered vector if it was not added already.
 
template<class... Args>
T * prepend (const QCString &key, Args &&... args)
 
bool del (const QCString &key)
 Removes an object from the container and deletes it.
 
Ptroperator[] (size_t pos)
 
const Ptroperator[] (size_t pos) const
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
reverse_iterator rbegin ()
 
reverse_iterator rend ()
 
const_reverse_iterator rbegin () const
 
const_reverse_iterator rend () const
 
bool empty () const
 
size_t size () const
 
void clear ()
 

Private Attributes

Map m_lookup
 
Vec m_entries
 

Detailed Description

template<class T, class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
class LinkedMap< T, Hash, KeyEqual, Map >

Container class representing a vector of objects with keys.

Objects can efficiently be looked up given the key. Objects are owned by the container. When adding objects the order of addition is kept, and used while iterating.

Definition at line 35 of file linkedmap.h.

Member Typedef Documentation

◆ const_iterator

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
using LinkedMap< T, Hash, KeyEqual, Map >::const_iterator = typename Vec::const_iterator

Definition at line 41 of file linkedmap.h.

◆ const_reverse_iterator

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
using LinkedMap< T, Hash, KeyEqual, Map >::const_reverse_iterator = typename Vec::const_reverse_iterator

Definition at line 43 of file linkedmap.h.

◆ iterator

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
using LinkedMap< T, Hash, KeyEqual, Map >::iterator = typename Vec::iterator

Definition at line 40 of file linkedmap.h.

◆ Ptr

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
using LinkedMap< T, Hash, KeyEqual, Map >::Ptr = std::unique_ptr<T>

Definition at line 38 of file linkedmap.h.

◆ reverse_iterator

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
using LinkedMap< T, Hash, KeyEqual, Map >::reverse_iterator = typename Vec::reverse_iterator

Definition at line 42 of file linkedmap.h.

◆ Vec

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
using LinkedMap< T, Hash, KeyEqual, Map >::Vec = std::vector<Ptr>

Definition at line 39 of file linkedmap.h.

Member Function Documentation

◆ add() [1/4]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
template<class... Args>
T * LinkedMap< T, Hash, KeyEqual, Map >::add ( const char * k,
Args &&... args )
inline

Adds a new object to the ordered vector if it was not added already.

Return a non-owning pointer to the newly added object, or to the existing object if it was already inserted before under the given key.

Definition at line 90 of file linkedmap.h.

91 {
92 T *result = find(k);
93 if (result==nullptr)
94 {
95 std::string key(k ? k : "");
97 result = ptr.get();
98 m_lookup.emplace(key,result);
99 m_entries.push_back(std::move(ptr));
100 }
101 return result;
102 }
Container class representing a vector of objects with keys.
Definition linkedmap.h:36
Vec m_entries
Definition linkedmap.h:221
std::unique_ptr< T > Ptr
Definition linkedmap.h:38
Map m_lookup
Definition linkedmap.h:220
const T * find(const std::string &key) const
Find an object given the key.
Definition linkedmap.h:47

References find(), m_entries, and m_lookup.

Referenced by SectionManager::add(), SectionManager::add(), addEnumValuesToEnums(), ClassDefImpl::addMembersToTemplateInstance(), addXRefItem(), DirDefImpl::createNewDir(), ClassDefImpl::deepCopy(), findEnums(), NamespaceDefImpl::insertMember(), ClassDefImpl::mergeCategory(), ClassDefImpl::mergeMembersFromBaseClasses(), readDir(), readFileOrDirectory(), and SectionManager::replace().

◆ add() [2/4]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
T * LinkedMap< T, Hash, KeyEqual, Map >::add ( const char * k,
Ptr && ptr )
inline

Adds an existing object to the ordered vector (unless another object was already added under the same key).

Ownership is transferred. Return a non-owning pointer to the newly added object, or to the existing object if it was already inserted before under the given key.

Definition at line 123 of file linkedmap.h.

124 {
125 T *result = find(k);
126 if (result==nullptr)
127 {
128 std::string key(k ? k : "");
129 result = ptr.get();
130 m_lookup.emplace(key,result);
131 m_entries.push_back(std::move(ptr));
132 }
133 return result;
134 }

References find(), m_entries, and m_lookup.

◆ add() [3/4]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
template<class... Args>
T * LinkedMap< T, Hash, KeyEqual, Map >::add ( const QCString & k,
Args &&... args )
inline

Definition at line 105 of file linkedmap.h.

106 {
107 std::string key = k.str();
108 T *result = find(key);
109 if (result==nullptr)
110 {
112 result = ptr.get();
113 m_lookup.emplace(key,result);
114 m_entries.push_back(std::move(ptr));
115 }
116 return result;
117 }

References find(), m_entries, m_lookup, and QCString::str().

◆ add() [4/4]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
T * LinkedMap< T, Hash, KeyEqual, Map >::add ( const QCString & k,
Ptr && ptr )
inline

Definition at line 136 of file linkedmap.h.

137 {
138 std::string key = k.str();
139 T *result = find(key);
140 if (result==nullptr)
141 {
142 result = ptr.get();
143 m_lookup.emplace(key,result);
144 m_entries.push_back(std::move(ptr));
145 }
146 return result;
147 }

References find(), m_entries, m_lookup, and QCString::str().

◆ begin() [1/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
iterator LinkedMap< T, Hash, KeyEqual, Map >::begin ( )
inline

Definition at line 201 of file linkedmap.h.

201{ return m_entries.begin(); }

References m_entries.

◆ begin() [2/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
const_iterator LinkedMap< T, Hash, KeyEqual, Map >::begin ( ) const
inline

Definition at line 203 of file linkedmap.h.

203{ return m_entries.cbegin(); }

References m_entries.

◆ clear()

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
void LinkedMap< T, Hash, KeyEqual, Map >::clear ( )
inline

Definition at line 212 of file linkedmap.h.

213 {
214 m_entries.clear();
215 m_lookup.clear();
216 }

References m_entries, and m_lookup.

Referenced by cleanUpDoxygen(), and clearAll().

◆ del()

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
bool LinkedMap< T, Hash, KeyEqual, Map >::del ( const QCString & key)
inline

Removes an object from the container and deletes it.

Returns true if the object was deleted or false it is was not found.

Definition at line 183 of file linkedmap.h.

184 {
185 auto it = m_lookup.find(key.str());
186 if (it!=m_lookup.end())
187 {
188 auto vecit = std::find_if(m_entries.begin(),m_entries.end(),[obj=it->second](auto &el) { return el.get()==obj; });
189 if (vecit!=m_entries.end()) // should always be true
190 {
191 m_entries.erase(vecit);
192 m_lookup.erase(it);
193 return true;
194 }
195 }
196 return false;
197 }

References m_entries, m_lookup, and QCString::str().

◆ empty()

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
bool LinkedMap< T, Hash, KeyEqual, Map >::empty ( ) const
inline

Definition at line 209 of file linkedmap.h.

209{ return m_entries.empty(); }

References m_entries.

◆ end() [1/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
iterator LinkedMap< T, Hash, KeyEqual, Map >::end ( )
inline

Definition at line 202 of file linkedmap.h.

202{ return m_entries.end(); }

References m_entries.

◆ end() [2/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
const_iterator LinkedMap< T, Hash, KeyEqual, Map >::end ( ) const
inline

Definition at line 204 of file linkedmap.h.

204{ return m_entries.cend(); }

References m_entries.

◆ find() [1/6]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
T * LinkedMap< T, Hash, KeyEqual, Map >::find ( const char * key)
inline

A non-const wrapper for find() const.

Definition at line 69 of file linkedmap.h.

70 {
71 return const_cast<T*>(static_cast<const LinkedMap&>(*this).find(key));
72 }

◆ find() [2/6]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
const T * LinkedMap< T, Hash, KeyEqual, Map >::find ( const char * key) const
inline

Find an object given the key.

Returns a pointer to the element if found or nullptr if it is not found.

Definition at line 63 of file linkedmap.h.

64 {
65 return find(std::string(key ? key : ""));
66 }

References find().

◆ find() [3/6]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
T * LinkedMap< T, Hash, KeyEqual, Map >::find ( const QCString & key)
inline

A non-const wrapper for find() const.

Definition at line 75 of file linkedmap.h.

76 {
77 return const_cast<T*>(static_cast<const LinkedMap&>(*this).find(key));
78 }

◆ find() [4/6]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
const T * LinkedMap< T, Hash, KeyEqual, Map >::find ( const QCString & key) const
inline

Find an object given the key.

Returns a pointer to the element if found or nullptr if it is not found.

Definition at line 55 of file linkedmap.h.

56 {
57 auto it = m_lookup.find(key.str());
58 return it!=m_lookup.end() ? it->second : nullptr;
59 }

References m_lookup, and QCString::str().

◆ find() [5/6]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
T * LinkedMap< T, Hash, KeyEqual, Map >::find ( const std::string & key)
inline

A non-const wrapper for find() const.

Definition at line 81 of file linkedmap.h.

82 {
83 return const_cast<T*>(static_cast<const LinkedMap&>(*this).find(key));
84 }

◆ find() [6/6]

◆ operator[]() [1/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
Ptr & LinkedMap< T, Hash, KeyEqual, Map >::operator[] ( size_t pos)
inline

Definition at line 199 of file linkedmap.h.

199{ return m_entries[pos]; }

References m_entries.

◆ operator[]() [2/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
const Ptr & LinkedMap< T, Hash, KeyEqual, Map >::operator[] ( size_t pos) const
inline

Definition at line 200 of file linkedmap.h.

200{ return m_entries[pos]; }

References m_entries.

◆ prepend() [1/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
template<class... Args>
T * LinkedMap< T, Hash, KeyEqual, Map >::prepend ( const char * k,
Args &&... args )
inline

Prepends a new object to the ordered vector if it was not added already.

Return a non-owning pointer to the newly added object, or to the existing object if it was already inserted before under the given key.

Definition at line 153 of file linkedmap.h.

154 {
155 T *result = find(k);
156 if (result==nullptr)
157 {
158 std::string key(k ? k : "");
160 result = ptr.get();
161 m_lookup.emplace(key,result);
162 m_entries.push_front(std::move(ptr));
163 }
164 return result;
165 }

References find(), m_entries, and m_lookup.

◆ prepend() [2/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
template<class... Args>
T * LinkedMap< T, Hash, KeyEqual, Map >::prepend ( const QCString & key,
Args &&... args )
inline

Definition at line 168 of file linkedmap.h.

169 {
170 T *result = find(key);
171 if (result==nullptr)
172 {
174 result = ptr.get();
175 m_lookup.emplace(key.str(),result);
176 m_entries.push_front(std::move(ptr));
177 }
178 return result;
179 }

References find(), m_entries, m_lookup, and QCString::str().

◆ rbegin() [1/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
reverse_iterator LinkedMap< T, Hash, KeyEqual, Map >::rbegin ( )
inline

Definition at line 205 of file linkedmap.h.

205{ return m_entries.rbegin(); }

References m_entries.

◆ rbegin() [2/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
const_reverse_iterator LinkedMap< T, Hash, KeyEqual, Map >::rbegin ( ) const
inline

Definition at line 207 of file linkedmap.h.

207{ return m_entries.crbegin(); }

References m_entries.

◆ rend() [1/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
reverse_iterator LinkedMap< T, Hash, KeyEqual, Map >::rend ( )
inline

Definition at line 206 of file linkedmap.h.

206{ return m_entries.rend(); }

References m_entries.

◆ rend() [2/2]

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
const_reverse_iterator LinkedMap< T, Hash, KeyEqual, Map >::rend ( ) const
inline

Definition at line 208 of file linkedmap.h.

208{ return m_entries.crend(); }

References m_entries.

◆ size()

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
size_t LinkedMap< T, Hash, KeyEqual, Map >::size ( ) const
inline

Definition at line 210 of file linkedmap.h.

210{ return m_entries.size(); }

References m_entries.

Referenced by computeClassRelations().

Member Data Documentation

◆ m_entries

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
Vec LinkedMap< T, Hash, KeyEqual, Map >::m_entries
private

◆ m_lookup

template<class T , class Hash = std::hash<std::string>, class KeyEqual = std::equal_to<std::string>, class Map = std::unordered_map<std::string,T*,Hash,KeyEqual >>
Map LinkedMap< T, Hash, KeyEqual, Map >::m_lookup
private

Definition at line 220 of file linkedmap.h.

Referenced by add(), add(), add(), add(), clear(), del(), find(), find(), prepend(), and prepend().


The documentation for this class was generated from the following file: