~ubuntu-branches/ubuntu/breezy/ace/breezy

« back to all changes in this revision

Viewing changes to examples/APG/Containers/Hash_Map.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Conrad, Benjamin Montgomery, Adam Conrad
  • Date: 2005-09-18 22:51:38 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 sarge) (0.1.2 woody)
  • Revision ID: james.westby@ubuntu.com-20050918225138-seav22q6fyylb536
Tags: 5.4.7-3ubuntu1
[ Benjamin Montgomery ]
* Added a patch for amd64 and powerpc that disables the compiler
  option -fvisibility-inlines-hidden

[ Adam Conrad ]
* Added DPATCH_OPTION_CPP=1 to debian/patches/00options to make
  Benjamin's above changes work correctly with dpatch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// Hash_Map.cpp,v 1.1 2004/01/01 21:01:00 shuston Exp
2
 
 
3
 
#include "ace/Hash_Map_Manager.h"
4
 
#include "ace/Synch.h" // needed for the lock
5
 
#include "ace/Functor.h"
6
 
#include "DataElement.h"
7
 
 
8
 
// Listing 1 code/ch05
9
 
// Little helper class.
10
 
template<class EXT_ID, class INT_ID>
11
 
class Hash_Map :
12
 
      public ACE_Hash_Map_Manager_Ex<EXT_ID, INT_ID,
13
 
      ACE_Hash<EXT_ID>, ACE_Equal_To<EXT_ID>, ACE_Null_Mutex>
14
 
{};
15
 
// Listing 1
16
 
 
17
 
class Hash_Map_Example
18
 
{
19
 
public:
20
 
  // Constructor
21
 
  Hash_Map_Example ();
22
 
 
23
 
  // Illustrate the hash map.
24
 
  int run (void);
25
 
 
26
 
  // Use the forward iterator.
27
 
  void iterate_forward (void);
28
 
 
29
 
  // Use the reverse iterator.
30
 
  void iterate_reverse (void);
31
 
 
32
 
  // Remove all the elements from the map.
33
 
  void remove_all (void);
34
 
 
35
 
private:
36
 
  Hash_Map<int, DataElement> map_;
37
 
};
38
 
 
39
 
// Listing 2 code/ch05
40
 
Hash_Map_Example::Hash_Map_Example()
41
 
{
42
 
  ACE_TRACE (ACE_TEXT ("Hash_Map_Example::Hash_Map_Example"));
43
 
 
44
 
  map_.open (100);
45
 
}
46
 
// Listing 2
47
 
 
48
 
int Hash_Map_Example::run (void)
49
 
{
50
 
  ACE_TRACE (ACE_TEXT ("Hash_Map_Example::run"));
51
 
 
52
 
  for (int i = 0; i < 100; i++)
53
 
    {
54
 
      map_.bind (i, DataElement(i));
55
 
    }
56
 
 
57
 
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Map has \n")));
58
 
  for (int j = 0; j < 100; j++)
59
 
    {
60
 
      DataElement d;
61
 
      map_.find (j,d);
62
 
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), d.getData ()));
63
 
    }
64
 
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
65
 
 
66
 
  // Use the forward iterator.
67
 
  this->iterate_forward ();
68
 
 
69
 
  // Use the reverse iterator.
70
 
  this->iterate_reverse ();
71
 
 
72
 
  // Remove all the elements from the map.
73
 
  this->remove_all ();
74
 
 
75
 
  // Iterate through the map again.
76
 
  this->iterate_forward ();
77
 
 
78
 
  return 0;
79
 
}
80
 
 
81
 
void Hash_Map_Example::iterate_forward (void)
82
 
{
83
 
  ACE_TRACE (ACE_TEXT ("Hash_Map_Example::iterate_forward"));
84
 
 
85
 
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Forward Iteration \n")));
86
 
  for (Hash_Map<int, DataElement>::iterator iter = map_.begin ();
87
 
       iter != map_.end (); iter++)
88
 
    {
89
 
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), (*iter).int_id_.getData ()));
90
 
    }
91
 
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
92
 
}
93
 
 
94
 
void Hash_Map_Example::iterate_reverse (void)
95
 
{
96
 
  ACE_TRACE (ACE_TEXT ("Hash_Map_Example::iterate_reverse"));
97
 
 
98
 
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Reverse Iteration \n")));
99
 
  for (Hash_Map<int, DataElement>::reverse_iterator iter = map_.rbegin ();
100
 
       iter != map_.rend (); iter++)
101
 
    {
102
 
      ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("%d:"), (*iter).int_id_.getData ()));
103
 
    }
104
 
  ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("\n")));
105
 
}
106
 
 
107
 
void Hash_Map_Example::remove_all (void)
108
 
{
109
 
  ACE_TRACE (ACE_TEXT ("Hash_Map_Example::remove_all"));
110
 
  map_.unbind_all ();
111
 
}
112
 
 
113
 
int ACE_TMAIN (int, ACE_TCHAR *[])
114
 
{
115
 
  Hash_Map_Example me;
116
 
  return me.run ();
117
 
}
118
 
 
119
 
#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
120
 
template class Hash_Map <int, DataElement>
121
 
;
122
 
template class ACE_Hash_Map_Manager_Ex<int, DataElement, ACE_Hash<int>, ACE_Equal_To<int>, ACE_Null_Mutex>
123
 
;
124
 
template class ACE_Hash_Map_Entry<int, DataElement>
125
 
;
126
 
template class ACE_Hash_Map_Iterator_Base_Ex<int, DataElement, ACE_Hash<int>, ACE_Equal_To<int>, ACE_Null_Mutex>
127
 
;
128
 
#elif defined (ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
129
 
#pragma instantiate Hash_Map <int, DataElement*>
130
 
#pragma instantiate ACE_Hash_Map_Manager_Ex<int, DataElement, ACE_Hash<int>, ACE_Equal_To<int>, ACE_Null_Mutex>;
131
 
#pragma instantiate ACE_Hash_Map_Entry<int, DataElement>;
132
 
#pragma instantiate ACE_Hash_Map_Iterator_Base_Ex<int, DataElement, ACE_Hash<int>, ACE_Equal_To<int>, ACE_Null_Mutex>;
133
 
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION*/
134