41#ifndef Foam_HashPtrTable_H
42#define Foam_HashPtrTable_H
55template<
class T>
class tmp;
56template<
class T,
class Key,
class Hash>
class HashPtrTable;
58template<
class T,
class Key,
class Hash>
66template<
class T,
class Key=word,
class Hash=Foam::Hash<Key>>
82 template<
class... Args>
98 using iterator =
typename parent_type::iterator;
146 inline const T*
test(
const Key& key)
const;
150 inline const T*
get(
const Key& key)
const;
192 bool erase(
const Key& key);
237 template<
class... Args>
238 inline bool emplace(
const Key& key, Args&&...
args);
244 template<
class... Args>
252 template<
class... Args>
257 inline bool insert(
const Key&,
T*) =
delete;
261 inline bool insert(
const Key& key, std::unique_ptr<T>&& ptr);
268 inline bool set(
const Key& key,
T* ptr);
271 inline bool set(
const Key& key, std::unique_ptr<T>&& ptr);
280 inline bool set(
const Key& key,
const tmp<T>& ptr);
289 return this->
insert(key, std::move(ptr));
295 return this->
set(key, std::move(ptr));
A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.
void merge(HashPtrTable< T, Key, Hash > &&source)
Attempts to extract entries from source parameter and insert them into this, does not overwrite exist...
HashPtrTable(const label initialCapacity)
Construct given initial table capacity.
bool set(const Key &key, const refPtr< T > &ptr)
Assign a new entry from refPtr (move or clone), overwrites existing.
bool insert(const Key &key, std::unique_ptr< T > &&ptr)
Insert a new entry, not overwriting existing entries.
bool set(const Key &key, autoPtr< T > &&ptr)
Assign a new entry, overwrites existing.
const T * get(const Key &key) const
Return const pointer associated with given entry or a nullptr if the key does not exist in the table.
autoPtr< T > remove(const Key &key)
Remove entry specified by given key.
bool insert(const Key &key, autoPtr< T > &ptr)
Insert a new entry, not overwriting existing entries.
typename parent_type::iterator iterator
HashPtrTable(Istream &is, const INew &inew)
Construct from Istream using given Istream constructor class.
bool erase(const Key &key)
Erase entry specified by given key and delete the allocated pointer.
constexpr HashPtrTable() noexcept=default
Default construct: empty without allocation (capacity=0).
const T * test(const Key &key) const
Return const pointer associated with given entry or a nullptr if the key does not exist in the table.
bool insert(const Key &key, autoPtr< T > &&ptr)
Insert a new entry, not overwriting existing entries.
constexpr HashPtrTable(Foam::zero) noexcept
Construct empty without allocation (capacity=0).
autoPtr< T > release(const Key &key)
Release ownership of the pointer and replace with a nullptr.
T & emplace_set(const Key &key, Args &&... args)
Emplace set an entry, overwriting any existing entries.
HashPtrTable(const dictionary &dict)
Construct from dictionary with default dictionary constructor class.
autoPtr< T > remove(iterator &iter)
Remove entry specified by given iterator.
bool set(const Key &key, const tmp< T > &ptr)
Assign a new entry from tmp (move or clone), overwrites existing.
void operator=(this_type &&rhs)
Move assignment.
bool insert(const Key &, T *)=delete
No insert() with raw pointers (potential memory leaks). Use insert() with autoPtr or set().
void write(Ostream &os) const
Invoke write() on each non-null entry.
void merge(HashPtrTable< T, Key, Hash > &source)
Attempts to extract entries from source parameter and insert them into this, does not overwrite exist...
bool set(const Key &key, autoPtr< T > &ptr)
Assign a new entry, overwrites existing.
bool erase(iterator &iter)
Erase entry specified by given iterator and delete the allocated pointer.
HashPtrTable(const this_type &rhs)
Copy construct, making a copy of each element.
HashPtrTable< T, Key, Hash > this_type
The template instance used for this table.
bool set(const Key &key, T *ptr)
Assign a new entry, overwrites existing.
T * get(const Key &key)
Return pointer associated with given entry or a nullptr if the key does not exist in the table.
typename parent_type::const_iterator const_iterator
T & try_emplace(const Key &key, Args &&... args)
Like emplace_set() but will not overwrite an occupied (non-null) location.
HashPtrTable(this_type &&rhs) noexcept
Move construct.
bool set(const Key &key, std::unique_ptr< T > &&ptr)
Assign a new entry, overwrites existing.
void operator=(const this_type &rhs)
Copy assignment.
bool emplace(const Key &key, Args &&... args)
Emplace insert a new entry, not overwriting existing entries.
void clear()
Clear all entries from table and delete any allocated pointers.
autoPtr< T > release(iterator &iter)
Release ownership of the pointer and replace with a nullptr.
HashTable< T *, Key, Hash > parent_type
HashPtrTable(Istream &is)
Construct from Istream using default Istream constructor class.
~HashPtrTable()
Destructor.
constexpr HashTable() noexcept
Default construct: empty without allocation (capacity=0).
A helper class when constructing from an Istream or dictionary.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
A class for managing references or pointers (no reference counting).
A class for managing temporary objects.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
OBJstream os(runTime.globalPath()/outputName)
Istream & operator>>(Istream &, directionInfo &)
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::argList args(argc, argv)
nonInt insert("surfaceSum(((S|magSf)*S)")
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...