Doxygen
Loading...
Searching...
No Matches
SymbolMap< T > Class Template Reference

Class implementing a symbol map that maps symbol names to objects. More...

#include <src/symbolmap.h>

+ Inheritance diagram for SymbolMap< T >:

Public Types

using Ptr = T *
 
using VectorPtr = std::vector<Ptr>
 
using Map = std::unordered_map<std::string,VectorPtr>
 
using iterator = typename Map::iterator
 
using const_iterator = typename Map::const_iterator
 

Public Member Functions

void add (const QCString &name, Ptr def)
 Add a symbol def into the map under key name.
 
void remove (const QCString &name, Ptr def)
 Remove a symbol def from the map that was stored under key name.
 
const VectorPtrfind (const QCString &name)
 Find the list of symbols stored under key name Returns a pair of iterators pointing to the start and end of the range of matching symbols.
 
iterator begin ()
 
iterator end ()
 
const_iterator begin () const
 
const_iterator end () const
 
bool empty () const
 

Private Attributes

Map m_map
 
VectorPtr m_noMatch
 

Detailed Description

template<class T>
class SymbolMap< T >

Class implementing a symbol map that maps symbol names to objects.

Symbol names do not have to be unique. Supports adding symbols with add(), removing symbols with remove(), and finding symbols with find().

Definition at line 31 of file symbolmap.h.

Member Typedef Documentation

◆ const_iterator

template<class T>
using SymbolMap< T >::const_iterator = typename Map::const_iterator

Definition at line 38 of file symbolmap.h.

◆ iterator

template<class T>
using SymbolMap< T >::iterator = typename Map::iterator

Definition at line 37 of file symbolmap.h.

◆ Map

template<class T>
using SymbolMap< T >::Map = std::unordered_map<std::string,VectorPtr>

Definition at line 36 of file symbolmap.h.

◆ Ptr

template<class T>
using SymbolMap< T >::Ptr = T *

Definition at line 34 of file symbolmap.h.

◆ VectorPtr

template<class T>
using SymbolMap< T >::VectorPtr = std::vector<Ptr>

Definition at line 35 of file symbolmap.h.

Member Function Documentation

◆ add()

template<class T>
void SymbolMap< T >::add ( const QCString & name,
Ptr def )
inline

Add a symbol def into the map under key name.

Definition at line 41 of file symbolmap.h.

42 {
43 auto it = m_map.find(name.str());
44 if (it!=m_map.end())
45 {
46 it->second.push_back(def);
47 }
48 else
49 {
50 m_map.emplace(name.str(),VectorPtr({def}));
51 }
52 }
Class implementing a symbol map that maps symbol names to objects.
Definition symbolmap.h:32
std::vector< Ptr > VectorPtr
Definition symbolmap.h:35
Map m_map
Definition symbolmap.h:89

References m_map, and QCString::str().

◆ begin() [1/2]

template<class T>
iterator SymbolMap< T >::begin ( )
inline

Definition at line 82 of file symbolmap.h.

82{ return m_map.begin(); }

References m_map.

◆ begin() [2/2]

template<class T>
const_iterator SymbolMap< T >::begin ( ) const
inline

Definition at line 84 of file symbolmap.h.

84{ return m_map.cbegin(); }

References m_map.

◆ empty()

template<class T>
bool SymbolMap< T >::empty ( ) const
inline

Definition at line 86 of file symbolmap.h.

86{ return m_map.empty(); }

References m_map.

◆ end() [1/2]

template<class T>
iterator SymbolMap< T >::end ( )
inline

Definition at line 83 of file symbolmap.h.

83{ return m_map.end(); }

References m_map.

◆ end() [2/2]

template<class T>
const_iterator SymbolMap< T >::end ( ) const
inline

Definition at line 85 of file symbolmap.h.

85{ return m_map.cend(); }

References m_map.

◆ find()

template<class T>
const VectorPtr & SymbolMap< T >::find ( const QCString & name)
inline

Find the list of symbols stored under key name Returns a pair of iterators pointing to the start and end of the range of matching symbols.

Definition at line 75 of file symbolmap.h.

76 {
77 assert(m_noMatch.empty());
78 auto it = m_map.find(name.str());
79 return it==m_map.end() ? m_noMatch : it->second;
80 }
VectorPtr m_noMatch
Definition symbolmap.h:90

References m_map, m_noMatch, and QCString::str().

◆ remove()

template<class T>
void SymbolMap< T >::remove ( const QCString & name,
Ptr def )
inline

Remove a symbol def from the map that was stored under key name.

Definition at line 55 of file symbolmap.h.

56 {
57 auto it1 = m_map.find(name.str());
58 if (it1!=m_map.end())
59 {
60 VectorPtr &v = it1->second;
61 auto it2 = std::find(v.begin(),v.end(),def);
62 if (it2!=v.end())
63 {
64 v.erase(it2);
65 if (v.empty())
66 {
67 m_map.erase(it1);
68 }
69 }
70 }
71 }
iterator end()
Definition symbolmap.h:83
iterator begin()
Definition symbolmap.h:82
bool empty() const
Definition symbolmap.h:86

References m_map, and QCString::str().

Member Data Documentation

◆ m_map

template<class T>
Map SymbolMap< T >::m_map
private

Definition at line 89 of file symbolmap.h.

Referenced by add(), begin(), begin(), empty(), end(), end(), find(), and remove().

◆ m_noMatch

template<class T>
VectorPtr SymbolMap< T >::m_noMatch
private

Definition at line 90 of file symbolmap.h.

Referenced by find().


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