#include <OTC/collctn/uniqmap.hh> template<class T1, class T2> class OTC_UniqMap {
public:
static os_typespec* get_os_typespec();
~OTC_UniqMap();
typedef int (*type1)(T1 const&,T1 const&);
typedef int (*type2)(T2 const&,T2 const&);
OTC_UniqMap(type1 theKeyRankFn=0, type2 theItemRankFn=0);
OTC_UniqMap(int (*theKeyRankFn)( T1 const&, T1 const&)=0, int (*theItemRankFn)(T2 const&, T2 const&)=0 );
OTC_UniqMap(OTC_UniqMap<T1,T2> const& theMap);
void removeAll();
OTC_UniqMap<T1,T2>& operator=(OTC_UniqMap<T1,T2> const& theMap);
void add(T1 const& theKey, T2 const& theItem);
void removeKey(T1 const& theKey);
void removeItem(T2 const& theItem);
OTC_Boolean containsKey(T1 const& theKey) const;
OTC_Boolean containsItem(T2 const& theItem) const;
T2 const& item(T1 const& theKey) const;
T1 const& key(T2 const& theItem) const;
T1 const& pickKey() const;
T2 const& pickItem() const;
inline u_int population() const;
inline OTC_Boolean isEmpty() const;
OTC_Iterator<T1> keys( OTC_Direction theDirection=OTCLIB_FORWARD, OTC_Protection theProtection=OTCLIB_SAFE ) const;
OTC_Iterator<T2> items( OTC_Direction theDirection=OTCLIB_FORWARD, OTC_Protection theProtection=OTCLIB_SAFE ) const;
OTC_PairIterator<T1,T2> pairs( OTC_Direction theDirection=OTCLIB_FORWARD, OTC_Protection theProtection=OTCLIB_SAFE ) const;
};
OTC_HashActions
class.
OTC_UniqMap(int (*theKeyRankFn)(
T1 const&,
T1 const&)=0,
int (*theItemRankFn)(T2 const&,
T2 const&)=0
);
theKeyRankFn
and theItemRankFn
are rank functions,
which if provided will override the
OTC_RankActions
class.
OTC_UniqMap(OTC_UniqMap<T1,T2> const& theMap);
theMap
.
void removeAll();
OTC_UniqMap<T1,T2>& operator=(OTC_UniqMap<T1,T2> const& theMap);
theMap
.
Returns a reference to this map.
void add(T1 const& theKey, T2 const& theItem);
theKey
does
not exist in this map and theItem
does
not already exist in the map, then
theItem
will be entered into this map.
If an item corresponding to theKey
already exiss, or theItem
already
exists, an exception will be raised.
void removeKey(T1 const& theKey);
theKey
exists in this map, the key/item pair will
be removed. If an item corresponding to
theKey
does not exist, an exception will
be raised.
void removeItem(T2 const& theItem);
theItem
exists
in this map, the key/item pair will be
removed. If a key corresponding to
theItem
does not exist, an exception
will be raised.
OTC_Boolean containsKey(T1 const& theKey) const;
OTCLIB_TRUE
if this map contains
an item corresponding to theKey
.
OTC_Boolean containsItem(T2 const& theItem) const;
OTCLIB_TRUE
if this map contains
a key corresponding to theItem
.
T2 const& item(T1 const& theKey) const;
theKey
exists in this map, a reference to
the item will be returned. If an item
corresponding to theKey
does not exist,
an exception will be raised.
T1 const& key(T2 const& theItem) const;
theItem
exists in this map, a reference to the key
will be returned. If a key corresponding
to theItem
does not exist, an exception
will be raised.
T1 const& pickKey() const;
T2 const& pickItem() const;
inline u_int population() const;
inline OTC_Boolean isEmpty() const;
OTCLIB_TRUE
if the collection is
empty.
OTCLIB_SAFE
or OTCLIB_UNSAFE
.
To get an unsafe iterator, the OTCLIB_UNSAFE
argument should
be used.
The first argument to the following functions indicates the
direction of traversal of the iterator. Traversal in the
direction of first to last item is indicated by a value of
OTCLIB_FORWARD
. Traversal in the reverse direction is
indicated by a value of OTCLIB_BACKWARD
. The default value
is OTCLIB_FORWARD
. In the OTC_Map
class, traversal in
the forward direction will result in the first key/item being
accessible being the oldest key/item in the set. Moving the
iterator will result in successively newer key/items in the set
being accessible.
When iterating over items, in the order in which they were
inserted, be very careful about inserting new items into the set.
This is because any new items inserted, will also be seen by the
iterator. If you were inserting a new item for every item seen,
you would end up with an infinite loop.
OTC_Iterator<T1> keys(
OTC_Direction theDirection=OTCLIB_FORWARD,
OTC_Protection theProtection=OTCLIB_SAFE
) const;
theDirection
. If
theDirection
is set to OTCLIB_FORWARD
,
keys will be visited in the order in
which they were inserted. If
theDirection
is OTCLIB_BACKWARD
,
keys will be visited in the reverse order.
The default direction is forward.
OTC_Iterator<T2> items(
OTC_Direction theDirection=OTCLIB_FORWARD,
OTC_Protection theProtection=OTCLIB_SAFE
) const;
theDirection
. If
theDirection
is set to OTCLIB_FORWARD
,
items will be visited in the order in
which they were inserted. If
theDirection
is OTCLIB_BACKWARD
,
items will be visited in the reverse order.
OTC_PairIterator<T1,T2> pairs(
OTC_Direction theDirection=OTCLIB_FORWARD,
OTC_Protection theProtection=OTCLIB_SAFE
) const;
theDirection
. If theDirection
is set
to OTCLIB_FORWARD
, key/item pairs will
be visited in the order in which they were
inserted. If theDirection
is
OTCLIB_BACKWARD
, key/item pairs will be
visited in the reverse order. The default
direction is forward.
OTC_UniqMap<EX_Foo const*,EX_Bar const*>
and not just
OTC_Map<EX_Foo*,EX_Bar*>
. If this is not done, it would be
possible for a user to modify parts of the key or item from which
the hash value is generated. If the hash value for an object is
changed, the key or item will no longer be accessible.
The OTC_Bucket
class is used internally to hold both key and
items. Thus the OTC_BaseActions
class may be used to provide
actions to be performed when items are inserted or removed from
the map.
Since an attempt to access or remove objects which are not in the
map will raise an exception, it is important first to check that
an object is actually in the map using the appropriate
contains()
function.
OTC_Iterator
, OTC_Bucket
, OTC_BaseActions
,
OTC_HashActions
, OTC_RankActions