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

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

#include <src/linkedmap.h>

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

Public Types

using 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)
 non-const wrapper for find() const
 
T * find (const QCString &key)
 
T * find (const std::string &key)
 non-const wrapper for find() const
 
bool add (const char *k, T *obj)
 Adds an object reference to the ordered vector if it was not added already.
 
bool add (const QCString &k, T *obj)
 
bool prepend (const char *k, T *obj)
 Prepends an object reference to the ordered vector if it was not added already.
 
bool prepend (const QCString &key, T *obj)
 
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 LinkedRefMap< T, Hash, KeyEqual, Map >

Container class representing a vector of objects with keys.

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

Definition at line 231 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 LinkedRefMap< T, Hash, KeyEqual, Map >::const_iterator = typename Vec::const_iterator

Definition at line 237 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 LinkedRefMap< T, Hash, KeyEqual, Map >::const_reverse_iterator = typename Vec::const_reverse_iterator

Definition at line 239 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 LinkedRefMap< T, Hash, KeyEqual, Map >::iterator = typename Vec::iterator

Definition at line 236 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 LinkedRefMap< T, Hash, KeyEqual, Map >::Ptr = T*

Definition at line 234 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 LinkedRefMap< T, Hash, KeyEqual, Map >::reverse_iterator = typename Vec::reverse_iterator

Definition at line 238 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 LinkedRefMap< T, Hash, KeyEqual, Map >::Vec = std::vector<Ptr>

Definition at line 235 of file linkedmap.h.

Member Function Documentation

