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 1664 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 1673 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1674  {
1675  if (allocate)
1676  {
1677  m_object = new (m_buf) T(t);
1678  }
1679  }

◆ maybe_allocate() [2/5]

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

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

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

◆ 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 1690 of file Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h.

1691  {
1692  if (allocate)
1693  {
1694  m_object = new (m_buf) T(std::forward<Args>(args)...);
1695  }
1696  }

◆ maybe_allocate() [4/5]

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

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

1698  : maybe_allocate(other.get())
1699  {
1700  }

◆ maybe_allocate() [5/5]

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

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

1703  : maybe_allocate(other.get())
1704  {
1705  }

◆ ~maybe_allocate()

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

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

1741  {
1742  if (m_object != nullptr)
1743  {
1744  m_object->~T();
1745  }
1746  }

Member Function Documentation

◆ get() [1/3]

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

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

1759  {
1760  return *m_object;
1761  }

◆ get() [2/3]

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

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

1754  {
1755  return *m_object;
1756  }

◆ get() [3/3]

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

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

1764  {
1765  return *m_object;
1766  }

◆ operator const T &()

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

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

1789  {
1790  return *m_object;
1791  }

◆ operator T&()

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

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

1779  {
1780  return *m_object;
1781  }

◆ operator T&&()

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

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

1784  {
1785  return *m_object;
1786  }

◆ operator->() [1/2]

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

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

1774  {
1775  return m_object;
1776  }

◆ operator->() [2/2]

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

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

1769  {
1770  return m_object;
1771  }

◆ operator=() [1/2]

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

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

1708  {
1709  if (&other != this)
1710  {
1711  if (m_object != nullptr)
1712  {
1713  (*m_object) = other.get();
1714  }
1715  else
1716  {
1717  m_object = new (m_buf) T(other.get());
1718  }
1719  }
1720  return (*this);
1721  }

◆ operator=() [2/2]

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

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

1725  {
1726  if (&other != this)
1727  {
1728  if (m_object != nullptr)
1729  {
1730  (*m_object) = other.get();
1731  }
1732  else
1733  {
1734  m_object = new (m_buf) T(other.get());
1735  }
1736  }
1737  return (*this);
1738  }

◆ valid()

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

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

1749  {
1750  return m_object != nullptr;
1751  }

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:
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:1669
CaloRecGPU::Helpers::maybe_allocate::maybe_allocate
maybe_allocate(const bool allocate, const T &t)
Definition: Calorimeter/CaloRecGPU/CaloRecGPU/Helpers.h:1673
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:1668
python.CaloScaleNoiseConfig.args
args
Definition: CaloScaleNoiseConfig.py:80
TSU::T
unsigned long long T
Definition: L1TopoDataTypes.h:35