Use =default for skeleton copy constructor
[ACE_TAO.git] / ACE / tests / Lazy_Map_Manager_Test.cpp
blobeb155786a1ec137ece86888155191e089ca4ecdf
2 //=============================================================================
3 /**
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.
25 void
26 display_map (LAZY_MAP &map)
29 // Simple iteration printing the entries.
30 for (LAZY_MAP::iterator iter = map.begin ();
31 iter != map.end ();
32 ++iter)
34 LAZY_MAP::ENTRY &entry = *iter;
35 ACE_DEBUG ((LM_DEBUG,
36 ACE_TEXT ("%d "),
37 entry.int_id_));
40 ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
44 // Simple reverse iteration printing the entries.
45 for (LAZY_MAP::reverse_iterator iter = map.rbegin ();
46 iter != map.rend ();
47 ++iter)
49 LAZY_MAP::ENTRY &entry = *iter;
50 ACE_DEBUG ((LM_DEBUG,
51 ACE_TEXT ("%d "),
52 entry.int_id_));
55 ACE_DEBUG ((LM_DEBUG,
56 ACE_TEXT ("\n")));
59 ACE_DEBUG ((LM_DEBUG,
60 ACE_TEXT ("\n")));
63 // Test for map manager.
65 void
66 map_test ()
68 // Map of size 3.
69 LAZY_MAP map (3);
70 int i = 0;
72 // Insert a few entries.
73 for (i = 0; i < 3; ++i)
74 map.bind (i, i);
76 display_map (map);
78 // Remove middle one.
79 map.unbind (1);
81 display_map (map);
83 // Remove the entry on one end.
84 map.unbind (0);
86 display_map (map);
88 // Remove the entry on the other end.
89 map.unbind (2);
91 display_map (map);
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)
100 map.bind (i, i);
102 display_map (map);
104 // Remove middle one.
106 // Deletion while iterating.
107 for (LAZY_MAP::iterator iter = map.begin ();
108 iter != map.end ();
109 ++iter)
111 LAZY_MAP::ENTRY &entry = *iter;
112 if (entry.int_id_ == 1)
113 map.unbind (1);
116 display_map (map);
119 // Remove the entry on one end.
121 // Deletion while iterating.
122 for (LAZY_MAP::iterator iter = map.begin ();
123 iter != map.end ();
124 ++iter)
126 LAZY_MAP::ENTRY &entry = *iter;
127 if (entry.int_id_ == 0)
128 map.unbind (0);
131 display_map (map);
134 // Remove the entry on the other end.
136 // Deletion while iterating.
137 for (LAZY_MAP::iterator iter = map.begin ();
138 iter != map.end ();
139 ++iter)
141 LAZY_MAP::ENTRY &entry = *iter;
142 if (entry.int_id_ == 2)
143 map.unbind (2);
146 display_map (map);
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)
153 map.bind (i, i);
155 display_map (map);
157 // Remove a few entries (in reverse order).
158 for (i = 3; i >= 0; --i)
159 map.unbind (i);
161 display_map (map);
164 // Simple active map manager.
165 using ACTIVE_MAP = ACE_Active_Map_Manager<int>;
167 // Displaying the contents of an active map manager.
169 void
170 display_map (ACTIVE_MAP &map)
173 // Simple iteration printing the entries.
174 for (ACTIVE_MAP::iterator iter = map.begin ();
175 iter != map.end ();
176 ++iter)
178 ACTIVE_MAP::ENTRY &entry = *iter;
179 ACE_DEBUG ((LM_DEBUG,
180 ACE_TEXT ("%d "),
181 entry.int_id_));
184 ACE_DEBUG ((LM_DEBUG,
185 ACE_TEXT ("\n")));
189 // Simple reverse iteration printing the entries.
190 for (ACTIVE_MAP::reverse_iterator iter = map.rbegin ();
191 iter != map.rend ();
192 ++iter)
194 ACTIVE_MAP::ENTRY &entry = *iter;
195 ACE_DEBUG ((LM_DEBUG,
196 ACE_TEXT ("%d "),
197 entry.int_id_));
200 ACE_DEBUG ((LM_DEBUG,
201 ACE_TEXT ("\n")));
204 ACE_DEBUG ((LM_DEBUG,
205 ACE_TEXT ("\n")));
208 // Test for active map manager.
210 void
211 active_map_test ()
213 // Map of size 3.
214 ACTIVE_MAP map (3);
215 ACE_Active_Map_Manager_Key keys[4];
216 int i = 0;
218 // Insert a few entries.
219 for (i = 0; i < 3; ++i)
220 map.bind (i, keys[i]);
222 display_map (map);
224 // Remove middle one.
225 map.unbind (keys[1]);
227 display_map (map);
229 // Remove the entry on one end.
230 map.unbind (keys[0]);
232 display_map (map);
234 // Remove the entry on the other end.
235 map.unbind (keys[2]);
237 display_map (map);
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]);
248 display_map (map);
250 // Remove middle one.
252 // Deletion while iterating.
253 for (ACTIVE_MAP::iterator iter = map.begin ();
254 iter != map.end ();
255 ++iter)
257 ACTIVE_MAP::ENTRY &entry = *iter;
258 if (entry.int_id_ == 1)
259 map.unbind (keys[1]);
262 display_map (map);
265 // Remove the entry on one end.
267 // Deletion while iterating.
268 for (ACTIVE_MAP::iterator iter = map.begin ();
269 iter != map.end ();
270 ++iter)
272 ACTIVE_MAP::ENTRY &entry = *iter;
273 if (entry.int_id_ == 0)
274 map.unbind (keys[0]);
277 display_map (map);
280 // Remove the entry on the other end.
282 // Deletion while iterating.
283 for (ACTIVE_MAP::iterator iter = map.begin ();
284 iter != map.end ();
285 ++iter)
287 ACTIVE_MAP::ENTRY &entry = *iter;
288 if (entry.int_id_ == 2)
289 map.unbind (keys[2]);
292 display_map (map);
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]);
301 display_map (map);
303 // Remove a few entries (in reverse order).
304 for (i = 3; i >= 0; --i)
305 map.unbind (keys[i]);
307 display_map (map);
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")));
318 map_test ();
320 ACE_DEBUG ((LM_DEBUG,
321 ACE_TEXT ("\nActive Map Manager...\n\n")));
322 active_map_test ();
324 ACE_LOG_MSG->set_flags (ACE_Log_Msg::VERBOSE_LITE);
325 ACE_END_TEST;
326 return 0;