浏览该文件的文档.
19 #include <unordered_map>
32 template<
class T,
class Hash = std::hash<std::
string>,
33 class KeyEqual = std::equal_to<std::
string>,
34 class Map = std::unordered_map<std::
string,T*,Hash,KeyEqual > >
38 using Ptr = std::unique_ptr<T>;
39 using Vec = std::vector<Ptr>;
40 using iterator =
typename Vec::iterator;
47 const T *
find(
const std::string &key)
const
50 return it!=
m_lookup.end() ? it->second :
nullptr;
58 return it!=
m_lookup.end() ? it->second :
nullptr;
63 const T *
find(
const char *key)
const
65 return find(std::string(key ? key :
""));
69 T*
find(
const char *key)
71 return const_cast<T*
>(
static_cast<const LinkedMap&
>(*this).
find(key));
77 return const_cast<T*
>(
static_cast<const LinkedMap&
>(*this).
find(key));
81 T*
find(
const std::string &key)
83 return const_cast<T*
>(
static_cast<const LinkedMap&
>(*this).
find(key));
89 template<
class...Args>
90 T *
add(
const char *k, Args&&... args)
95 std::string key(k ? k :
"");
96 Ptr ptr = std::make_unique<T>(
QCString(k),std::forward<Args>(args)...);
104 template<
class...Args>
107 std::string key = k.
str();
108 T *result =
find(key);
111 Ptr ptr = std::make_unique<T>(k,std::forward<Args>(args)...);
123 T *
add(
const char *k,
Ptr &&ptr)
128 std::string key(k ? k :
"");
138 std::string key = k.
str();
139 T *result =
find(key);
152 template<
class...Args>
153 T *
prepend(
const char *k, Args&&... args)
158 std::string key(k ? k :
"");
159 Ptr ptr = std::make_unique<T>(key.c_str(),std::forward<Args>(args)...);
167 template<
class...Args>
170 T *result =
find(key);
173 Ptr ptr = std::make_unique<T>(key,std::forward<Args>(args)...);
188 auto vecit = std::find_if(
m_entries.begin(),
m_entries.end(),[obj=it->second](
auto &el) { return el.get()==obj; });
228 template<
class T,
class Hash = std::hash<std::
string>,
229 class KeyEqual = std::equal_to<std::
string>,
230 class Map = std::unordered_map<std::
string,T*,Hash,KeyEqual > >
235 using Vec = std::vector<Ptr>;
243 const T *
find(
const std::string &key)
const
246 return it!=
m_lookup.end() ? it->second :
nullptr;
254 return it!=
m_lookup.end() ? it->second :
nullptr;
259 const T *
find(
const char *key)
const
261 return find(std::string(key ? key :
""));
276 T*
find(
const std::string &key)
284 bool add(
const char *k, T* obj)
286 if (
find(k)==
nullptr)
288 std::string key(k ? k :
"");
301 std::string key = k.
str();
302 if (
find(key)==
nullptr)
319 if (
find(k)==
nullptr)
321 std::string key(k ? k :
"");
334 if (
find(key)==
nullptr)
353 auto vecit = std::find_if(
m_entries.begin(),
m_entries.end(),[obj=it->second](
auto &el) { return el.get()==obj; });
bool add(const char *k, T *obj)
Adds an object reference to the ordered vector if it was not added already.
Container class representing a vector of objects with keys.
const T * find(const QCString &key) const
find an object given the key.
Ptr & operator[](size_t pos)
T * find(const QCString &key)
typename Vec::const_iterator const_iterator
typename Vec::const_reverse_iterator const_reverse_iterator
T * add(const char *k, Ptr &&ptr)
Adds an existing object to the ordered vector (unless another object was already added under the same...
bool add(const QCString &k, T *obj)
bool del(const QCString &key)
Removes an object from the container and deletes it.
T * add(const char *k, Args &&... args)
Adds a new object to the ordered vector if it was not added already.
reverse_iterator rbegin()
bool del(const QCString &key)
Removes an object from the container and deletes it.
typename Vec::reverse_iterator reverse_iterator
Ptr & operator[](size_t pos)
const T * find(const char *key) const
find an object given the key.
bool prepend(const char *k, T *obj)
Prepends an object reference to the ordered vector if it was not added already.
T * find(const std::string &key)
non-const wrapper for find() const
typename Vec::const_reverse_iterator const_reverse_iterator
typename Vec::iterator iterator
const Ptr & operator[](size_t pos) const
const_iterator end() const
const_iterator begin() const
reverse_iterator rbegin()
const T * find(const std::string &key) const
Find an object given the key.
T * prepend(const char *k, Args &&... args)
Prepends a new object to the ordered vector if it was not added already.
const_reverse_iterator rbegin() const
bool prepend(const QCString &key, T *obj)
Container class representing a vector of objects with keys.
T * find(const char *key)
non-const wrapper for find() const
typename Vec::const_iterator const_iterator
const_reverse_iterator rend() const
const T * find(const std::string &key) const
find an object given the key.
typename Vec::iterator iterator
typename Vec::reverse_iterator reverse_iterator
This is an alternative implementation of QCString.