ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
CaloRecGPU::Helpers::maybe_allocate< T > Struct Template Reference

Possibly holds an object in its internal buffer. More...

#include <Helpers.h>

Collaboration diagram for CaloRecGPU::Helpers::maybe_allocate< T >:

Public Member Functions

 maybe_allocate (const bool allocate, const T &t)
 
 maybe_allocate (const bool allocate, T &&t)
 
template<class ... Args>
 maybe_allocate (const bool allocate, Args &&... args)
 
 maybe_allocate (const maybe_allocate &other)
 
 maybe_allocate (maybe_allocate &&other)
 
maybe_allocateoperator= (const maybe_allocate &other)
 
maybe_allocateoperator= (maybe_allocate &&other)
 
 ~maybe_allocate ()
 
bool valid () const
 
T && get () &&
 
T & get () &
 
const T & get () const &
 
const T * operator-> () const
 
T * operator-> ()
 
 operator T& ()
 
 operator T&& () &&
 
 operator const T & () const
 

Private Attributes

char m_buf [sizeof(T)]
 
T * m_object = nullptr
 

Detailed Description

template<class T>
struct CaloRecGPU::Helpers::maybe_allocate< T >

Possibly holds an object in its internal buffer.

Useful to forego heap allocations, but still have the option not to construct something...

Definition at line 1671 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

Constructor & Destructor Documentation

◆ maybe_allocate() [1/5]

template<class T >
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( const bool  allocate,
const T &  t 
)
inline

Definition at line 1680 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1681  {
1682  if (allocate)
1683  {
1684  m_object = new (m_buf) T(t);
1685  }
1686  }

◆ maybe_allocate() [2/5]

template<class T >
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( const bool  allocate,
T &&  t 
)
inline

Definition at line 1688 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1689  {
1690  if (allocate)
1691  {
1692  m_object = new (m_buf) T(t);
1693  }
1694  }

◆ maybe_allocate() [3/5]

template<class T >
template<class ... Args>
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( const bool  allocate,
Args &&...  args 
)
inline

Definition at line 1697 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1698  {
1699  if (allocate)
1700  {
1701  m_object = new (m_buf) T(std::forward<Args>(args)...);
1702  }
1703  }

◆ maybe_allocate() [4/5]

template<class T >
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( const maybe_allocate< T > &  other)
inline

Definition at line 1705 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1705  : maybe_allocate(other.get())
1706  {
1707  }

◆ maybe_allocate() [5/5]

template<class T >
CaloRecGPU::Helpers::maybe_allocate< T >::maybe_allocate ( maybe_allocate< T > &&  other)
inline

Definition at line 1710 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1710  : maybe_allocate(other.get())
1711  {
1712  }

◆ ~maybe_allocate()

template<class T >
CaloRecGPU::Helpers::maybe_allocate< T >::~maybe_allocate ( )
inline

Definition at line 1747 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1748  {
1749  if (m_object != nullptr)
1750  {
1751  m_object->~T();
1752  }
1753  }

Member Function Documentation

◆ get() [1/3]

template<class T >
T& CaloRecGPU::Helpers::maybe_allocate< T >::get ( ) &
inline

Definition at line 1765 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1766  {
1767  return *m_object;
1768  }

◆ get() [2/3]

template<class T >
T&& CaloRecGPU::Helpers::maybe_allocate< T >::get ( ) &&
inline

Definition at line 1760 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1761  {
1762  return *m_object;
1763  }

◆ get() [3/3]

template<class T >
const T& CaloRecGPU::Helpers::maybe_allocate< T >::get ( ) const &
inline

Definition at line 1770 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1771  {
1772  return *m_object;
1773  }

◆ operator const T &()

template<class T >
CaloRecGPU::Helpers::maybe_allocate< T >::operator const T & ( ) const
inline

Definition at line 1795 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1796  {
1797  return *m_object;
1798  }

◆ operator T&()

template<class T >
CaloRecGPU::Helpers::maybe_allocate< T >::operator T& ( )
inline

Definition at line 1785 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1786  {
1787  return *m_object;
1788  }

◆ operator T&&()

template<class T >
CaloRecGPU::Helpers::maybe_allocate< T >::operator T&& ( ) &&
inline

Definition at line 1790 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1791  {
1792  return *m_object;
1793  }

◆ operator->() [1/2]

template<class T >
T* CaloRecGPU::Helpers::maybe_allocate< T >::operator-> ( )
inline

Definition at line 1780 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1781  {
1782  return m_object;
1783  }

◆ operator->() [2/2]

template<class T >
const T* CaloRecGPU::Helpers::maybe_allocate< T >::operator-> ( ) const
inline

Definition at line 1775 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1776  {
1777  return m_object;
1778  }

◆ operator=() [1/2]

template<class T >
maybe_allocate& CaloRecGPU::Helpers::maybe_allocate< T >::operator= ( const maybe_allocate< T > &  other)
inline

Definition at line 1714 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1715  {
1716  if (&other != this)
1717  {
1718  if (m_object != nullptr)
1719  {
1720  (*m_object) = other.get();
1721  }
1722  else
1723  {
1724  m_object = new (m_buf) T(other.get());
1725  }
1726  }
1727  return (*this);
1728  }

◆ operator=() [2/2]

template<class T >
maybe_allocate& CaloRecGPU::Helpers::maybe_allocate< T >::operator= ( maybe_allocate< T > &&  other)
inline

Definition at line 1731 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1732  {
1733  if (&other != this)
1734  {
1735  if (m_object != nullptr)
1736  {
1737  (*m_object) = other.get();
1738  }
1739  else
1740  {
1741  m_object = new (m_buf) T(other.get());
1742  }
1743  }
1744  return (*this);
1745  }

◆ valid()

template<class T >
bool CaloRecGPU::Helpers::maybe_allocate< T >::valid ( ) const
inline

Definition at line 1755 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1756  {
1757  return m_object != nullptr;
1758  }

Member Data Documentation

◆ m_buf

template<class T >
char CaloRecGPU::Helpers::maybe_allocate< T >::m_buf[sizeof(T)]
private

◆ m_object

template<class T >
T* CaloRecGPU::Helpers::maybe_allocate< T >::m_object = nullptr
private

The documentation for this struct was generated from the following file:
python.CaloAddPedShiftConfig.args
args
Definition: CaloAddPedShiftConfig.py:47
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
CaloRecGPU::CUDA_Helpers::allocate
void * allocate(const size_t num)
Allocates and returns the address of num bytes from GPU memory.
CaloRecGPU::Helpers::maybe_allocate::m_object
T * m_object
Definition: Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h:1676
CaloRecGPU::Helpers::maybe_allocate::maybe_allocate
maybe_allocate(const bool allocate, const T &t)
Definition: Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h:1680
InDetDD::other
@ other
Definition: InDetDD_Defs.h:16
CaloRecGPU::Helpers::maybe_allocate::m_buf
char m_buf[sizeof(T)]
Definition: Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h:1675
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35