Commit fd2b7289 authored by Mark Olesen's avatar Mark Olesen
Browse files

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.
parent 27bbb516
......@@ -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>
bool Foam::HashPtrTable<T, Key, Hash>::erase(iterator& iter)
{
......
......@@ -123,17 +123,28 @@ public:
// Edit
//- Remove and return the pointer specified by given iterator.
//- Remove entry specified by given iterator.
// Includes a safeguard against the end-iterator.
//
// \return entry as an encapsulated pointer.
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.
// Includes a safeguard against the end-iterator.
//
// \return True if item was removed
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.
//
// \return True if item was removed
bool erase(const Key& key);
//- Clear all entries from table and delete any allocated pointers
......@@ -169,19 +180,20 @@ public:
// Housekeeping
//- No insert() with raw pointers (potential memory leaks)
// Use insert() with autoPtr or set()
//- No insert() with raw pointers (potential memory leaks).
//- Use insert() with autoPtr or set()
inline bool insert(const Key&, T*) = delete;
//- 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);
//- 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);
//- Use set(), not insert() to avoid potential memory leaks
//- Assign a new entry, overwriting existing entries.
inline bool set(const Key& key, T* ptr);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment