86 #ifndef DOXYGEN_COMPILE
88 template <
typename KeyType >
class SetvMember ;
90 template <
class ValueType ,
bool Forward >
class SetvIter ;
92 template <
class ValueType,
class KeyCompare,
class Allocator >
class Setv ;
97 class SetvMember<void> {
102 enum { black = 0 , red = 1 };
104 SetvMember<void> * parent ;
105 SetvMember<void> * left ;
106 SetvMember<void> * right ;
110 SetvMember<void>(
const SetvMember<void> & );
111 SetvMember<void> & operator = (
const SetvMember<void> & );
114 template<
bool Forward>
115 SetvMember<void> * setv_iterate(
const SetvMember<void> * );
118 SetvMember<void> * setv_iterate<true>(
const SetvMember<void> * );
121 SetvMember<void> * setv_iterate<false>(
const SetvMember<void> * );
137 template <
typename KeyType >
167 template<
class T ,
class C ,
class A >
friend class Setv ;
168 template<
class T ,
bool F >
friend class SetvIter ;
178 template <
class Type ,
bool Forward>
179 class SetvIter :
public std::iterator<std::bidirectional_iterator_tag,Type>
187 template <
class T ,
bool F >
friend class SetvIter ;
188 template <
class T ,
class C ,
class A >
friend class Setv ;
193 operator bool ()
const {
return n && n->parent ; }
206 template<
class T,
bool F>
208 { n = x.n ;
return *this ; }
211 template<
class T,
bool F>
215 template<
class T,
bool F>
220 {
return *(
operator bool() ? n :
reinterpret_cast<Type*
>(NULL) ); }
224 {
return (
operator bool() ? n : reinterpret_cast<Type*>(NULL) ); }
228 { n =
static_cast<Type*
>( setv_iterate<Forward>(n) );
return *this ; }
232 { n =
static_cast<Type*
>( setv_iterate<!Forward>(n) );
return *this ; }
238 n =
static_cast<Type*
>( setv_iterate<Forward>(n) );
246 n =
static_cast<Type*
>( setv_iterate<!Forward>(n) );
253 #ifndef DOXYGEN_COMPILE
256 class Setv<void,void,void> :
private SetvMember<void> {
258 friend class SetvMember<void> ;
263 size_t size()
const {
return m_size ; }
265 SetvMember<void> * nRoot()
const {
return m_header.parent ; }
267 SetvMember<void> * nEnd()
const
268 {
return const_cast<SetvMember<void>*
>( & m_right_end ); }
270 SetvMember<void> * nREnd()
const
271 {
return const_cast<SetvMember<void>*
>( & m_left_end ); }
273 SetvMember<void> * nBegin()
const
274 {
return ( m_left_end.right != nREnd() ) ? m_left_end.right : nEnd(); }
276 SetvMember<void> * nRBegin()
const
277 {
return ( m_right_end.left != nEnd() ) ? m_right_end.left : nREnd(); }
281 void insert( SetvMember<void> * y , SetvMember<void> * z ,
bool z_lt_y );
283 void remove( SetvMember<void> * );
285 SetvMember<void> * unbalancing_removal( SetvMember<void> ** n );
287 static Setv<void,void,void> *
container(
const SetvMember<void> * );
291 SetvMember<void> & m_header ;
292 SetvMember<void> m_left_end ;
293 SetvMember<void> m_right_end ;
317 template <
class ValueType ,
318 class KeyCompare = std::less<typename ValueType::key_type> ,
319 class Allocator = std::allocator<ValueType> >
334 #ifndef DOXYGEN_COMPILE
336 typedef typename allocator_type::reference reference ;
337 typedef typename allocator_type::const_reference const_reference ;
338 typedef typename allocator_type::pointer pointer ;
339 typedef typename allocator_type::const_pointer const_pointer ;
340 typedef typename allocator_type::size_type size_type ;
341 typedef typename allocator_type::difference_type difference_type ;
348 struct value_compare :
public std::binary_function<value_type,value_type,bool>
354 return comp( x.SetvMember<key_type>::key() ,
355 y.SetvMember<key_type>::key() );
366 :
Setv<void,void,void>(),
367 alloc(arg_alloc), key_less(arg_compare), value_less() {}
382 iterator begin()
const
388 static_cast<value_type*>( Setv<void,void,void>::nEnd() ) ); }
390 reverse_iterator rbegin()
const
391 {
return reverse_iterator(
392 static_cast<value_type*>( Setv<void,void,void>::nRBegin() ) ); }
394 reverse_iterator rend()
const
395 {
return reverse_iterator(
396 static_cast<value_type*>( Setv<void,void,void>::nREnd() ) ); }
418 std::pair<iterator,bool>
425 void erase( iterator position );
450 size_type
max_size()
const {
return alloc.max_size(); }
486 value_compare value_less ;
495 #ifndef DOXYGEN_COMPILE
501 template<
class T,
class C,
class M>
506 template<
class T,
class C,
class M>
508 std::pair<typename Setv<T,C,M>::iterator,
bool>
514 const typename Setv<T,C,M>::key_type & k = v->key();
523 x = ( flag = key_less( k , static_cast<MemberType*>(x)->key() ) )
524 ? x->left : x->right ;
529 const bool k_lt_y = flag ;
531 x = flag && y != nBegin() ? ( flag = false , setv_iterate<false>(y) ) : y ;
533 if ( flag || ( flag = key_less(static_cast<MemberType*>(x)->key(),k) ) ) {
538 v =
static_cast<typename Setv<T,C,M>::value_type*
>( x );
541 return std::pair<typename Setv<T,C,M>::iterator,
bool>( iterator(v), flag );
544 template<
class T,
class C,
class M>
546 std::pair<typename Setv<T,C,M>::iterator,
bool>
548 typename Setv<T,C,M>::value_type * v )
557 x = ( flag = key_less( k , static_cast<MemberType*>(x)->key() ) )
558 ? x->left : x->right ;
563 const bool k_lt_y = flag ;
565 x = flag && y != nBegin() ? ( flag = false , setv_iterate<false>(y) ) : y ;
567 if ( flag || ( flag = key_less(static_cast<MemberType*>(x)->key(),k) ) ) {
569 v = alloc.allocate(1);
572 v->SetvMember<key_type>::m_key = k ;
577 v =
static_cast<typename Setv<T,C,M>::value_type*
>( x );
579 return std::pair<typename Setv<T,C,M>::iterator,
bool>( iterator(v), flag );
582 template<
class T,
class C,
class M>
584 typename Setv<T,C,M>::value_type &
587 std::pair<typename Setv<T,C,M>::iterator,
bool> result = insert(k);
588 return *result.second ;
591 template<
class T,
class C,
class M>
597 alloc.deallocate( p , 1 );
600 template<
class T,
class C,
class M>
604 if ( p.operator
bool() ) { erase( p.n ); }
607 template<
class T,
class C,
class M>
609 typename Setv<T,C,M>::size_type
612 iterator i = find(k);
613 return i != end() ? ( erase( i ) , 1 ) : 0 ;
616 template<
class T,
class C,
class M>
619 if ( Setv<void,void,void>::size() ) {
622 while ( ( t = Setv<void,void,void>::unbalancing_removal( &n ) ) ) {
623 alloc.destroy( static_cast<value_type*>(t) );
624 alloc.deallocate( static_cast<value_type*>(t) , 1 );
627 Setv<void,void,void>::initialize();
630 template<
class T,
class C,
class M>
632 typename Setv<T,C,M>::iterator
637 while ( x ) x = key_less(static_cast<MemberType*>(x)->key(),k)
638 ? x->right : ( y = x )->left ;
639 return iterator( static_cast<value_type*>(y) );
642 template<
class T,
class C,
class M>
644 typename Setv<T,C,M>::iterator
649 while ( x ) x = key_less(k,static_cast<MemberType*>(x)->key())
650 ? ( y = x )->left : x->right ;
651 return iterator( static_cast<value_type*>(y) );
654 template<
class T,
class C,
class M>
656 typename Setv<T,C,M>::iterator
659 typename Setv<T,C,M>::iterator i = lower_bound(k);
662 if ( i != end() && key_less(k,(*i).MemberType::key()) ) i = end();
667 template<
class T,
class C,
class M>
669 typename Setv<T,C,M>::size_type
672 typename Setv<T,C,M>::iterator i = lower_bound(k);
673 return i == end() || key_less(k,(*i).SetvMember<T>::key()) ? 0 : 1 ;
676 template<
class T,
class C,
class M>
679 : Setv<void,void,void>()
681 for ( const_iterator i = V.begin() ; i != V.end() ; ++i ) {
682 pointer a = alloc.allocate(1);
683 alloc.construct(a,*i);
684 insert( i->SetvMember<key_type>::key() , a );
688 template<
class T,
class C,
class M>
694 for ( const_iterator i = V.begin() ; i != V.end() ; ++i ) {
695 pointer a = alloc.allocate(1);
696 alloc.construct(a,*i);
697 insert( i->SetvMember<key_type>::key() , a );
702 template<
class T,
class C,
class M>
708 return c ?
static_cast<Setv<T,C,M>*
>( c ) :
709 reinterpret_cast<Setv<T,C,M>*
>( NULL );
712 template<
class T,
class C,
class M>
716 size_type count = 0 ;
717 iterator i = begin();
720 while ( i != end() &&
721 ( ++(j=i) == end() || key_less( i->MemberType::key() ,
722 j->MemberType::key() ) )
726 return ( i == end() && count == size() );
value_type & operator[](const key_type &key)
Retrieve or create a value with the given key.
bool operator!=(const SetvIter< T, F > &y) const
Return if not pointing to the same entity.
bool empty() const
Query if container is empty.
const key_type & key() const
size_type max_size() const
Query capacity.
Type * operator->() const
Pointer to a valid entity, null otherwise.
bool operator==(const SetvIter< T, F > &y) const
Return if pointing to the same entity.
value_compare value_comp() const
Comparison operator for key type via the value type.
SetvIter()
Default constructor to NULL entity.
std::pair< iterator, bool > insert(const key_type &key, value_type *value=NULL)
Inserts the given entity with key() == key.
allocator_type get_allocator() const
Allocator.
bool verify_ordering() const
Verify that iteration of the container is properly ordered.
SetvIter< Type, Forward > & operator--()
Decrement to the previous entity.
key_compare key_comp() const
Comparison operator for key type.
static Setv< value_type, key_compare, allocator_type > * container(const value_type &)
Query the container for a given member.
SetvIter(const SetvIter< T, F > &x)
Copy from other similar iterators. Compilation will fail when assigning non-const to const...
void erase(iterator position)
Destroys the member referenced by the iterator.
SetvIter< Type, Forward > & operator=(const SetvIter< T, F > &x)
Assign from other similar iterators. Compilation will fail when assigning non-const to const...
iterator find(const key_type &) const
Find a member with a given key.
SetvIter< Type, Forward > operator++(int)
Return this iterator and then increment to the next entity.
iterator lower_bound(const key_type &) const
First member with key equal to or greater than the given key.
SetvMember(const KeyType &k)
size_type size() const
Query number of members.
ValueType::key_type key_type
Type of the comparison keys, obtained from the member class.
KeyCompare key_compare
Key comparison operator.
Template class for the Setv bidirectional iterators.
ValueType value_type
Type of the members.
Setv< value_type, key_compare, allocator_type > & operator=(const Setv< value_type, key_compare, allocator_type > &)
Assignment.
SetvIter< Type, Forward > & operator++()
Increment to the next entity.
Associative container of explictly managed entities.
Type & operator*() const
Reference to a valid entity, null otherwise.
SetvIter< Type, Forward > operator--(int)
Return this iterator and then decrement to the previous entity.
Allocator allocator_type
Allocator class.
Base class for Setv members.Objects stored in a Setv container must be derived from this template bas...
void clear()
Destroys all members.
iterator upper_bound(const key_type &) const
Last member with key greater than or equal to the given key.
Setv(const key_compare &arg_compare=key_compare(), const allocator_type &arg_alloc=allocator_type())
Construct with comparison and allocator.
size_type count(const key_type &) const
Count number of members with a given key, zero or one.
SetvMember(const SetvMember< key_type > &rhs)
void remove(value_type &v)
Removes the member from container but does not destroy it. The caller assumes responsibility for the ...