OpenMS
ExposedVector< VectorElement > Class Template Reference

Makes a vector<VectorElement> available in the derived class and exposed commonly used vector member functions at class level. More...

#include <OpenMS/DATASTRUCTURES/ExposedVector.h>

Inheritance diagram for ExposedVector< VectorElement >:
[legend]
Collaboration diagram for ExposedVector< VectorElement >:
[legend]

Public Types

using VecMember = std::vector< VectorElement >
 
using value_type = typename VecMember::value_type
 
using iterator = typename VecMember::iterator
 
using const_iterator = typename VecMember::const_iterator
 
using reverse_iterator = typename VecMember::reverse_iterator
 
using const_reverse_iterator = typename VecMember::const_reverse_iterator
 
using size_type = typename VecMember::size_type
 
using pointer = typename VecMember::pointer
 
using reference = typename VecMember::reference
 
using const_reference = typename VecMember::const_reference
 
using difference_type = typename VecMember::difference_type
 

Public Member Functions

 ExposedVector ()=default
 
 ExposedVector (const size_t n)
 
 ExposedVector (const size_t n, const VectorElement &val)
 
template<class Iter >
 ExposedVector (Iter begin, Iter end)
 
 ExposedVector (const ExposedVector &rhs)=default
 Copy C'tor. More...
 
 ExposedVector (ExposedVector &&rhs) noexcept=default
 Move C'tor. More...
 
ExposedVectoroperator= (const ExposedVector &rhs)=default
 Assignment. More...
 
ExposedVectoroperator= (ExposedVector &&rhs) noexcept=default
 Move Assignment. More...
 
iterator begin () noexcept
 
iterator end () noexcept
 
const_iterator begin () const noexcept
 
const_iterator end () const noexcept
 
const_iterator cbegin () const noexcept
 
const_iterator cend () const noexcept
 
size_t size () const noexcept
 
void resize (const size_t new_size)
 
void reserve (const size_t new_size)
 
bool empty () const noexcept
 
VectorElement & operator[] (size_t i) noexcept
 
const VectorElement & operator[] (size_t i) const noexcept
 
VectorElement & at (size_t i)
 
const VectorElement & at (size_t i) const
 
VectorElement & back () noexcept
 
const VectorElement & back () const noexcept
 
void push_back (const VectorElement &f)
 
void push_back (VectorElement &&f)
 
template<typename... Args>
decltype(auto) emplace_back (Args &&... args)
 
void pop_back () noexcept
 
iterator erase (const_iterator where) noexcept
 
iterator erase (const_iterator from, const_iterator to) noexcept
 
template<typename T >
iterator insert (const_iterator where, T from, T to)
 
const VecMembergetData () const
 read-only access to the underlying data More...
 
VecMembergetData ()
 read access to the underlying data More...
 

Protected Attributes

VecMember data_
 the container which holds all the data More...
 

Detailed Description

template<class VectorElement>
class OpenMS::ExposedVector< VectorElement >

Makes a vector<VectorElement> available in the derived class and exposed commonly used vector member functions at class level.

This saves writing repetitive code which forwards commonly used functions of a data member, e.g. 'data_.begin()' as a member function of the class. Also it makes private inheritance from vector<VectorElement> obsolete. The latter is problematic for many reasons (read up on 'prefer composition over inheritance'). In our case, even linking can be problematic with private inheritance once you require RTTI (which some tools do, e.g. softwipe).

To fully utilize this class (i.e. access the 'iterator' type), insert

#define EXPOSED_VECTOR_INTERFACE(InnerElement)
Macro to expose common dependent types, such as iterator in the derived class.
Definition: ExposedVector.h:19

in your derived class, where VectorElement is identical to the template argument of ExposedVector, e.g. 'Feature' for FeatureMap.

Member Typedef Documentation

◆ const_iterator

using const_iterator = typename VecMember::const_iterator

◆ const_reference

