19#include <unordered_map>
32template<
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>;
47 const T *
find(
const std::string &key)
const
50 return it!=
m_lookup.end() ? it->second :
nullptr;
55 const T *
find(
const QCString &key)
const
58 return it!=
m_lookup.end() ? it->second :
nullptr;
63 const T *
find(
const char *key)
const
65 return find(std::string(key ? key :
""));
71 return const_cast<T*
>(
static_cast<const LinkedMap&
>(*this).find(key));
75 T*
find(
const QCString &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 [[maybe_unused]] 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>
105 [[maybe_unused]] T *
add(
const QCString &k, Args&&... 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 [[maybe_unused]] T *
add(
const char *k,
Ptr &&ptr)
128 std::string key(k ? k :
"");
136 [[maybe_unused]] T *
add(
const QCString &k,
Ptr &&ptr)
138 std::string key = k.
str();
139 T *result =
find(key);
152 template<
class...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>
168 T *
prepend(
const QCString &key, Args&&... args)
170 T *result =
find(key);
173 Ptr ptr = std::make_unique<T>(key,std::forward<Args>(args)...);
183 bool del(
const QCString &key)
188 auto vecit = std::find_if(
m_entries.begin(),
m_entries.end(),[obj=it->second](
auto &el) { return el.get()==obj; });
228template<
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;
251 const T *
find(
const QCString &key)
const
254 return it!=
m_lookup.end() ? it->second :
nullptr;
259 const T *
find(
const char *key)
const
261 return find(std::string(key ? key :
""));
267 return const_cast<T*
>(
static_cast<const LinkedRefMap&
>(*this).find(key));
272 return const_cast<T*
>(
static_cast<const LinkedRefMap&
>(*this).find(key));
276 T*
find(
const std::string &key)
278 return const_cast<T*
>(
static_cast<const LinkedRefMap&
>(*this).find(key));
284 bool add(
const char *k, T* obj)
286 if (
find(k)==
nullptr)
288 std::string key(k ? k :
"");
299 bool add(
const QCString &k, T* obj)
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)
348 bool del(
const QCString &key)
353 auto vecit = std::find_if(
m_entries.begin(),
m_entries.end(),[obj=it->second](
auto &el) { return el.get()==obj; });
Container class representing a vector of objects with keys.
T * prepend(const QCString &key, Args &&... args)
T * find(const std::string &key)
A non-const wrapper for find() const.
T * add(const QCString &k, Args &&... args)
typename Vec::reverse_iterator reverse_iterator
const Ptr & operator[](size_t pos) const
bool del(const QCString &key)
Removes an object from the container and deletes it.
T * find(const char *key)
A non-const wrapper for find() const.
typename Vec::const_iterator const_iterator
T * find(const QCString &key)
A non-const wrapper for find() const.
typename Vec::iterator iterator
const_iterator begin() const
const T * find(const QCString &key) const
Find an object given the key.
const_reverse_iterator rend() const
T * add(const QCString &k, Ptr &&ptr)
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
reverse_iterator rbegin()
T * add(const char *k, Args &&... args)
Adds a new object to the ordered vector if it was not added already.
const T * find(const std::string &key) const
Find an object given the key.
T * add(const char *k, Ptr &&ptr)
Adds an existing object to the ordered vector (unless another object was already added under the same...
typename Vec::const_reverse_iterator const_reverse_iterator
Ptr & operator[](size_t pos)
const_iterator end() const
const T * find(const char *key) const
Find an object given the key.
Container class representing a vector of objects with keys.
const Ptr & operator[](size_t pos) const
T * find(const char *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.
const_reverse_iterator rbegin() const
T * find(const QCString &key)
const T * find(const QCString &key) const
find an object given the key.
typename Vec::const_reverse_iterator const_reverse_iterator
bool del(const QCString &key)
Removes an object from the container and deletes it.
T * find(const std::string &key)
non-const wrapper for find() const
const_iterator end() const
const_iterator begin() const
typename Vec::reverse_iterator reverse_iterator
bool prepend(const char *k, T *obj)
Prepends an object reference to the ordered vector if it was not added already.
Ptr & operator[](size_t pos)
bool prepend(const QCString &key, T *obj)
const T * find(const std::string &key) const
find an object given the key.
const_reverse_iterator rend() const
reverse_iterator rbegin()
bool add(const QCString &k, T *obj)
typename Vec::const_iterator const_iterator
const T * find(const char *key) const
find an object given the key.
typename Vec::iterator iterator
const std::string & str() const