Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / Map_Manager / test_hash_map_manager.cpp
blob4f60194758ced531b64ea5335e1466bcc25faa1f
1 #include "ace/OS_main.h"
2 #include "ace/Hash_Map_Manager.h"
3 #include "ace/ACE.h"
4 #include "ace/SString.h"
5 #include "ace/Synch.h"
6 #include "ace/Synch_Traits.h"
7 #include "ace/OS_NS_stdio.h"
8 #include "ace/os_include/os_assert.h"
10 const int MAX_KEY_LEN = 1000;
12 typedef ACE_Hash_Map_Manager<ACE_TString, ACE_TString, ACE_SYNCH_RW_MUTEX> MAP_MANAGER;
14 int
15 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
17 if (argc != 4)
18 ACE_ERROR_RETURN ((LM_ERROR, "usage: %s tablesize file1 file2\n",
19 argv[0]), -1);
20 else
22 int total = ACE_OS::atoi (argv[1]);
24 if (!ACE_OS::freopen (argv[2], ACE_TEXT("r"), stdin))
25 ACE_OS::perror (argv[0]), ACE_OS::exit (1);
27 MAP_MANAGER hash (total);
29 ACE_TCHAR key[MAX_KEY_LEN];
31 while (ACE_OS::fgets (key, sizeof key, stdin))
32 // stream ops are just too slow!!
34 ACE_TString string (key);
35 hash.bind (string, string);
38 ACE_OS::fclose (stdin);
40 MAP_MANAGER::ITERATOR iterator (hash);
42 for (MAP_MANAGER::ENTRY *entry = 0;
43 iterator.next (entry) != 0;
44 iterator.advance ())
45 ACE_DEBUG ((LM_DEBUG, "%s %s\n",
46 entry->ext_id_.fast_rep (),
47 entry->int_id_.fast_rep ()));
49 if (!ACE_OS::freopen (argv[3], ACE_TEXT("r"), stdin))
50 ACE_OS::perror (argv[0]), ACE_OS::exit (1);
52 while (ACE_OS::fgets (key, sizeof key, stdin))
54 ACE_TString name (key);
55 ACE_TString value;
56 assert (hash.find (name, value) != -1);
57 assert (name == value);
60 if (!ACE_OS::freopen (argv[3], ACE_TEXT("r"), stdin))
61 ACE_OS::perror (argv[0]), ACE_OS::exit (1);
63 while (ACE_OS::fgets (key, sizeof key, stdin))
65 ACE_TString string (key);
66 assert (hash.unbind (string) != -1);
69 assert (hash.current_size () == 0);
71 ACE_OS::fclose (stdin);
74 return 0;