BornAgain  1.18.0
Simulate and fit neutron and x-ray scattering at grazing incidence
SafePointerVector< T > Class Template Reference
Collaboration diagram for SafePointerVector< T >:

Public Types

typedef std::vector< T * >::iterator iterator
 
typedef std::vector< T * >::const_iterator const_iterator
 

Public Member Functions

 SafePointerVector ()
 
 SafePointerVector (const SafePointerVector &other)
 
 SafePointerVector (SafePointerVector &&other)
 
 ~SafePointerVector ()
 
SafePointerVectoroperator= (const SafePointerVector &right)
 
SafePointerVectoroperator= (SafePointerVector &&right)
 
size_t size () const
 
bool empty () const
 
void push_back (T *pointer)
 
T * operator[] (size_t index)
 
const T * operator[] (size_t index) const
 
iterator begin ()
 
const_iterator begin () const
 
iterator end ()
 
const_iterator end () const
 
bool deleteElement (T *pointer)
 
T * back ()
 
const T * back () const
 
void clear ()
 

Private Attributes

std::vector< T * > m_pointers
 

Detailed Description

template<class T>
class SafePointerVector< T >

A vector of pointers, owned by *this, with methods to handle them safely.

The objects pointed to must support the ICloneable interface.

Definition at line 26 of file SafePointerVector.h.

Member Typedef Documentation

◆ iterator

template<class T >
typedef std::vector<T*>::iterator SafePointerVector< T >::iterator

Definition at line 29 of file SafePointerVector.h.

◆ const_iterator

template<class T >
typedef std::vector<T*>::const_iterator SafePointerVector< T >::const_iterator

Definition at line 30 of file SafePointerVector.h.

Constructor & Destructor Documentation

◆ SafePointerVector() [1/3]

template<class T >
SafePointerVector< T >::SafePointerVector ( )
inline

Definition at line 31 of file SafePointerVector.h.

31 {}

◆ SafePointerVector() [2/3]

template<class T >
SafePointerVector< T >::SafePointerVector ( const SafePointerVector< T > &  other)

Definition at line 58 of file SafePointerVector.h.

59 {
60  for (const_iterator it = other.begin(); it != other.end(); ++it)
61  m_pointers.push_back((*it)->clone());
62 }
std::vector< T * >::const_iterator const_iterator
std::vector< T * > m_pointers

References SafePointerVector< T >::begin(), and SafePointerVector< T >::end().

Here is the call graph for this function:

◆ SafePointerVector() [3/3]

template<class T >
SafePointerVector< T >::SafePointerVector ( SafePointerVector< T > &&  other)

Definition at line 65 of file SafePointerVector.h.

65  : m_pointers{other.m_pointers}
66 {
67 }

◆ ~SafePointerVector()

template<class T >
SafePointerVector< T >::~SafePointerVector ( )
inline

Definition at line 34 of file SafePointerVector.h.

34 { clear(); }

References SafePointerVector< T >::clear().

Here is the call graph for this function:

Member Function Documentation

◆ operator=() [1/2]

template<class T >
SafePointerVector< T > & SafePointerVector< T >::operator= ( const SafePointerVector< T > &  right)

Definition at line 70 of file SafePointerVector.h.

71 {
72  if (this == &right)
73  return *this;
74  clear();
75  for (const_iterator it = right.begin(); it != right.end(); ++it)
76  m_pointers.push_back((*it)->clone());
77  return *this;
78 }

References SafePointerVector< T >::begin(), and SafePointerVector< T >::end().

Here is the call graph for this function:

◆ operator=() [2/2]

template<class T >
SafePointerVector< T > & SafePointerVector< T >::operator= ( SafePointerVector< T > &&  right)

Definition at line 81 of file SafePointerVector.h.

82 {
83  clear();
84  m_pointers = std::move(right.m_pointers);
85  right.m_pointers.clear();
86  return *this;
87 }

◆ size()

◆ empty()

template<class T >
bool SafePointerVector< T >::empty ( ) const
inline

Definition at line 39 of file SafePointerVector.h.

39 { return m_pointers.empty(); }

References SafePointerVector< T >::m_pointers.

Referenced by DetectorMask::hasMasks(), and DetectorMask::process_masks().

◆ push_back()

◆ operator[]() [1/2]

template<class T >
T* SafePointerVector< T >::operator[] ( size_t  index)
inline

Definition at line 41 of file SafePointerVector.h.

41 { return m_pointers[index]; }

References SafePointerVector< T >::m_pointers.

◆ operator[]() [2/2]

template<class T >
const T* SafePointerVector< T >::operator[] ( size_t  index) const
inline

Definition at line 42 of file SafePointerVector.h.

42 { return m_pointers[index]; }

References SafePointerVector< T >::m_pointers.

◆ begin() [1/2]

template<class T >
iterator SafePointerVector< T >::begin ( )
inline

◆ begin() [2/2]

template<class T >
const_iterator SafePointerVector< T >::begin ( ) const
inline

Definition at line 44 of file SafePointerVector.h.

44 { return m_pointers.begin(); }

References SafePointerVector< T >::m_pointers.

◆ end() [1/2]

template<class T >
iterator SafePointerVector< T >::end ( )
inline

◆ end() [2/2]

template<class T >
const_iterator SafePointerVector< T >::end ( ) const
inline

Definition at line 46 of file SafePointerVector.h.

46 { return m_pointers.end(); }

References SafePointerVector< T >::m_pointers.

◆ deleteElement()

template<class T >
bool SafePointerVector< T >::deleteElement ( T *  pointer)
inline

Definition at line 89 of file SafePointerVector.h.

90 {
91  iterator it = std::find(m_pointers.begin(), m_pointers.end(), pointer);
92  if (it == m_pointers.end())
93  return false;
94  m_pointers.erase(it);
95  delete pointer;
96  return true;
97 }
std::vector< T * >::iterator iterator

◆ back() [1/2]

template<class T >
T* SafePointerVector< T >::back ( )
inline

Definition at line 50 of file SafePointerVector.h.

50 { return m_pointers.back(); }

References SafePointerVector< T >::m_pointers.

Referenced by MultiLayer::addLayerWithTopRoughness().

◆ back() [2/2]

template<class T >
const T* SafePointerVector< T >::back ( ) const
inline

Definition at line 51 of file SafePointerVector.h.

51 { return m_pointers.back(); }

References SafePointerVector< T >::m_pointers.

◆ clear()

template<class T >
void SafePointerVector< T >::clear

Definition at line 99 of file SafePointerVector.h.

100 {
101  for (iterator it = begin(); it != end(); ++it)
102  delete (*it);
103  m_pointers.clear();
104 }

Referenced by DetectorMask::removeMasks(), and SafePointerVector< T >::~SafePointerVector().

Member Data Documentation

◆ m_pointers


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