1 #include "ace/Log_Msg.h"
2 #include "ace/Map_Manager.h"
4 #include "DataElement.h"
10 // Illustrate the ACE_Map_Manager.
14 // Iterate in the forward direction.
15 void iterate_forward ();
17 // Iterate in the other direction.
18 void iterate_reverse ();
20 // Remove all elements from the map.
24 ACE_Map_Manager
<KeyType
,DataElement
,ACE_Null_Mutex
> map_
;
27 // Listing 2 code/ch05
28 int Map_Example::run ()
30 ACE_TRACE ("Map_Example::run");
32 // Corresponding KeyType objects are created on the fly.
33 for (int i
= 0; i
< 100; i
++)
35 map_
.bind (i
, DataElement (i
));
38 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Map has\n")));
39 for (int j
= 0; j
< 100; j
++)
43 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%d:"), d
.getData ()));
45 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
47 // Iterate in the forward direction.
48 this->iterate_forward ();
50 // Iterate in the other direction.
51 this->iterate_reverse ();
53 // Remove all elements from the map.
56 // Iterate in the forward direction.
57 this->iterate_forward ();
62 // Listing 3 code/ch05
63 void Map_Example::iterate_forward ()
65 ACE_TRACE ("Map_Example::iterate_forward");
67 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Forward iteration\n")));
68 for (ACE_Map_Manager
<KeyType
,
70 ACE_Null_Mutex
>::iterator
75 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%d:"),
76 (*iter
).int_id_
.getData ()));
78 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
82 void Map_Example::iterate_reverse ()
84 ACE_TRACE ("Map_Example::iterate_reverse");
85 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("Reverse iteration\n")));
86 for (ACE_Map_Manager
<KeyType
,
88 ACE_Null_Mutex
>::reverse_iterator
89 iter
= map_
.rbegin ();
93 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("%d:"),
94 (*iter
).int_id_
.getData ()));
96 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
99 // Listing 4 code/ch05
100 void Map_Example::remove_all ()
102 ACE_TRACE ("Map_Example::remove_all");
104 // Note that we can't use the iterators here as they
105 // are invalidated after deletions or insertions.
110 int ACE_TMAIN (int, ACE_TCHAR
*[])