BornAgain  1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
OwningVector< T > Class Template Reference

Description

template<class T>
class OwningVector< T >

A vector of unique pointers to objects that are cloneable.

Equips vector<unique_ptr<T>> with copy constructor. For use with polymorphic objects, or in pimpl idiom. The objects pointed to must posses a clone() function.

Definition at line 35 of file OwningVector.h.

Collaboration diagram for OwningVector< T >:
[legend]

Public Types

using ConstIterator = typename std::vector< T * >::const_iterator
 
using Iterator = typename std::vector< T * >::iterator
 

Public Member Functions

 OwningVector ()=default
 
 OwningVector (const OwningVector &other)
 Constructor that clones elements in given vector. More...
 
 OwningVector (const std::vector< T * > &v)
 Constructor that takes over ownership of elements in given vector. More...
 
 ~OwningVector ()
 
T *const & at (int i) const
 
const T * back () const
 
Iterator begin ()
 
ConstIterator begin () const
 
void clear ()
 
std::vector< T * > cloned_vector () const
 
std::vector< const T * > const_vector () const
 
void emplace_back (T *e)
 
bool empty () const
 
Iterator end ()
 
ConstIterator end () const
 
OwningVectoroperator= (const OwningVector &other)
 
T *const & operator[] (int i) const
 
size_t size () const
 

Private Attributes

std::vector< T * > m_v
 

Member Typedef Documentation

◆ ConstIterator

template<class T >
using OwningVector< T >::ConstIterator = typename std::vector<T*>::const_iterator

Definition at line 90 of file OwningVector.h.

◆ Iterator

template<class T >
using OwningVector< T >::Iterator = typename std::vector<T*>::iterator

Definition at line 89 of file OwningVector.h.

Constructor & Destructor Documentation

◆ OwningVector() [1/3]

template<class T >
OwningVector< T >::OwningVector ( )
default

◆ OwningVector() [2/3]

template<class T >
OwningVector< T >::OwningVector ( const std::vector< T * > &  v)
inline

Constructor that takes over ownership of elements in given vector.

Definition at line 39 of file OwningVector.h.

40  {
41  m_v.reserve(v.size());
42  for (T* e : v)
43  m_v.emplace_back(e);
44  }
std::vector< T * > m_v
Definition: OwningVector.h:98

References OwningVector< T >::m_v.

◆ OwningVector() [3/3]

template<class T >
OwningVector< T >::OwningVector ( const OwningVector< T > &  other)
inline

Constructor that clones elements in given vector.

Definition at line 46 of file OwningVector.h.

47  {
48  m_v.reserve(other.size());
49  for (T* e : other)
50  m_v.emplace_back(e->clone());
51  }
size_t size() const
Definition: OwningVector.h:70

References OwningVector< T >::m_v, and OwningVector< T >::size().

Here is the call graph for this function:

◆ ~OwningVector()

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

Definition at line 52 of file OwningVector.h.

52 { clear(); }
void clear()
Definition: OwningVector.h:63

References OwningVector< T >::clear().

Here is the call graph for this function:

Member Function Documentation

◆ at()

template<class T >
T* const& OwningVector< T >::at ( int  i) const
inline

◆ back()

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

Definition at line 74 of file OwningVector.h.

74 { return m_v.back(); }

References OwningVector< T >::m_v.

Referenced by MultiLayer::addLayerWithTopRoughness().

◆ begin() [1/2]

template<class T >
Iterator OwningVector< T >::begin ( )
inline

Definition at line 94 of file OwningVector.h.

94 { return m_v.begin(); }

References OwningVector< T >::m_v.

◆ begin() [2/2]

template<class T >
ConstIterator OwningVector< T >::begin ( ) const
inline

Definition at line 92 of file OwningVector.h.

92 { return m_v.begin(); }

References OwningVector< T >::m_v.

◆ clear()

template<class T >
void OwningVector< T >::clear ( )
inline

Definition at line 63 of file OwningVector.h.

64  {
65  for (T* e : *this)
66  delete e;
67  m_v.clear();
68  }

References OwningVector< T >::m_v.

Referenced by OwningVector< T >::~OwningVector(), and IDetector::clear().

◆ cloned_vector()

template<class T >
std::vector<T*> OwningVector< T >::cloned_vector ( ) const
inline

Definition at line 81 of file OwningVector.h.

82  {
83  std::vector<T*> ret;
84  for (T* e : m_v)
85  ret.emplace_back(e->clone());
86  return ret;
87  }

References OwningVector< T >::m_v.

Referenced by Frame::cloned_axes().

◆ const_vector()

template<class T >
std::vector<const T*> OwningVector< T >::const_vector ( ) const
inline

Definition at line 76 of file OwningVector.h.

77  {
78  const std::vector<const T*> ret(m_v.begin(), m_v.end());
79  return ret;
80  }

References OwningVector< T >::m_v.

◆ emplace_back()

◆ empty()

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

Definition at line 71 of file OwningVector.h.

71 { return m_v.empty(); }

References OwningVector< T >::m_v.

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

◆ end() [1/2]

template<class T >
Iterator OwningVector< T >::end ( )
inline

Definition at line 95 of file OwningVector.h.

95 { return m_v.end(); }

References OwningVector< T >::m_v.

◆ end() [2/2]

template<class T >
ConstIterator OwningVector< T >::end ( ) const
inline

Definition at line 93 of file OwningVector.h.

93 { return m_v.end(); }

References OwningVector< T >::m_v.

◆ operator=()

template<class T >
OwningVector& OwningVector< T >::operator= ( const OwningVector< T > &  other)
inline

Definition at line 53 of file OwningVector.h.

54  {
55  if (this == &other)
56  return *this;
57  OwningVector ret(other);
58  std::swap(m_v, ret.m_v);
59  return *this;
60  }
A vector of unique pointers to objects that are cloneable.
Definition: OwningVector.h:35

References OwningVector< T >::m_v.

◆ operator[]()

template<class T >
T* const& OwningVector< T >::operator[] ( int  i) const
inline

Definition at line 72 of file OwningVector.h.

72 { return m_v.operator[](i); }

References OwningVector< T >::m_v.

◆ size()

Member Data Documentation

◆ m_v


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