diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C index 57c4b9bd37..7ca213778e 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.C @@ -86,6 +86,14 @@ Foam::autoPtr Foam::HashPtrTable::remove(iterator& iter) } +template +Foam::autoPtr Foam::HashPtrTable::remove(const Key& key) +{ + auto iter = this->find(key); + return this->remove(iter); +} + + template bool Foam::HashPtrTable::erase(iterator& iter) { diff --git a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H index 655c715c5e..5e6b5514d1 100644 --- a/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H +++ b/src/OpenFOAM/containers/HashTables/HashPtrTable/HashPtrTable.H @@ -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 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 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& 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&& 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);