mutable
A Database System for Research and Fast Prototyping
Loading...
Searching...
No Matches
Data Structures | Public Types | Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Member Functions | Private Attributes | Friends
m::Pool< T, Hash, KeyEqual, ThreadSafe > Struct Template Reference

A pool implements an implicitly garbage-collected set of instances of a class hierarchy. More...

#include <Pool.hpp>

Collaboration diagram for m::Pool< T, Hash, KeyEqual, ThreadSafe >:
[legend]

Data Structures

struct  dereference_equal_to
 
struct  dereference_hash
 

Public Types

using counter_type = std::conditional_t< ThreadSafe, std::atomic< uint32_t >, uint32_t >
 
using table_type = std::unordered_map< std::unique_ptr< T >, counter_type, dereference_hash, dereference_equal_to >
 
using pooled_type = T
 
template<typename U >
using proxy_type = Pooled< U, Pool, false >
 
template<typename U >
using proxy_optional_type = Pooled< U, Pool, true >
 
using hasher = Hash
 
using key_equal = KeyEqual
 
using const_iterator = table_type::const_iterator
 

Public Member Functions

 Pool ()=default
 
 Pool (std::size_t initial_capacity)
 
 ~Pool ()
 
std::size_t size () const
 Returns the number of elements in the pool.
 
const_iterator begin ()
 
const_iterator end ()
 
const_iterator cbegin () const
 
const_iterator cend () const
 
template<typename U >
requires std::derived_from<U, T>
Pooled< U, Pool, false > operator() (U &&u)
 Returns the pooled.
 
template<typename U >
requires std::derived_from<U, T>
Pool< T, Hash, KeyEqual, ThreadSafe >::proxy_type< Uoperator() (U &&u)
 

Static Public Attributes

static constexpr bool is_thread_safe = ThreadSafe
 

Private Member Functions

template<typename U , bool CanBeNone>
bool erase (const Pooled< U, Pool, CanBeNone > &pooled)
 Erases the pooled entity from the pool.
 

Static Private Member Functions

template<typename U , bool CanBeNone>
requires std::derived_from<U, T>
static const UGet (const Pooled< U, Pool, CanBeNone > &pooled)
 Returns a reference to the value referenced by.
 

Private Attributes

table_type table_
 
OptField< ThreadSafe, reader_writer_mutextable_mutex_
 

Friends

template<typename , typename , bool >
struct Pooled
 

Detailed Description

template<typename T, typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
struct m::Pool< T, Hash, KeyEqual, ThreadSafe >

A pool implements an implicitly garbage-collected set of instances of a class hierarchy.

Definition at line 80 of file Pool.hpp.

Member Typedef Documentation

◆ const_iterator

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
using m::Pool< T, Hash, KeyEqual, ThreadSafe >::const_iterator = table_type::const_iterator

Definition at line 121 of file Pool.hpp.

◆ counter_type

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
using m::Pool< T, Hash, KeyEqual, ThreadSafe >::counter_type = std::conditional_t<ThreadSafe, std::atomic<uint32_t>, uint32_t>

Definition at line 102 of file Pool.hpp.

◆ hasher

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
using m::Pool< T, Hash, KeyEqual, ThreadSafe >::hasher = Hash

Definition at line 107 of file Pool.hpp.

◆ key_equal

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
using m::Pool< T, Hash, KeyEqual, ThreadSafe >::key_equal = KeyEqual

Definition at line 108 of file Pool.hpp.

◆ pooled_type

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
using m::Pool< T, Hash, KeyEqual, ThreadSafe >::pooled_type = T

Definition at line 104 of file Pool.hpp.

◆ proxy_optional_type

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
template<typename U >
using m::Pool< T, Hash, KeyEqual, ThreadSafe >::proxy_optional_type = Pooled<U, Pool, true>

Definition at line 106 of file Pool.hpp.

◆ proxy_type

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
template<typename U >
using m::Pool< T, Hash, KeyEqual, ThreadSafe >::proxy_type = Pooled<U, Pool, false>

Definition at line 105 of file Pool.hpp.

◆ table_type

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
using m::Pool< T, Hash, KeyEqual, ThreadSafe >::table_type = std::unordered_map<std::unique_ptr<T>, counter_type, dereference_hash, dereference_equal_to>

Definition at line 103 of file Pool.hpp.

Constructor & Destructor Documentation

◆ Pool() [1/2]

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
m::Pool< T, Hash, KeyEqual, ThreadSafe >::Pool ( )
default

