HashPtrTable< T, Key, Hash > Class Template Reference

A HashTable of pointers to objects of type <T>, with deallocation management of the pointers. More...

Inheritance diagram for HashPtrTable< T, Key, Hash >:
[legend]

Public Types

typedef HashPtrTable< T, Key, Hashthis_type
 The template instance used for this table. More...
 
typedef HashTable< T *, Key, Hashparent_type
 The template instance used for the parent HashTable. More...
 
using iterator = typename parent_type::iterator
 
using const_iterator = typename parent_type::const_iterator
 

Public Member Functions

 HashPtrTable ()=default
 Default construct with default table capacity. More...
 
 HashPtrTable (const label size)
 Construct given initial table capacity. More...
 
template<class INew >
 HashPtrTable (Istream &is, const INew &inew)
 Construct from Istream using given Istream constructor class. More...
 
 HashPtrTable (Istream &is)
 Construct from Istream using default Istream constructor class. More...
 
 HashPtrTable (const dictionary &dict)
 Construct from dictionary with default dictionary constructor class. More...
 
 HashPtrTable (const this_type &rhs)
 Copy construct, making a copy of each element. More...
 
 HashPtrTable (this_type &&rhs)
 Move construct. More...
 
 ~HashPtrTable ()
 Destructor. More...
 
const Tget (const Key &key) const
 
autoPtr< Trelease (iterator &iter)
 Release ownership of the pointer and replace with a nullptr. More...
 
autoPtr< Trelease (const Key &key)
 Release ownership of the pointer and replace with a nullptr. More...
 
autoPtr< Tremove (iterator &iter)
 Remove entry specified by given iterator. More...
 
autoPtr< Tremove (const Key &key)
 Remove entry specified by given key. More...
 
bool erase (iterator &iter)
 
bool erase (const Key &key)
 
void clear ()
 Clear all entries from table and delete any allocated pointers. More...
 
void write (Ostream &os) const
 Invoke write() on each non-null entry. More...
 
void operator= (const this_type &rhs)
 Copy assignment. More...
 
void operator= (this_type &&rhs)
 Move assignment. More...
 
template<class... Args>
bool emplace (const Key &key, Args &&... args)
 Emplace insert a new entry, not overwriting existing entries. More...
 
template<class... Args>
bool emplace_set (const Key &key, Args &&... args)
 Emplace set an entry, overwriting any existing entries. More...
 
bool insert (const Key &, T *)=delete
 
bool insert (const Key &key, autoPtr< T > &ptr)
 Insert a new entry, not overwriting existing entries. More...
 
bool insert (const Key &key, autoPtr< T > &&ptr)
 Insert a new entry, not overwriting existing entries. More...
 
bool insert (const Key &key, std::unique_ptr< T > &&ptr)
 Insert a new entry, not overwriting existing entries. More...
 
bool set (const Key &key, T *ptr)
 Assign a new entry, overwriting existing entries. More...
 
bool set (const Key &key, autoPtr< T > &ptr)
 Assign a new entry, overwriting existing entries. More...
 
bool set (const Key &key, autoPtr< T > &&ptr)
 Assign a new entry, overwriting existing entries. More...
 
bool set (const Key &key, std::unique_ptr< T > &&ptr)
 Assign a new entry, overwriting existing entries. More...
 

Friends

Istreamoperator>> (Istream &is, HashPtrTable< T, Key, Hash > &tbl)
 Clear table and read from Istream. More...
 

Detailed Description

template<class T, class Key = word, class Hash = Foam::Hash<Key>>
class Foam::HashPtrTable< T, Key, Hash >

A HashTable of pointers to objects of type <T>, with deallocation management of the pointers.

Source files

Definition at line 54 of file HashPtrTable.H.

Member Typedef Documentation

◆ this_type

typedef HashPtrTable<T, Key, Hash> this_type

The template instance used for this table.

Definition at line 83 of file HashPtrTable.H.

◆ parent_type

typedef HashTable<T*, Key, Hash> parent_type

The template instance used for the parent HashTable.

Definition at line 86 of file HashPtrTable.H.

◆ iterator

using iterator = typename parent_type::iterator

Definition at line 88 of file HashPtrTable.H.

◆ const_iterator

Definition at line 89 of file HashPtrTable.H.

Constructor & Destructor Documentation

◆ HashPtrTable() [1/7]

HashPtrTable ( )
default

Default construct with default table capacity.

◆ HashPtrTable() [2/7]

HashPtrTable ( const label  size)
inlineexplicit

Construct given initial table capacity.

Definition at line 33 of file HashPtrTableI.H.

◆ HashPtrTable() [3/7]

HashPtrTable ( Istream is,
const INew inew 
)

Construct from Istream using given Istream constructor class.

Definition at line 161 of file HashPtrTableIO.C.

◆ HashPtrTable() [4/7]

HashPtrTable ( Istream is)

Construct from Istream using default Istream constructor class.

Definition at line 168 of file HashPtrTableIO.C.

◆ HashPtrTable() [5/7]

HashPtrTable ( const dictionary dict)
explicit

Construct from dictionary with default dictionary constructor class.

