KiCad PCB EDA Suite
Loading...
Searching...
No Matches
LEAK_AT_EXIT< T > Class Template Reference

A wrapper for static data that should not be destroyed at program exit. More...

#include <leak_at_exit.h>

Public Member Functions

 LEAK_AT_EXIT ()
 
 LEAK_AT_EXIT (const LEAK_AT_EXIT &)=delete
 
LEAK_AT_EXIToperator= (const LEAK_AT_EXIT &)=delete
 
 LEAK_AT_EXIT (LEAK_AT_EXIT &&)=delete
 
LEAK_AT_EXIToperator= (LEAK_AT_EXIT &&)=delete
 
TGet ()
 Access the underlying object, creating it on first call.
 
Toperator* ()
 
Toperator-> ()
 
 operator T& ()
 

Private Attributes

Tm_instance
 
std::once_flag m_initFlag
 

Detailed Description

template<typename T>
class LEAK_AT_EXIT< T >

A wrapper for static data that should not be destroyed at program exit.

Usage: // Instead of: static std::map<wxString, Data> GlobalData;

// Use: static LEAK_AT_EXIT<std::map<wxString, Data>> GlobalData;

The wrapped object is heap-allocated on first access and never freed. This avoids running potentially expensive destructors during static destruction, speeding up program exit.

Each LEAK_AT_EXIT instance has its own storage, so multiple static variables of the same type will each get their own heap allocation.

Thread-safe for concurrent first access (uses std::call_once).

Definition at line 67 of file leak_at_exit.h.

Constructor & Destructor Documentation

◆ LEAK_AT_EXIT() [1/3]

template<typename T>
LEAK_AT_EXIT< T >::LEAK_AT_EXIT ( )
inline

Definition at line 70 of file leak_at_exit.h.

References m_instance.

Referenced by LEAK_AT_EXIT(), LEAK_AT_EXIT(), operator=(), and operator=().

◆ LEAK_AT_EXIT() [2/3]

template<typename T>
LEAK_AT_EXIT< T >::LEAK_AT_EXIT ( const LEAK_AT_EXIT< T > & )
delete

References LEAK_AT_EXIT().

◆ LEAK_AT_EXIT() [3/3]

template<typename T>
LEAK_AT_EXIT< T >::LEAK_AT_EXIT ( LEAK_AT_EXIT< T > && )
delete

References LEAK_AT_EXIT().

Member Function Documentation

◆ Get()

template<typename T>
T & LEAK_AT_EXIT< T >::Get ( )
inline

Access the underlying object, creating it on first call.

The object is intentionally never destroyed.

Definition at line 82 of file leak_at_exit.h.

References LSAN_IGNORE, m_initFlag, m_instance, and T.

Referenced by LEAK_AT_EXIT< std::map< wxString, LIB_DATA > >::operator std::map< wxString, LIB_DATA > &(), operator*(), and operator->().

◆ operator T&()

template<typename T>
LEAK_AT_EXIT< T >::operator T& ( )
inline

Definition at line 97 of file leak_at_exit.h.

◆ operator*()

template<typename T>
T & LEAK_AT_EXIT< T >::operator* ( )
inline

Definition at line 93 of file leak_at_exit.h.

References Get(), and T.

◆ operator->()

template<typename T>
T * LEAK_AT_EXIT< T >::operator-> ( )
inline

Definition at line 94 of file leak_at_exit.h.

References Get(), and T.

◆ operator=() [1/2]

template<typename T>
LEAK_AT_EXIT & LEAK_AT_EXIT< T >::operator= ( const LEAK_AT_EXIT< T > & )
delete

References LEAK_AT_EXIT().

◆ operator=() [2/2]

template<typename T>
LEAK_AT_EXIT & LEAK_AT_EXIT< T >::operator= ( LEAK_AT_EXIT< T > && )
delete

References LEAK_AT_EXIT().

Member Data Documentation

◆ m_initFlag

template<typename T>
std::once_flag LEAK_AT_EXIT< T >::m_initFlag
private

Definition at line 101 of file leak_at_exit.h.

Referenced by Get().

◆ m_instance

template<typename T>
T* LEAK_AT_EXIT< T >::m_instance
private

Definition at line 100 of file leak_at_exit.h.

Referenced by Get(), and LEAK_AT_EXIT().


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