Doxygen
symbolmap.h
浏览该文件的文档.
1 /******************************************************************************
2  *
3  * Copyright (C) 1997-2020 by Dimitri van Heesch.
4  *
5  * Permission to use, copy, modify, and distribute this software and its
6  * documentation under the terms of the GNU General Public License is hereby
7  * granted. No representations are made about the suitability of this software
8  * for any purpose. It is provided "as is" without express or implied warranty.
9  * See the GNU General Public License for more details.
10  *
11  * Documents produced by Doxygen are derivative works derived from the
12  * input used in their production; they are not affected by this license.
13  *
14  */
15 
16 #ifndef SYMBOLMAP_H
17 #define SYMBOLMAP_H
18 
19 #include <algorithm>
20 #include <map>
21 #include <vector>
22 #include <string>
23 #include <utility>
24 
25 //! Class implementing a symbol map that maps symbol names to objects.
26 //! Symbol names do not have to be unique.
27 //! Supports adding symbols with add(), removing symbols with remove(), and
28 //! finding symbols with find().
29 template<class T>
30 class SymbolMap
31 {
32  public:
33  using Ptr = T *;
34  using Map = std::multimap<std::string,Ptr>;
35  using iterator = typename Map::iterator;
36  using const_iterator = typename Map::const_iterator;
37 
38  //! Add a symbol \a def into the map under key \a name
39  void add(const QCString &name,Ptr def)
40  {
41  m_map.insert({name.str(),def});
42  }
43 
44  //! Remove a symbol \a def from the map that was stored under key \a name
45  void remove(const QCString &name,Ptr def)
46  {
47  auto range = find(name.str());
48  for (auto it=range.first; it!=range.second; )
49  {
50  if (it->second==def) it = m_map.erase(it); else ++it;
51  }
52  }
53 
54  //! Find the list of symbols stored under key \a name
55  //! Returns a pair of iterators pointing to the start and end of the range of matching symbols
56  std::pair<const_iterator,const_iterator> find(const QCString &name) const
57  {
58  return m_map.equal_range(name.str());
59  }
60 
61  //! Find the list of symbols stored under key \a name
62  //! Returns a pair of iterators pointing to the start and end of the range of matching symbols
63  std::pair<iterator,iterator> find(const QCString &name)
64  {
65  return m_map.equal_range(name.str());
66  }
67 
68  iterator begin() { return m_map.begin(); }
69  iterator end() { return m_map.end(); }
70  const_iterator begin() const { return m_map.cbegin(); }
71  const_iterator end() const { return m_map.cend(); }
72  bool empty() const { return m_map.empty(); }
73  size_t size() const { return m_map.size(); }
74 
75  private:
77 };
78 
79 #endif
QCString::str
std::string str() const
Definition: qcstring.h:442
SymbolMap::iterator
typename Map::iterator iterator
Definition: symbolmap.h:48
SymbolMap::end
iterator end()
Definition: symbolmap.h:82
SymbolMap::find
std::pair< const_iterator, const_iterator > find(const QCString &name) const
Find the list of symbols stored under key name Returns a pair of iterators pointing to the start and ...
Definition: symbolmap.h:69
SymbolMap::const_iterator
typename Map::const_iterator const_iterator
Definition: symbolmap.h:49
SymbolMap::begin
iterator begin()
Definition: symbolmap.h:81
SymbolMap::add
void add(const QCString &name, Ptr def)
Add a symbol def into the map under key name
Definition: symbolmap.h:52
SymbolMap::Ptr
T * Ptr
Definition: symbolmap.h:46
SymbolMap::remove
void remove(const QCString &name, Ptr def)
Remove a symbol def from the map that was stored under key name
Definition: symbolmap.h:58
SymbolMap::m_map
Map m_map
Definition: symbolmap.h:89
SymbolMap::size
size_t size() const
Definition: symbolmap.h:86
SymbolMap::empty
bool empty() const
Definition: symbolmap.h:85
SymbolMap
Class implementing a symbol map that maps symbol names to objects.
Definition: symbolmap.h:30
SymbolMap::Map
std::multimap< std::string, Ptr > Map
Definition: symbolmap.h:47
QCString
This is an alternative implementation of QCString.
Definition: qcstring.h:108