Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

KeyMutableSet< Key, T, _Compare > Class Template Reference

This set inherits from the STL multiset, with a slight variation: You are allowed to update the key of a particular iterator that you have obtained. More...

#include <key_mutable_set.h>

Inherits multiset< KeyMutableShell< T >, _Compare >.

Inheritance diagram for KeyMutableSet:

Inheritance graph
[legend]
Collaboration diagram for KeyMutableSet< Key, T, _Compare >:

Collaboration graph
[legend]
List of all members.

Public Methods

SUPER::iterator find (T &key)
 This allows you to find an item given a Key. More...

SUPER::iterator find (const Key &key)
 This allows you to find an item given a Key. More...

SUPER::iterator lower_bound (T &key)
 This allows you to find the first item that has AT LEAST the value of a Key . More...

SUPER::iterator lower_bound (const Key &key)
 This allows you to find the first item that has AT LEAST the value of a Key . More...

SUPER::iterator upper_bound (T &key)
 This allows you to find the first item that has MORE THAN the value of a Key . More...

SUPER::iterator upper_bound (const Key &key)
 This allows you to find the first item that has MORE THAN the value of a Key . More...

void checkSet ()
 This just checks the order of the set for testing purposes.. More...

SUPER::iterator changeKey (typename SUPER::iterator iter, const Key &newKey)
 Given an iterator you can alter that iterator's key to be the one passed in. More...


Private Types

typedef std::multiset< KeyMutableShell<
T >, _Compare > 
SUPER

Private Methods

T & valueFromKey (const Key &key)

Detailed Description

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
class KeyMutableSet< Key, T, _Compare >

This set inherits from the STL multiset, with a slight variation: You are allowed to update the key of a particular iterator that you have obtained.

Note: T is the type that each element is pointing to. The template argument should not be a pointer, but the type when added will be T* .


Member Typedef Documentation

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
typedef std::multiset<KeyMutableShell<T>,_Compare> KeyMutableSet< Key, T, _Compare >::SUPER [private]
 


Member Function Documentation

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
SUPER::iterator KeyMutableSet< Key, T, _Compare >::changeKey typename SUPER::iterator    iter,
const Key &    newKey
[inline]
 

Given an iterator you can alter that iterator's key to be the one passed in.

The type must have a function called changeKey(const Key &newKey) that changes its key to the specified new key.

00081                                                                                        {
00082         typename SUPER::iterator templess=iter,tempmore=iter;
00083         tempmore++;
00084         if (templess!=begin())
00085             templess--;
00086         _Compare comparator;
00087         KeyMutableShell<T> newKeyShell(&valueFromKey(newKey));
00088         bool endOutOfOrder=false;
00089         if (tempmore!=end()) {
00090             endOutOfOrder=comparator(*tempmore,newKeyShell);
00091         }
00092         if (comparator(newKeyShell,*templess)||endOutOfOrder) {
00093             KeyMutableShell<T> k = *iter;
00094             erase(iter);
00095             k->changeKey(newKey);
00096             insert (k);
00097         }else {
00098             (*iter)->changeKey(newKey);
00099         }
00100         //checkSet();
00101         return tempmore;
00102     }

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
void KeyMutableSet< Key, T, _Compare >::checkSet   [inline]
 

This just checks the order of the set for testing purposes..

00067                      {
00068         _Compare comparator;
00069         if (begin()!=end()) {
00070             for (typename SUPER::iterator newiter=begin(), iter=newiter++;newiter!=end();iter=newiter++) {
00071                 if (comparator(*newiter,*iter)) { //greater than
00072                     printf("ERROR: keys out of order!!!!!!\n");
00073                 }
00074             }
00075         }
00076     }

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
SUPER::iterator KeyMutableSet< Key, T, _Compare >::find const Key &    key [inline]
 

This allows you to find an item given a Key.

00047                                                  {
00048         return find(valueFromKey(key));
00049     }

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
SUPER::iterator KeyMutableSet< Key, T, _Compare >::find T &    key [inline]
 

This allows you to find an item given a Key.

00043                                          {
00044     return SUPER::find(KeyMutableShell<T>(&key));
00045     }

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
SUPER::iterator KeyMutableSet< Key, T, _Compare >::lower_bound const Key &    key [inline]
 

This allows you to find the first item that has AT LEAST the value of a Key .

00055                                                         {
00056         return lower_bound(valueFromKey(key));
00057     }

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
SUPER::iterator KeyMutableSet< Key, T, _Compare >::lower_bound T &    key [inline]
 

This allows you to find the first item that has AT LEAST the value of a Key .

00051                                                 {
00052         return SUPER::lower_bound(KeyMutableShell<T>(&key));
00053     }

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
SUPER::iterator KeyMutableSet< Key, T, _Compare >::upper_bound const Key &    key [inline]
 

This allows you to find the first item that has MORE THAN the value of a Key .

00063                                                         {
00064         return upper_bound(valueFromKey(key));
00065     }

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
SUPER::iterator KeyMutableSet< Key, T, _Compare >::upper_bound T &    key [inline]
 

This allows you to find the first item that has MORE THAN the value of a Key .

00059                                                 {
00060         return SUPER::upper_bound(KeyMutableShell<T>(&key));
00061     }

template<class Key, class T, class _Compare = std::less <KeyMutableShell<T> >>
T& KeyMutableSet< Key, T, _Compare >::valueFromKey const Key &    key [inline, private]
 

00036                                      {
00037         static T t;
00038         t.changeKey(key);
00039         return t;
00040     }


The documentation for this class was generated from the following file:
Generated on Mon Jul 7 21:13:53 2003 for Ethereal by doxygen1.2.15