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

1677  {
1678  if (allocate)
1679  {
1680  m_object = new (m_buf) T(t);
1681  }
1682  }

◆ maybe_allocate() [2/5]

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

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

1685  {
1686  if (allocate)
1687  {
1688  m_object = new (m_buf) T(t);
1689  }
1690  }

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

1694  {
1695  if (allocate)
1696  {
1697  m_object = new (m_buf) T(std::forward<Args>(args)...);
1698  }
1699  }

◆ maybe_allocate() [4/5]

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

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

1701  : maybe_allocate(other.get())
1702  {
1703  }

◆ maybe_allocate() [5/5]

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

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

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

◆ ~maybe_allocate()

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

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

1744  {
1745  if (m_object != nullptr)
1746  {
1747  m_object->~T();
1748  }
1749  }

Member Function Documentation

◆ get() [1/3]

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

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

1762  {
1763  return *m_object;
1764  }

◆ get() [2/3]

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

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

1757  {
1758  return *m_object;
1759  }

◆ get() [3/3]

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

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

1767  {
1768  return *m_object;
1769  }

◆ operator const T &()

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

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

1792  {
1793  return *m_object;
1794  }

◆ operator T&()

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

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

1782  {
1783  return *m_object;
1784  }

◆ operator T&&()

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

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

1787  {
1788  return *m_object;
1789  }

◆ operator->() [1/2]

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

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

1777  {
1778  return m_object;
1779  }

◆ operator->() [2/2]

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

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

1772  {
1773  return m_object;
1774  }

◆ operator=() [1/2]

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

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

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

◆ operator=() [2/2]

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

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

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

◆ valid()

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

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

1752  {
1753  return m_object != nullptr;
1754  }

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