Definition at line 175 of file HashPtrTableIO.C.

◆ HashPtrTable() [6/7]

HashPtrTable ( const this_type rhs)

Copy construct, making a copy of each element.

◆ HashPtrTable() [7/7]

HashPtrTable ( this_type &&  rhs)

Move construct.

◆ ~HashPtrTable()

Destructor.

Definition at line 73 of file HashPtrTable.C.

Member Function Documentation

◆ get()

const T * get ( const Key &  key) const
inline

Return const pointer associated with given entry, returning a nullptr if the key does not exist in the table.

Definition at line 42 of file HashPtrTableI.H.

◆ release() [1/2]

Foam::autoPtr< T > release ( iterator iter)

Release ownership of the pointer and replace with a nullptr.

Includes a safeguard against the end-iterator.

Returns
the entry's old value as an encapsulated pointer.

Definition at line 82 of file HashPtrTable.C.

◆ release() [2/2]

Foam::autoPtr< T > release ( const Key &  key)

Release ownership of the pointer and replace with a nullptr.

Returns
the entry's old value as an encapsulated pointer.

Definition at line 96 of file HashPtrTable.C.

◆ remove() [1/2]

Foam::autoPtr< T > remove ( iterator iter)

Remove entry specified by given iterator.

Includes a safeguard against the end-iterator.

Returns
the entry's old value as an encapsulated pointer.

Definition at line 104 of file HashPtrTable.C.

◆ remove() [2/2]

Foam::autoPtr< T > remove ( const Key &  key)

Remove entry specified by given key.

Returns
the entry's old value as an encapsulated pointer.

Definition at line 118 of file HashPtrTable.C.

◆ erase() [1/2]

bool erase ( iterator iter)

Erase entry specified by given iterator and delete the allocated pointer.

Includes a safeguard against the end-iterator.

Returns
True if item was removed

Definition at line 126 of file HashPtrTable.C.

◆ erase() [2/2]

bool erase ( const Key &  key)

Erase entry specified by given key and delete the allocated pointer.

Returns
True if item was removed

Definition at line 144 of file HashPtrTable.C.

◆ clear()

void clear ( )

Clear all entries from table and delete any allocated pointers.

Definition at line 152 of file HashPtrTable.C.

◆ write()

void write ( Ostream os) const

Invoke write() on each non-null entry.

Definition at line 144 of file HashPtrTableIO.C.

◆ operator=() [1/2]

void operator= ( const this_type rhs)

Copy assignment.

Referenced by PtrMap< Foam::coordSystem::cylindrical >::operator=().

Here is the caller graph for this function:

◆ operator=() [2/2]

void operator= ( this_type &&  rhs)

Move assignment.

◆ emplace()

bool emplace ( const Key &  key,
Args &&...  args 
)
inline

Emplace insert a new entry, not overwriting existing entries.

Returns
True if the entry did not previously exist in the table.

Definition at line 56 of file HashPtrTableI.H.

◆ emplace_set()

bool emplace_set ( const Key &  key,
Args &&...  args 
)
inline

Emplace set an entry, overwriting any existing entries.

Returns
True, since it always overwrites any entries.

Definition at line 73 of file HashPtrTableI.H.

◆ insert() [1/4]

bool insert ( const Key &  ,
T  
)
inlinedelete

No insert() with raw pointers (potential memory leaks). Use insert() with autoPtr or set()

◆ insert() [2/4]

bool insert ( const Key &  key,
autoPtr< T > &  ptr 
)
inline

Insert a new entry, not overwriting existing entries.

Returns
True if the entry inserted (not previously in table)

Definition at line 84 of file HashPtrTableI.H.

◆ insert() [3/4]

bool insert ( const Key &  key,
autoPtr< T > &&  ptr 
)
inline

Insert a new entry, not overwriting existing entries.

Returns
True if the entry inserted (not previously in table)

Definition at line 101 of file HashPtrTableI.H.

◆ insert() [4/4]

bool insert ( const Key &  key,
std::unique_ptr< T > &&  ptr 
)
inline

Insert a new entry, not overwriting existing entries.

Returns
True if the entry inserted (not previously in table)

Definition at line 118 of file HashPtrTableI.H.

◆ set() [1/4]

bool set ( const Key &  key,
T ptr 
)
inline

◆ set() [2/4]

bool set ( const Key &  key,
autoPtr< T > &  ptr 
)
inline

Assign a new entry, overwriting existing entries.

Definition at line 155 of file HashPtrTableI.H.

◆ set() [3/4]

bool set ( const Key &  key,
autoPtr< T > &&  ptr 
)
inline

Assign a new entry, overwriting existing entries.

Definition at line 166 of file HashPtrTableI.H.

◆ set() [4/4]

bool set ( const Key &  key,
std::unique_ptr< T > &&  ptr 
)
inline

Assign a new entry, overwriting existing entries.

Definition at line 177 of file HashPtrTableI.H.

Friends And Related Function Documentation

◆ operator>>

Istream& operator>> ( Istream is,
HashPtrTable< T, Key, Hash > &  tbl 
)
friend

Clear table and read from Istream.


The documentation for this class was generated from the following files: