ATLAS Offline Software
Loading...
Searching...
No Matches
LookUpTable< T, C > Class Template Reference

Generic lookup table. More...

#include <LookUpTable.h>

Collaboration diagram for LookUpTable< T, C >:

Public Types

typedef T val_type
typedef std::vector< val_typevec_type
typedef std::pair< val_type, val_typepair_type
typedef vec_type::iterator vec_type_it
typedef vec_type::const_iterator vec_type_cit

Public Member Functions

 LookUpTable ()=default
 ~LookUpTable ()=default
bool empty () const
void setData (const vec_type &data)
const vec_typegetData () const
vec_type_it begin ()
vec_type_it end ()
vec_type_cit begin () const
vec_type_cit end () const
vec_type_cit lowerBound (const val_type &val)
pair_type find (const val_type &val) const
template<class CC>
pair_type find (const val_type &val, const CC &c) const

Private Attributes

vec_type m_data

Detailed Description

template<class T, class C = std::less<T>>
class LookUpTable< T, C >

Generic lookup table.

Uses comparison function objects or the < operator to sort and look up values in the table.

Definition at line 21 of file LookUpTable.h.

Member Typedef Documentation

◆ pair_type

template<class T, class C = std::less<T>>
typedef std::pair<val_type, val_type> LookUpTable< T, C >::pair_type

Definition at line 25 of file LookUpTable.h.

◆ val_type

template<class T, class C = std::less<T>>
typedef T LookUpTable< T, C >::val_type

Definition at line 23 of file LookUpTable.h.

◆ vec_type

template<class T, class C = std::less<T>>
typedef std::vector<val_type> LookUpTable< T, C >::vec_type

Definition at line 24 of file LookUpTable.h.

◆ vec_type_cit

template<class T, class C = std::less<T>>
typedef vec_type::const_iterator LookUpTable< T, C >::vec_type_cit

Definition at line 28 of file LookUpTable.h.

◆ vec_type_it

template<class T, class C = std::less<T>>
typedef vec_type::iterator LookUpTable< T, C >::vec_type_it

Definition at line 27 of file LookUpTable.h.

Constructor & Destructor Documentation

◆ LookUpTable()

template<class T, class C = std::less<T>>
LookUpTable< T, C >::LookUpTable ( )
default

◆ ~LookUpTable()

template<class T, class C = std::less<T>>
LookUpTable< T, C >::~LookUpTable ( )
default

Member Function Documentation

◆ begin() [1/2]

template<class T, class C = std::less<T>>
vec_type_it LookUpTable< T, C >::begin ( )
inline

Definition at line 38 of file LookUpTable.h.

38{ return m_data.begin(); }
vec_type m_data
Definition LookUpTable.h:57

◆ begin() [2/2]

template<class T, class C = std::less<T>>
vec_type_cit LookUpTable< T, C >::begin ( ) const
inline

Definition at line 40 of file LookUpTable.h.

40{ return m_data.begin(); }

◆ empty()

template<class T, class C = std::less<T>>
bool LookUpTable< T, C >::empty ( ) const
inline

Definition at line 33 of file LookUpTable.h.

33{ return m_data.empty(); }

◆ end() [1/2]

template<class T, class C = std::less<T>>
vec_type_it LookUpTable< T, C >::end ( )
inline

Definition at line 39 of file LookUpTable.h.

39{ return m_data.end(); }

◆ end() [2/2]

template<class T, class C = std::less<T>>
vec_type_cit LookUpTable< T, C >::end ( ) const
inline

Definition at line 41 of file LookUpTable.h.

41{ return m_data.end(); }

◆ find() [1/2]

template<class T, class C>
LookUpTable< T, C >::pair_type LookUpTable< T, C >::find ( const val_type & val) const
inline

Definition at line 71 of file LookUpTable.h.

71 {
72 vec_type_cit it = lower_bound(m_data.begin(), m_data.end(), val, C());
73 if (it == m_data.end())
74 return std::make_pair(*(it - 2), *(it - 1));
75 else if (it == m_data.begin())
76 return std::make_pair(*it, *(it + 1));
77 else
78 return std::make_pair(*(it - 1), *it);
79}
Generic lookup table.
Definition LookUpTable.h:21
vec_type::const_iterator vec_type_cit
Definition LookUpTable.h:28

◆ find() [2/2]

template<class T, class C = std::less<T>>
template<class CC>
pair_type LookUpTable< T, C >::find ( const val_type & val,
const CC & c ) const
inline

Definition at line 46 of file LookUpTable.h.

46 {
47 vec_type_cit it = lower_bound(m_data.begin(), m_data.end(), val, c);
48 if (it == m_data.end())
49 return std::make_pair(*(it - 2), *(it - 1));
50 else if (it == m_data.begin())
51 return std::make_pair(*it, *(it + 1));
52 else
53 return std::make_pair(*(it - 1), *it);
54 }

◆ getData()

template<class T, class C = std::less<T>>
const vec_type & LookUpTable< T, C >::getData ( ) const
inline

Definition at line 36 of file LookUpTable.h.

36{ return m_data; }

◆ lowerBound()

template<class T, class C>
LookUpTable< T, C >::vec_type_cit LookUpTable< T, C >::lowerBound ( const val_type & val)
inline

Definition at line 65 of file LookUpTable.h.

65 {
66 vec_type_cit it = lower_bound(m_data.begin(), m_data.end(), val, C());
67 if (it == m_data.end()) return m_data.end() - 1;
68 return it;
69}

◆ setData()

template<class T, class C>
void LookUpTable< T, C >::setData ( const vec_type & data)
inline

Definition at line 60 of file LookUpTable.h.

60 {
61 m_data.assign(data.begin(), data.end());
62 sort(m_data.begin(), m_data.end(), C());
63}
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
vec_type_it end()
Definition LookUpTable.h:39
vec_type_it begin()
Definition LookUpTable.h:38

Member Data Documentation

◆ m_data

template<class T, class C = std::less<T>>
vec_type LookUpTable< T, C >::m_data
private

Definition at line 57 of file LookUpTable.h.


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