CookMem 1.4.0
A C++ memory context / allocator
Loading...
Searching...
No Matches
cookmem::TLSContextProvider< Context, Tag > Class Template Reference

#include <allocator.h>

Public Types

typedef Context context_type
 
typedef std::true_type propagate_on_container_copy_assignment
 
typedef std::true_type propagate_on_container_move_assignment
 
typedef std::true_type propagate_on_container_swap
 
typedef std::false_type is_always_equal
 

Public Member Functions

 TLSContextProvider ()
 
Context & get () const
 
bool operator== (const TLSContextProvider &other) const
 
bool operator!= (const TLSContextProvider &other) const
 

Static Public Member Functions

static Context & getActiveContext ()
 
static Context & getThreadContext ()
 

Friends

template<class , class >
class TLSContextScope
 

Detailed Description

template<class Context, class Tag>
class cookmem::TLSContextProvider< Context, Tag >

Provides one shared, default-constructed context per Context, Tag, and thread.

Use a distinct Tag type to give different allocator groups separate contexts.

Member Typedef Documentation

◆ context_type

The type of the memory context.

◆ is_always_equal

template<class Context , class Tag >
typedef std::false_type cookmem::TLSContextProvider< Context, Tag >::is_always_equal

Providers are equal only when they refer to the same context.

◆ propagate_on_container_copy_assignment

template<class Context , class Tag >
typedef std::true_type cookmem::TLSContextProvider< Context, Tag >::propagate_on_container_copy_assignment

Containers take the allocator of the source when copy-assigned.

◆ propagate_on_container_move_assignment

template<class Context , class Tag >
typedef std::true_type cookmem::TLSContextProvider< Context, Tag >::propagate_on_container_move_assignment

Containers take the allocator of the source when move-assigned.

◆ propagate_on_container_swap

template<class Context , class Tag >
typedef std::true_type cookmem::TLSContextProvider< Context, Tag >::propagate_on_container_swap

Containers exchange allocators when swapped.

Constructor & Destructor Documentation

◆ TLSContextProvider()

template<class Context , class Tag >
cookmem::TLSContextProvider< Context, Tag >::TLSContextProvider ( )
inline

Constructor. The provider refers to the active context of the current thread: the context of the innermost matching TLSContextScope if there is one, or the persistent thread-local context otherwise.

Member Function Documentation

◆ get()

template<class Context , class Tag >
Context & cookmem::TLSContextProvider< Context, Tag >::get ( ) const
inline

Get the memory context.

Returns
the context this provider was bound to when it was constructed.

◆ getActiveContext()

template<class Context , class Tag >
static Context & cookmem::TLSContextProvider< Context, Tag >::getActiveContext ( )
inlinestatic

Returns the active context, or the persistent thread context when no scope is active.

◆ getThreadContext()

template<class Context , class Tag >
static Context & cookmem::TLSContextProvider< Context, Tag >::getThreadContext ( )
inlinestatic

Returns this thread's persistent context, even when a scope is active.

◆ operator!=()

template<class Context , class Tag >
bool cookmem::TLSContextProvider< Context, Tag >::operator!= ( const TLSContextProvider< Context, Tag > &  other) const
inline

Check if two providers refer to different memory contexts.

Parameters
otherthe provider to compare with.
Returns
true if the providers refer to different contexts.

◆ operator==()

template<class Context , class Tag >
bool cookmem::TLSContextProvider< Context, Tag >::operator== ( const TLSContextProvider< Context, Tag > &  other) const
inline

Check if two providers refer to the same memory context.

Parameters
otherthe provider to compare with.
Returns
true if both providers refer to the same context.

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