2 #ifndef GAUDIKERNEL_VECTORMAP_H
3 #define GAUDIKERNEL_VECTORMAP_H 1
17 #include "GaudiKernel/MapBase.h"
20 #include "GaudiKernel/StatusCode.h"
21 #include "GaudiKernel/StringKey.h"
104 class KEYCOMPARE=std::less<const KEY> ,
105 class ALLOCATOR=std::allocator<std::pair<KEY,VALUE> >
118 typedef std::pair<key_type,mapped_type>
value_type ;
125 typedef typename ALLOCATOR::const_reference
reference ;
129 typedef typename ALLOCATOR::size_type
size_type ;
136 typedef std::vector<value_type,allocator_type>
_vector ;
141 typedef typename _vector::iterator
_iterator ;
146 typedef typename _vector::const_iterator
iterator ;
154 typedef std::pair<iterator,iterator>
iterators ;
164 struct _compare_type :
public key_compare
169 _compare_type (
const key_compare& cmp ) : key_compare ( cmp ) {}
173 bool operator () (
const key_type& k1 ,
const key_type& k2 )
const
174 {
return this->key_compare::operator() ( k1 , k2 ) ; }
176 bool operator() (
const value_type& v1 ,
const value_type& v2 )
const
179 bool operator() (
const key_type& k ,
const value_type& v )
const
182 bool operator() (
const value_type& v ,
const key_type & k )
const
226 size_type
erase (
const key_type& key )
228 iterator pos =
find ( key ) ;
229 if (
end() == pos ) {
return 0 ; }
239 size_type
erase ( iterator first ,
243 return last - first ;
266 template <
class TYPE>
267 size_type
erase ( TYPE first , TYPE last )
270 for ( ; first != last ; ++first ) { res +=
erase ( *first ) ; }
316 (
const key_type& key ,
317 const mapped_type& mapped )
318 {
return insert ( value_type ( key , mapped ) ) ; }
361 (
const value_type&
value )
365 if (
end() == result ||
compare( value.first , result -> first ) )
366 { result =
m_vct.insert ( result , value ) ; found = false ; }
380 const value_type& value )
382 if ( pos !=
end() &&
compare ( *pos , value ) &&
383 ( pos ==
end() - 1 ||
384 ( !
compare ( value , *( pos + 1 ) )
385 &&
compare ( *( pos + 1 ) , value ) ) ) )
401 const key_type& key ,
402 const mapped_type& mapped )
403 {
return insert ( pos , value_type ( key , mapped ) ) ; }
410 template <
class PAIRS>
414 {
for ( ; first != last ; ++first ) {
insert ( *first ) ; } }
423 template <
class KEYS,
class VALUES>
void insert
427 {
for ( ; kf != kl ; ++kf, ++vf ) {
insert ( *kf , *vf ) ; } }
454 iterator
find (
const key_type& key )
const
457 if (
end() != res &&
compare ( key , res->first ) )
477 size_type
count (
const key_type& key )
const
478 {
return end() ==
find ( key ) ? 0 : 1 ; }
484 iterators
equal_range (
const key_type& key )
const
498 void reserve ( size_type num ) {
m_vct.reserve ( num ) ; }
503 std::swap (
m_vct , other.m_vct ) ;
510 {
return m_vct == other.m_vct ; }
513 {
return m_vct < other.m_vct ; }
519 {
return right < left ; }
522 {
return !( left == right ) ; }
525 {
return !( left < right ) ; }
528 {
return !( right < left ) ; }
560 (
const key_type& key ,
561 const mapped_type& mapped )
564 if (
end() == result ||
compare ( key , result -> first ) )
569 else { result->second = mapped ; }
602 bool update (
const value_type& val )
603 {
return update ( val.first , val.second ) ; }
636 const mapped_type&
operator() (
const key_type& key )
const
638 static const mapped_type s_default =
mapped_type() ;
639 iterator res =
find ( key ) ;
640 if (
end() == res ) {
return s_default ; }
674 const mapped_type&
operator[] (
const key_type& key )
const
675 {
return (*
this)( key ) ; }
694 const mapped_type&
at (
const key_type& key )
const
696 iterator res =
find ( key ) ;
709 VectorMap (
const allocator_type& alloc = allocator_type () )
726 template <
class INPUT>
729 const allocator_type& alloc = allocator_type () )
730 :
m_vct ( first , last , alloc )
742 if ( &right ==
this ) {
return *this ; }
743 m_vct = right.m_vct ;
752 const compare_type&
compare ()
const
760 friend std::ostream&
operator<<
761 ( std::ostream& str ,
const VectorMap& ) {
return str ; }
768 for ( const_iterator it = right.begin() ; right.end() != it ; ++it )
769 {
update ( it->first , it->second ) ; }
774 template <
class K1,
class K2,
class K3,
class K4>
777 for (
typename VectorMap<K1,K2,K3,K4>::const_iterator it =
778 right.begin() ; right.end() != it ; ++it )
779 {
update ( it->first , it->second ) ; }
791 const key_type&
key_at (
const size_t index )
const
793 if ( index >=
size() )
795 const_iterator it = this->
begin() ;
796 std::advance ( it , index ) ;
804 const mapped_type&
value_at (
const size_t index )
const
806 if ( index >=
size() )
808 const_iterator it = this->
begin() ;
809 std::advance ( it , index ) ;
822 template <
class TYPE1,
class TYPE2>
823 bool compare (
const TYPE1& obj1 ,
824 const TYPE2& obj2 )
const
826 return compare() ( obj1 , obj2 ) ;
832 return std::lower_bound
837 _iterator
iter ( iterator p )
839 _iterator result =
m_vct.begin() ;
840 std::advance ( result , std::distance (
begin() , p ) ) ;
845 iterator
iter ( _iterator p )
847 iterator result (
begin() ) ;
848 std::advance ( result , std::distance (
m_vct.begin() , p ) ) ;
876 { left.
swap( right ) ; }
898 const std::string& input ) ;
912 const std::string& input ) ;
922 #endif // GAUDIKERNEL_MAPS_H
const mapped_type & operator[](const key_type &key) const
access to element by key (const version) there is no container increment for missing keys ...
A bit modified version of 'Loki::AssocVector' associative vector from Loki library by Andrei Alexandr...
friend bool operator!=(const VectorMap &left, const VectorMap &right)
bool operator==(const VectorMap &other) const
comparison criteria for containers
const mapped_type & at(const key_type &key) const
checked access to elements by key throw std::out_of_range exception for non-existing keys ...
const mapped_type & operator()(const key_type &key) const
access to element by key (const version) there is no container increment for missing keys ...
~VectorMap()
destructor (non-virtual!)
void reserve(size_type num)
reserve the space in the container for at least 'num' elements
_vector::iterator _iterator
the regular iterator (no export)
const key_type & key_at(const size_t index) const
useful method for python decoration:
_vector::const_iterator iterator
visible const_iterator (exported)
StatusCode parse(GaudiUtils::HashMap< K, V > &result, const std::string &input)
Basic parser for the types of HashMap used in DODBasicMapper.
bool operator()(const key_type &k1, const key_type &k2) const
compare keys: use key_compare
result_type insert(const key_type &key, const mapped_type &mapped)
insert the (key,value) pair into the container
size_type max_size() const
maximal allowed size
iterator find(const key_type &key) const
find the element by key
const key_compare & compare_key() const
get the comparison criteria for keys
reverse_iterator rbegin() const
"rbegin" iterator for sequential access (const-only version!)
std::pair< iterator, iterator > iterators
visible iterator pait
iterator lower_bound(const key_type &key) const
iterator end() const
"end" iterator for sequential access (const-only version!)
ALLOCATOR::const_reference reference
the types to conform STL
_vector m_vct
the underlying sorted vector of (key,mapped) pairs
std::reverse_iterator< const_iterator > const_reverse_iterator
visible reverse const_iterator (exported)
This class is used for returning status codes from appropriate routines.
iterator begin() const
"begin" iterator for sequential access (const-only version!)
_compare_type()
default constructor
friend bool operator>=(const VectorMap &left, const VectorMap &right)
std::reverse_iterator< iterator > reverse_iterator
visible reverse const_iterator (exported)
friend bool operator>(const VectorMap &left, const VectorMap &right)
std::pair< iterator, bool > result_type
visible iterator pait
ALLOCATOR::const_reference const_reference
the types to conform STL
friend bool operator<=(const VectorMap &left, const VectorMap &right)
reverse_iterator rend() const
"rend" iterator for sequential access (const-only version!)
VALUE mapped_type
the actual type of value
_compare_type compare_type
the actual comparison criteria for valye_type objects
_vector::const_iterator const_iterator
visible const_iterator (exported)
iterator upper_bound(const key_type &key) const
bool operator<(const VectorMap &other) const
comparison criteria for containers
VectorMap & operator=(const VectorMap &right)
size_type count(const key_type &key) const
count number of elements with the certain key
const compare_type & compare() const
get the comparison criteria itself
ALLOCATOR allocator_type
allocator (could be useful for optimizations)
Forward declarations for the functions in SerializeSTL.h.
_iterator iter(iterator p)
the conversion from 'const' to 'non-const' iterator
bool update(const key_type &key, const mapped_type &mapped)
forced insertion of the key/mapped pair The method acts like "insert" but it DOES overwrite the exist...
KEYCOMPARE key_compare
comparison of keys
void clear()
clear the container
KEY key_type
the actual type of key
void throw_out_of_range_exception() const
throw std::out_of_range exception
void swap(VectorMap &other)
swap function, which 'swaps' the content of two containers
ALLOCATOR::difference_type difference_type
the types to conform STL
bool empty() const
empty container ?
iterators equal_range(const key_type &key) const
std::pair< key_type, mapped_type > value_type
the actual storage item
VectorMap & merge(const VectorMap &right)
merge two maps
Helper base-class to allow the generic Python-decoration for all "map-like" classes in Gaudi...
ALLOCATOR::size_type size_type
the types to conform STL
void erase(iterator pos)
erase the element using the iterator
Helper functions to set/get the application return code.
VectorMap(const allocator_type &alloc=allocator_type())
default constructor from the the allocator
size_type size() const
number of elements
std::vector< value_type, allocator_type > _vector
the actual storage container (no export)
const mapped_type & value_at(const size_t index) const
useful method for python decoration: