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

1655  {
1656  if (allocate)
1657  {
1658  m_object = new (m_buf) T(t);
1659  }
1660  }

◆ maybe_allocate() [2/5]

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

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

1663  {
1664  if (allocate)
1665  {
1666  m_object = new (m_buf) T(t);
1667  }
1668  }

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

1672  {
1673  if (allocate)
1674  {
1675  m_object = new (m_buf) T(std::forward<Args>(args)...);
1676  }
1677  }

◆ maybe_allocate() [4/5]

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

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

1679  : maybe_allocate(other.get())
1680  {
1681  }

◆ maybe_allocate() [5/5]

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

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

1684  : maybe_allocate(other.get())
1685  {
1686  }

◆ ~maybe_allocate()

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

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

1722  {
1723  if (m_object != nullptr)
1724  {
1725  m_object->~T();
1726  }
1727  }

Member Function Documentation

◆ get() [1/3]

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

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

1740  {
1741  return *m_object;
1742  }

◆ get() [2/3]

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

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

1735  {
1736  return *m_object;
1737  }

◆ get() [3/3]

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

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

1745  {
1746  return *m_object;
1747  }

◆ operator const T &()

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

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

1770  {
1771  return *m_object;
1772  }

◆ operator T&()

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

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

1760  {
1761  return *m_object;
1762  }

◆ operator T&&()

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

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

1765  {
1766  return *m_object;
1767  }

◆ operator->() [1/2]

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

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

1755  {
1756  return m_object;
1757  }

◆ operator->() [2/2]

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

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

1750  {
1751  return m_object;
1752  }

◆ operator=() [1/2]

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

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

1689  {
1690  if (&other != this)
1691  {
1692  if (m_object != nullptr)
1693  {
1694  (*m_object) = other.get();
1695  }
1696  else
1697  {
1698  m_object = new (m_buf) T(other.get());
1699  }
1700  }
1701  return (*this);
1702  }

◆ operator=() [2/2]

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

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

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

◆ valid()

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

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

1730  {
1731  return m_object != nullptr;
1732  }

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