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"
20 // Simple map manager.
21 using LAZY_MAP
= ACE_Map_Manager
<int, int, ACE_Null_Mutex
>;
23 // Displaying the contents of a map manager.
26 display_map (LAZY_MAP
&map
)
29 // Simple iteration printing the entries.
30 for (LAZY_MAP::iterator iter
= map
.begin ();
34 LAZY_MAP::ENTRY
&entry
= *iter
;
40 ACE_DEBUG ((LM_DEBUG
, ACE_TEXT ("\n")));
44 // Simple reverse iteration printing the entries.
45 for (LAZY_MAP::reverse_iterator iter
= map
.rbegin ();
49 LAZY_MAP::ENTRY
&entry
= *iter
;
63 // Test for map manager.
72 // Insert a few entries.
73 for (i
= 0; i
< 3; ++i
)
83 // Remove the entry on one end.
88 // Remove the entry on the other end.
93 // If we have lazy map managers, we can delete entries while
94 // iterating over the map.
96 #if defined (ACE_HAS_LAZY_MAP_MANAGER)
98 // Insert a few entries.
99 for (i
= 0; i
< 3; ++i
)
104 // Remove middle one.
106 // Deletion while iterating.
107 for (LAZY_MAP::iterator iter
= map
.begin ();
111 LAZY_MAP::ENTRY
&entry
= *iter
;
112 if (entry
.int_id_
== 1)
119 // Remove the entry on one end.
121 // Deletion while iterating.
122 for (LAZY_MAP::iterator iter
= map
.begin ();
126 LAZY_MAP::ENTRY
&entry
= *iter
;
127 if (entry
.int_id_
== 0)
134 // Remove the entry on the other end.
136 // Deletion while iterating.
137 for (LAZY_MAP::iterator iter
= map
.begin ();
141 LAZY_MAP::ENTRY
&entry
= *iter
;
142 if (entry
.int_id_
== 2)
149 #endif /* ACE_HAS_LAZY_MAP_MANAGER */
151 // Insert a few entries. This will force an increase in map size.
152 for (i
= 0; i
< 4; ++i
)
157 // Remove a few entries (in reverse order).
158 for (i
= 3; i
>= 0; --i
)
164 // Simple active map manager.
165 using ACTIVE_MAP
= ACE_Active_Map_Manager
<int>;
167 // Displaying the contents of an active map manager.
170 display_map (ACTIVE_MAP
&map
)
173 // Simple iteration printing the entries.
174 for (ACTIVE_MAP::iterator iter
= map
.begin ();
178 ACTIVE_MAP::ENTRY
&entry
= *iter
;
179 ACE_DEBUG ((LM_DEBUG
,
184 ACE_DEBUG ((LM_DEBUG
,
189 // Simple reverse iteration printing the entries.
190 for (ACTIVE_MAP::reverse_iterator iter
= map
.rbegin ();
194 ACTIVE_MAP::ENTRY
&entry
= *iter
;
195 ACE_DEBUG ((LM_DEBUG
,
200 ACE_DEBUG ((LM_DEBUG
,
204 ACE_DEBUG ((LM_DEBUG
,
208 // Test for active map manager.
215 ACE_Active_Map_Manager_Key keys
[4];
218 // Insert a few entries.
219 for (i
= 0; i
< 3; ++i
)
220 map
.bind (i
, keys
[i
]);
224 // Remove middle one.
225 map
.unbind (keys
[1]);
229 // Remove the entry on one end.
230 map
.unbind (keys
[0]);
234 // Remove the entry on the other end.
235 map
.unbind (keys
[2]);
239 // If we have lazy map managers, we can delete entries while
240 // iterating over the map.
242 #if defined (ACE_HAS_LAZY_MAP_MANAGER)
244 // Insert a few entries.
245 for (i
= 0; i
< 3; ++i
)
246 map
.bind (i
, keys
[i
]);
250 // Remove middle one.
252 // Deletion while iterating.
253 for (ACTIVE_MAP::iterator iter
= map
.begin ();
257 ACTIVE_MAP::ENTRY
&entry
= *iter
;
258 if (entry
.int_id_
== 1)
259 map
.unbind (keys
[1]);
265 // Remove the entry on one end.
267 // Deletion while iterating.
268 for (ACTIVE_MAP::iterator iter
= map
.begin ();
272 ACTIVE_MAP::ENTRY
&entry
= *iter
;
273 if (entry
.int_id_
== 0)
274 map
.unbind (keys
[0]);
280 // Remove the entry on the other end.
282 // Deletion while iterating.
283 for (ACTIVE_MAP::iterator iter
= map
.begin ();
287 ACTIVE_MAP::ENTRY
&entry
= *iter
;
288 if (entry
.int_id_
== 2)
289 map
.unbind (keys
[2]);
295 #endif /* ACE_HAS_LAZY_MAP_MANAGER */
297 // Insert a few entries. This will force an increase in map size.
298 for (i
= 0; i
< 4; ++i
)
299 map
.bind (i
, keys
[i
]);
303 // Remove a few entries (in reverse order).
304 for (i
= 3; i
>= 0; --i
)
305 map
.unbind (keys
[i
]);
311 run_main (int, ACE_TCHAR
*[])
313 ACE_START_TEST (ACE_TEXT ("Lazy_Map_Manager_Test"));
314 ACE_LOG_MSG
->clr_flags (ACE_Log_Msg::VERBOSE_LITE
);
316 ACE_DEBUG ((LM_DEBUG
,
317 ACE_TEXT ("\nMap Manager...\n\n")));
320 ACE_DEBUG ((LM_DEBUG
,
321 ACE_TEXT ("\nActive Map Manager...\n\n")));
324 ACE_LOG_MSG
->set_flags (ACE_Log_Msg::VERBOSE_LITE
);