◆ add() [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 >>
bool LinkedRefMap< T, Hash, KeyEqual, Map >::add ( const char * k,
T * obj )
inline

Adds an object reference to the ordered vector if it was not added already.

Return true if the reference was added, and false if an object with the same key was already added before

Definition at line 284 of file linkedmap.h.

285 {
286 if (find(k)==nullptr) // new element
287 {
288 std::string key(k ? k : "");
289 m_lookup.emplace(key,obj);
290 m_entries.push_back(obj);
291 return true;
292 }
293 else // already existing, don't add
294 {
295 return false;
296 }
297 }
Container class representing a vector of objects with keys.
Definition linkedmap.h:232
const T * find(const std::string &key) const
find an object given the key.
Definition linkedmap.h:243

References find(), m_entries, and m_lookup.

Referenced by FileDefImpl::insertClass(), and NamespaceDefImpl::insertClass().

◆ add() [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 >>
bool LinkedRefMap< T, Hash, KeyEqual, Map >::add ( const QCString & k,
T * obj )
inline

Definition at line 299 of file linkedmap.h.

300 {
301 std::string key = k.str();
302 if (find(key)==nullptr) // new element
303 {
304 m_lookup.emplace(key,obj);
305 m_entries.push_back(obj);
306 return true;
307 }
308 else // already existing, don't add
309 {
310 return false;
311 }
312 }

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 LinkedRefMap< T, Hash, KeyEqual, Map >::begin ( )
inline

Definition at line 366 of file linkedmap.h.

366{ 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 LinkedRefMap< T, Hash, KeyEqual, Map >::begin ( ) const
inline

Definition at line 368 of file linkedmap.h.

368{ 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 LinkedRefMap< T, Hash, KeyEqual, Map >::clear ( )
inline

Definition at line 377 of file linkedmap.h.

378 {
379 m_entries.clear();
380 m_lookup.clear();
381 }

References m_entries, and m_lookup.

◆ 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 LinkedRefMap< 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 348 of file linkedmap.h.

349 {
350 auto it = m_lookup.find(key.str());
351 if (it!=m_lookup.end())
352 {
353 auto vecit = std::find_if(m_entries.begin(),m_entries.end(),[obj=it->second](auto &el) { return el.get()==obj; });
354 if (vecit!=m_entries.end()) // should always be true
355 {
356 m_entries.erase(vecit);
357 m_lookup.erase(it);
358 return true;
359 }
360 }
361 return false;
362 }

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 LinkedRefMap< T, Hash, KeyEqual, Map >::empty ( ) const
inline

◆ 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 LinkedRefMap< T, Hash, KeyEqual, Map >::end ( )
inline

Definition at line 367 of file linkedmap.h.

367{ 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 LinkedRefMap< T, Hash, KeyEqual, Map >::end ( ) const
inline

Definition at line 369 of file linkedmap.h.

369{ 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 * LinkedRefMap< T, Hash, KeyEqual, Map >::find ( const char * key)
inline

non-const wrapper for find() const

Definition at line 265 of file linkedmap.h.

266 {
267 return const_cast<T*>(static_cast<const LinkedRefMap&>(*this).find(key));
268 }

References find().

◆ 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 * LinkedRefMap< T, Hash, KeyEqual, Map >::find ( const char * key) const
inline

find an object given the key.

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

Definition at line 259 of file linkedmap.h.

260 {
261 return find(std::string(key ? key : ""));
262 }

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 * LinkedRefMap< T, Hash, KeyEqual, Map >::find ( const QCString & key)
inline

Definition at line 270 of file linkedmap.h.

271 {
272 return const_cast<T*>(static_cast<const LinkedRefMap&>(*this).find(key));
273 }

References find().

◆ 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 * LinkedRefMap< T, Hash, KeyEqual, Map >::find ( const QCString & key) const
inline

find an object given the key.

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

Definition at line 251 of file linkedmap.h.

252 {
253 auto it = m_lookup.find(key.str());
254 return it!=m_lookup.end() ? it->second : nullptr;
255 }

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 * LinkedRefMap< T, Hash, KeyEqual, Map >::find ( const std::string & key)
inline

non-const wrapper for find() const

Definition at line 276 of file linkedmap.h.

277 {
278 return const_cast<T*>(static_cast<const LinkedRefMap&>(*this).find(key));
279 }

References find().

◆ find() [6/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 * LinkedRefMap< T, Hash, KeyEqual, Map >::find ( const std::string & key) const
inline

find an object given the key.

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

Definition at line 243 of file linkedmap.h.

244 {
245 auto it = m_lookup.find(key);
246 return it!=m_lookup.end() ? it->second : nullptr;
247 }

References m_lookup.

Referenced by add(), add(), find(), find(), find(), find(), findGlobalMember(), prepend(), and prepend().

◆ 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 & LinkedRefMap< T, Hash, KeyEqual, Map >::operator[] ( size_t pos)
inline

Definition at line 364 of file linkedmap.h.

364{ 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 & LinkedRefMap< T, Hash, KeyEqual, Map >::operator[] ( size_t pos) const
inline

Definition at line 365 of file linkedmap.h.

365{ 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 >>
bool LinkedRefMap< T, Hash, KeyEqual, Map >::prepend ( const char * k,
T * obj )
inline

Prepends an object reference to the ordered vector if it was not added already.

Return true if the reference was added, and false if an object with the same key was already added before

Definition at line 317 of file linkedmap.h.

318 {
319 if (find(k)==nullptr) // new element
320 {
321 std::string key(k ? k : "");
322 m_lookup.emplace(key,obj);
323 m_entries.insert(m_entries.begin(),obj);
324 return true;
325 }
326 else // already existing, don't add
327 {
328 return false;
329 }
330 }

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 >>
bool LinkedRefMap< T, Hash, KeyEqual, Map >::prepend ( const QCString & key,
T * obj )
inline

Definition at line 332 of file linkedmap.h.

333 {
334 if (find(key)==nullptr) // new element
335 {
336 m_lookup.emplace(key.str(),obj);
337 m_entries.insert(m_entries.begin(),obj);
338 return true;
339 }
340 else // already existing, don't add
341 {
342 return false;
343 }
344 }

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 LinkedRefMap< T, Hash, KeyEqual, Map >::rbegin ( )
inline

Definition at line 370 of file linkedmap.h.

370{ 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 LinkedRefMap< T, Hash, KeyEqual, Map >::rbegin ( ) const
inline

Definition at line 372 of file linkedmap.h.

372{ 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 LinkedRefMap< T, Hash, KeyEqual, Map >::rend ( )
inline

Definition at line 371 of file linkedmap.h.

371{ 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 LinkedRefMap< T, Hash, KeyEqual, Map >::rend ( ) const
inline

Definition at line 373 of file linkedmap.h.

373{ 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 LinkedRefMap< T, Hash, KeyEqual, Map >::size ( ) const
inline

Definition at line 375 of file linkedmap.h.

375{ return m_entries.size(); }

References m_entries.

Referenced by writeGroupTreeNode().

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 LinkedRefMap< 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 LinkedRefMap< T, Hash, KeyEqual, Map >::m_lookup
private

Definition at line 384 of file linkedmap.h.

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


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