mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
ENH: added HashPtrTable remove(const Key&) method
- already had remove() by iterator, but not by key. As per erase() which already worked by iterator or by key.
This commit is contained in:
@ -86,6 +86,14 @@ Foam::autoPtr<T> Foam::HashPtrTable<T, Key, Hash>::remove(iterator& iter)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
template<class T, class Key, class Hash>
|
||||||
|
Foam::autoPtr<T> Foam::HashPtrTable<T, Key, Hash>::remove(const Key& key)
|
||||||
|
{
|
||||||
|
auto iter = this->find(key);
|
||||||
|
return this->remove(iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
template<class T, class Key, class Hash>
|
template<class T, class Key, class Hash>
|
||||||
bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
|
bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -123,17 +123,28 @@ public:
|
|||||||
|
|
||||||
// Edit
|
// Edit
|
||||||
|
|
||||||
//- Remove and return the pointer specified by given iterator.
|
//- Remove entry specified by given iterator.
|
||||||
// Includes a safeguard against the end-iterator.
|
// Includes a safeguard against the end-iterator.
|
||||||
|
//
|
||||||
|
// \return entry as an encapsulated pointer.
|
||||||
autoPtr<T> remove(iterator& iter);
|
autoPtr<T> remove(iterator& iter);
|
||||||
|
|
||||||
//- Erase an entry specified by given iterator and delete the
|
//- Remove entry specified by given key.
|
||||||
|
//
|
||||||
|
// \return entry as an encapsulated pointer.
|
||||||
|
autoPtr<T> remove(const Key& key);
|
||||||
|
|
||||||
|
//- Erase entry specified by given iterator and delete the
|
||||||
//- allocated pointer.
|
//- allocated pointer.
|
||||||
// Includes a safeguard against the end-iterator.
|
// Includes a safeguard against the end-iterator.
|
||||||
|
//
|
||||||
|
// \return True if item was removed
|
||||||
bool erase(iterator& iter);
|
bool erase(iterator& iter);
|
||||||
|
|
||||||
//- Erase an entry specified by the given key and delete the
|
//- Erase entry specified by given key and delete the
|
||||||
//- allocated pointer.
|
//- allocated pointer.
|
||||||
|
//
|
||||||
|
// \return True if item was removed
|
||||||
bool erase(const Key& key);
|
bool erase(const Key& key);
|
||||||
|
|
||||||
//- Clear all entries from table and delete any allocated pointers
|
//- Clear all entries from table and delete any allocated pointers
|
||||||
@ -169,19 +180,20 @@ public:
|
|||||||
|
|
||||||
// Housekeeping
|
// Housekeeping
|
||||||
|
|
||||||
//- No insert() with raw pointers (potential memory leaks)
|
//- No insert() with raw pointers (potential memory leaks).
|
||||||
// Use insert() with autoPtr or set()
|
//- Use insert() with autoPtr or set()
|
||||||
inline bool insert(const Key&, T*) = delete;
|
inline bool insert(const Key&, T*) = delete;
|
||||||
|
|
||||||
//- Insert a new entry, not overwriting existing entries.
|
//- Insert a new entry, not overwriting existing entries.
|
||||||
// \return True if the entry inserted, which means that it did
|
//
|
||||||
// not previously exist in the table.
|
// \return True if the entry inserted (not previously in table)
|
||||||
inline bool insert(const Key& key, autoPtr<T>& aptr);
|
inline bool insert(const Key& key, autoPtr<T>& aptr);
|
||||||
|
|
||||||
//- Insert a new entry, not overwriting existing entries.
|
//- Insert a new entry, not overwriting existing entries.
|
||||||
|
//
|
||||||
|
// \return True if the entry inserted (not previously in table)
|
||||||
inline bool insert(const Key& key, autoPtr<T>&& aptr);
|
inline bool insert(const Key& key, autoPtr<T>&& aptr);
|
||||||
|
|
||||||
//- Use set(), not insert() to avoid potential memory leaks
|
|
||||||
//- Assign a new entry, overwriting existing entries.
|
//- Assign a new entry, overwriting existing entries.
|
||||||
inline bool set(const Key& key, T* ptr);
|
inline bool set(const Key& key, T* ptr);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user