using const_reference = typename VecMember::const_reference

◆ const_reverse_iterator

using const_reverse_iterator = typename VecMember::const_reverse_iterator

◆ difference_type

using difference_type = typename VecMember::difference_type

◆ iterator

using iterator = typename VecMember::iterator

◆ pointer

using pointer = typename VecMember::pointer

◆ reference

using reference = typename VecMember::reference

◆ reverse_iterator

using reverse_iterator = typename VecMember::reverse_iterator

◆ size_type

using size_type = typename VecMember::size_type

◆ value_type

using value_type = typename VecMember::value_type

◆ VecMember

using VecMember = std::vector<VectorElement>

Constructor & Destructor Documentation

◆ ExposedVector() [1/6]

ExposedVector ( )
default

◆ ExposedVector() [2/6]

ExposedVector ( const size_t  n)
inlineexplicit

◆ ExposedVector() [3/6]

ExposedVector ( const size_t  n,
const VectorElement &  val 
)
inline

◆ ExposedVector() [4/6]

ExposedVector ( Iter  begin,
Iter  end 
)
inline

◆ ExposedVector() [5/6]

ExposedVector ( const ExposedVector< VectorElement > &  rhs)
default

Copy C'tor.

◆ ExposedVector() [6/6]

ExposedVector ( ExposedVector< VectorElement > &&  rhs)
defaultnoexcept

Move C'tor.

Member Function Documentation

◆ at() [1/2]

VectorElement& at ( size_t  i)
inline

◆ at() [2/2]

const VectorElement& at ( size_t  i) const
inline

◆ back() [1/2]

const VectorElement& back ( ) const
inlinenoexcept

◆ back() [2/2]

VectorElement& back ( )
inlinenoexcept

◆ begin() [1/2]

const_iterator begin ( ) const
inlinenoexcept

◆ begin() [2/2]

iterator begin ( )
inlinenoexcept

◆ cbegin()

const_iterator cbegin ( ) const
inlinenoexcept

◆ cend()

const_iterator cend ( ) const
inlinenoexcept

◆ emplace_back()

decltype(auto) emplace_back ( Args &&...  args)
inline

◆ empty()

bool empty ( ) const
inlinenoexcept

◆ end() [1/2]

const_iterator end ( ) const
inlinenoexcept

◆ end() [2/2]

iterator end ( )
inlinenoexcept

◆ erase() [1/2]

iterator erase ( const_iterator  from,
const_iterator  to 
)
inlinenoexcept

◆ erase() [2/2]

iterator erase ( const_iterator  where)
inlinenoexcept

◆ getData() [1/2]

VecMember& getData ( )
inline

read access to the underlying data

References ExposedVector< VectorElement >::data_.

◆ getData() [2/2]

const VecMember& getData ( ) const
inline

read-only access to the underlying data

References ExposedVector< VectorElement >::data_.

◆ insert()

iterator insert ( const_iterator  where,
from,
to 
)
inline

◆ operator=() [1/2]

ExposedVector& operator= ( const ExposedVector< VectorElement > &  rhs)
default

Assignment.

◆ operator=() [2/2]

ExposedVector& operator= ( ExposedVector< VectorElement > &&  rhs)
defaultnoexcept

Move Assignment.

◆ operator[]() [1/2]

const VectorElement& operator[] ( size_t  i) const
inlinenoexcept

◆ operator[]() [2/2]

VectorElement& operator[] ( size_t  i)
inlinenoexcept

◆ pop_back()

void pop_back ( )
inlinenoexcept

◆ push_back() [1/2]

void push_back ( const VectorElement &  f)
inline

◆ push_back() [2/2]

void push_back ( VectorElement &&  f)
inline

◆ reserve()

void reserve ( const size_t  new_size)
inline

◆ resize()

void resize ( const size_t  new_size)
inline

◆ size()

size_t size ( ) const
inlinenoexcept

Member Data Documentation

◆ data_