◆ Pool() [2/2]

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
m::Pool< T, Hash, KeyEqual, ThreadSafe >::Pool ( std::size_t  initial_capacity)
inline

Definition at line 125 of file Pool.hpp.

◆ ~Pool()

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
m::Pool< T, Hash, KeyEqual, ThreadSafe >::~Pool ( )
inline

Definition at line 126 of file Pool.hpp.

References M_insist, and m::Pool< T, Hash, KeyEqual, ThreadSafe >::table_.

Member Function Documentation

◆ begin()

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
const_iterator m::Pool< T, Hash, KeyEqual, ThreadSafe >::begin ( )
inline

Definition at line 139 of file Pool.hpp.

References m::Pool< T, Hash, KeyEqual, ThreadSafe >::table_.

◆ cbegin()

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
const_iterator m::Pool< T, Hash, KeyEqual, ThreadSafe >::cbegin ( ) const
inline

Definition at line 141 of file Pool.hpp.

References m::Pool< T, Hash, KeyEqual, ThreadSafe >::table_.

◆ cend()

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
const_iterator m::Pool< T, Hash, KeyEqual, ThreadSafe >::cend ( ) const
inline

Definition at line 142 of file Pool.hpp.

References m::Pool< T, Hash, KeyEqual, ThreadSafe >::table_.

◆ end()

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
const_iterator m::Pool< T, Hash, KeyEqual, ThreadSafe >::end ( )
inline

Definition at line 140 of file Pool.hpp.

References m::Pool< T, Hash, KeyEqual, ThreadSafe >::table_.

◆ erase()

template<typename T , typename Hash , typename KeyEqual , bool ThreadSafe>
template<typename U , bool CanBeNone>
bool m::Pool< T, Hash, KeyEqual, ThreadSafe >::erase ( const Pooled< U, Pool< T, Hash, KeyEqual, ThreadSafe >, CanBeNone > &  pooled)
private

Erases the pooled entity from the pool.

Requires that the reference count is 0.

Definition at line 407 of file Pool.hpp.

References M_insist, and m::Pooled< T, Pool, CanBeNone >::ref_.

◆ Get()

template<typename T , typename Hash , typename KeyEqual , bool ThreadSafe>
requires std::derived_from<U, T>
template<typename U , bool CanBeNone>
requires std::derived_from<U, T>
const U & m::Pool< T, Hash, KeyEqual, ThreadSafe >::Get ( const Pooled< U, Pool< T, Hash, KeyEqual, ThreadSafe >, CanBeNone > &  pooled)
staticprivate

◆ operator()() [1/2]

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
template<typename U >
requires std::derived_from<U, T>
Pooled< U, Pool, false > m::Pool< T, Hash, KeyEqual, ThreadSafe >::operator() ( U &&  u)

Returns the pooled.

Parameters
u.

◆ operator()() [2/2]

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
template<typename U >
requires std::derived_from<U, T>
Pool< T, Hash, KeyEqual, ThreadSafe >::proxy_type< U > m::Pool< T, Hash, KeyEqual, ThreadSafe >::operator() ( U &&  u)

Definition at line 383 of file Pool.hpp.

References m::reader_writer_lock::lock_read(), M_insist, and m::U.

◆ size()

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
std::size_t m::Pool< T, Hash, KeyEqual, ThreadSafe >::size ( ) const
inline

Returns the number of elements in the pool.

Definition at line 137 of file Pool.hpp.

References m::Pool< T, Hash, KeyEqual, ThreadSafe >::table_.

Friends And Related Function Documentation

◆ Pooled

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
template<typename , typename , bool >
friend struct Pooled
friend

Definition at line 111 of file Pool.hpp.

Field Documentation

◆ is_thread_safe

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
constexpr bool m::Pool< T, Hash, KeyEqual, ThreadSafe >::is_thread_safe = ThreadSafe
staticconstexpr

Definition at line 113 of file Pool.hpp.

◆ table_

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
table_type m::Pool< T, Hash, KeyEqual, ThreadSafe >::table_
private

◆ table_mutex_

template<typename T , typename Hash = std::hash<T>, typename KeyEqual = std::equal_to<T>, bool ThreadSafe = false>
OptField<ThreadSafe, reader_writer_mutex> m::Pool< T, Hash, KeyEqual, ThreadSafe >::table_mutex_
mutableprivate

Definition at line 118 of file Pool.hpp.


The documentation for this struct was generated from the following file: