1 #include "ace/Hash_Map_Manager.h"
2 #include "ace/Synch.h" // Needed for the lock
3 #include "ace/Functor.h"
4 #include "DataElement.h"
5 #include "Hash_Map_Hash.h"
8 template<class EXT_ID
, class INT_ID
>
10 public ACE_Hash_Map_Manager_Ex
<EXT_ID
, INT_ID
,
11 ACE_Hash
<EXT_ID
>, ACE_Equal_To
<EXT_ID
>, ACE_Null_Mutex
>
15 class Hash_Map_Example
23 // illustrate the hash map
26 // use the forward iterate
27 void iterate_forward ();
29 // use the reverse iterator
30 void iterate_reverse ();
32 // remove all the elements from the map
36 Hash_Map
<KeyType
, DataElement
> map_
;
39 int Hash_Map_Example::run ()
41 ACE_TRACE ("Hash_Map_Example::run");
43 for (int i
= 0; i
< 100; i
++)
45 map_
.bind (i
, DataElement (i
));
48 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Map has\n")));
49 for (int j
= 0; j
< 100; j
++)
53 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%d:"), d
.getData ()));
55 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
57 // Use the forward iterator.
58 this->iterate_forward ();
60 // Use the reverse iterator.
61 this->iterate_reverse ();
63 // Remove all the elements from the map.
66 // Iterate through the map again.
67 this->iterate_forward ();
72 void Hash_Map_Example::iterate_forward ()
74 ACE_TRACE ("Hash_Map_Example::iterate_forward");
76 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Forward Iteration\n")));
77 for (Hash_Map
<KeyType
, DataElement
>::iterator iter
= map_
.begin ();
78 iter
!= map_
.end (); iter
++)
80 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%d:"), (*iter
).int_id_
.getData ()));
82 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
85 void Hash_Map_Example::iterate_reverse ()
87 ACE_TRACE ("Hash_Map_Example::iterate_reverse");
89 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Reverse Iteration\n")));
90 for (Hash_Map
<KeyType
, DataElement
>::reverse_iterator iter
= map_
.rbegin ();
91 iter
!= map_
.rend (); iter
++)
93 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%d:"), (*iter
).int_id_
.getData ()));
95 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
98 void Hash_Map_Example::remove_all ()
100 ACE_TRACE ("Hash_Map_Example::remove_all");
104 int ACE_TMAIN (int, ACE_TCHAR
*[])