2 //=============================================================================
4 * @file Lazy_Map_Manager_Test.cpp
6 * This is a simple test of the <ACE_Map_Manager> and
7 * <ACE_Active_Map_Manager> that illustrates how lazy map managers
8 * allow the deletion of entries while iterating over the map.
10 * @author Irfan Pyarali <irfan@cs.wustl.edu>
12 //=============================================================================
15 #include "test_config.h"
16 #include "ace/Map_Manager.h"
17 #include "ace/Active_Map_Manager.h"
21 // Simple map manager.
22 typedef ACE_Map_Manager
<int, int, ACE_Null_Mutex
> LAZY_MAP
;
24 // Displaying the contents of a map manager.
27 display_map (LAZY_MAP
&map
)
30 // Simple iteration printing the entries.
31 for (LAZY_MAP::iterator iter
= map
.begin ();
35 LAZY_MAP::ENTRY
&entry
= *iter
;
41 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
45 // Simple reverse iteration printing the entries.
46 for (LAZY_MAP::reverse_iterator iter
= map
.rbegin ();
50 LAZY_MAP::ENTRY
&entry
= *iter
;
64 // Test for map manager.
73 // Insert a few entries.
74 for (i
= 0; i
< 3; ++i
)
84 // Remove the entry on one end.
89 // Remove the entry on the other end.
94 // If we have lazy map managers, we can delete entries while
95 // iterating over the map.
97 #if defined (ACE_HAS_LAZY_MAP_MANAGER)
99 // Insert a few entries.
100 for (i
= 0; i
< 3; ++i
)
105 // Remove middle one.
107 // Deletion while iterating.
108 for (LAZY_MAP::iterator iter
= map
.begin ();
112 LAZY_MAP::ENTRY
&entry
= *iter
;
113 if (entry
.int_id_
== 1)
120 // Remove the entry on one end.
122 // Deletion while iterating.
123 for (LAZY_MAP::iterator iter
= map
.begin ();
127 LAZY_MAP::ENTRY
&entry
= *iter
;
128 if (entry
.int_id_
== 0)
135 // Remove the entry on the other end.
137 // Deletion while iterating.
138 for (LAZY_MAP::iterator iter
= map
.begin ();
142 LAZY_MAP::ENTRY
&entry
= *iter
;
143 if (entry
.int_id_
== 2)
150 #endif /* ACE_HAS_LAZY_MAP_MANAGER */
152 // Insert a few entries. This will force an increase in map size.
153 for (i
= 0; i
< 4; ++i
)
158 // Remove a few entries (in reverse order).
159 for (i
= 3; i
>= 0; --i
)
165 // Simple active map manager.
166 typedef ACE_Active_Map_Manager
<int> ACTIVE_MAP
;
168 // Displaying the contents of an active map manager.
171 display_map (ACTIVE_MAP
&map
)
174 // Simple iteration printing the entries.
175 for (ACTIVE_MAP::iterator iter
= map
.begin ();
179 ACTIVE_MAP::ENTRY
&entry
= *iter
;
180 ACE_DEBUG ((LM_DEBUG
,
185 ACE_DEBUG ((LM_DEBUG
,
190 // Simple reverse iteration printing the entries.
191 for (ACTIVE_MAP::reverse_iterator iter
= map
.rbegin ();
195 ACTIVE_MAP::ENTRY
&entry
= *iter
;
196 ACE_DEBUG ((LM_DEBUG
,
201 ACE_DEBUG ((LM_DEBUG
,
205 ACE_DEBUG ((LM_DEBUG
,
209 // Test for active map manager.
212 active_map_test (void)
216 ACE_Active_Map_Manager_Key keys
[4];
219 // Insert a few entries.
220 for (i
= 0; i
< 3; ++i
)
221 map
.bind (i
, keys
[i
]);
225 // Remove middle one.
226 map
.unbind (keys
[1]);
230 // Remove the entry on one end.
231 map
.unbind (keys
[0]);
235 // Remove the entry on the other end.
236 map
.unbind (keys
[2]);
240 // If we have lazy map managers, we can delete entries while
241 // iterating over the map.
243 #if defined (ACE_HAS_LAZY_MAP_MANAGER)
245 // Insert a few entries.
246 for (i
= 0; i
< 3; ++i
)
247 map
.bind (i
, keys
[i
]);
251 // Remove middle one.
253 // Deletion while iterating.
254 for (ACTIVE_MAP::iterator iter
= map
.begin ();
258 ACTIVE_MAP::ENTRY
&entry
= *iter
;
259 if (entry
.int_id_
== 1)
260 map
.unbind (keys
[1]);
266 // Remove the entry on one end.
268 // Deletion while iterating.
269 for (ACTIVE_MAP::iterator iter
= map
.begin ();
273 ACTIVE_MAP::ENTRY
&entry
= *iter
;
274 if (entry
.int_id_
== 0)
275 map
.unbind (keys
[0]);
281 // Remove the entry on the other end.
283 // Deletion while iterating.
284 for (ACTIVE_MAP::iterator iter
= map
.begin ();
288 ACTIVE_MAP::ENTRY
&entry
= *iter
;
289 if (entry
.int_id_
== 2)
290 map
.unbind (keys
[2]);
296 #endif /* ACE_HAS_LAZY_MAP_MANAGER */
298 // Insert a few entries. This will force an increase in map size.
299 for (i
= 0; i
< 4; ++i
)
300 map
.bind (i
, keys
[i
]);
304 // Remove a few entries (in reverse order).
305 for (i
= 3; i
>= 0; --i
)
306 map
.unbind (keys
[i
]);
312 run_main (int, ACE_TCHAR
*[])
314 ACE_START_TEST (ACE_TEXT ("Lazy_Map_Manager_Test"));
315 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::VERBOSE_LITE
);
317 ACE_DEBUG ((LM_DEBUG
,
318 ACE_TEXT ("\nMap Manager...\n\n")));
321 ACE_DEBUG ((LM_DEBUG
,
322 ACE_TEXT ("\nActive Map Manager...\n\n")));
325 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::VERBOSE_LITE
);