Panda3D
 All Classes Functions Variables Enumerations
pmap.h
1 // Filename: pmap.h
2 // Created by: drose (05Jun01)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PMAP_H
16 #define PMAP_H
17 
18 #include "dtoolbase.h"
19 #include "pallocator.h"
20 #include "stl_compares.h"
21 #include "register_type.h"
22 
23 #include <map>
24 #ifdef HAVE_STL_HASH
25 #include <hash_map>
26 #endif
27 
28 #ifndef USE_STL_ALLOCATOR
29 // If we're not using custom allocators, just use the standard class
30 // definition.
31 #define pmap map
32 #define pmultimap multimap
33 
34 #ifdef HAVE_STL_HASH
35 #define phash_map stdext::hash_map
36 #define phash_multimap stdext::hash_multimap
37 #else // HAVE_STL_HASH
38 #define phash_map map
39 #define phash_multimap multimap
40 #endif // HAVE_STL_HASH
41 
42 #else // USE_STL_ALLOCATOR
43 
44 ////////////////////////////////////////////////////////////////////
45 // Class : pmap
46 // Description : This is our own Panda specialization on the default
47 // STL map. Its main purpose is to call the hooks
48 // for MemoryUsage to properly track STL-allocated
49 // memory.
50 ////////////////////////////////////////////////////////////////////
51 template<class Key, class Value, class Compare = less<Key> >
52 class pmap : public map<Key, Value, Compare, pallocator_single<pair<const Key, Value> > > {
53 public:
55  typedef map<Key, Value, Compare, allocator> base_class;
56 
57  pmap(TypeHandle type_handle = pmap_type_handle) : base_class(Compare(), allocator(type_handle)) { }
58  pmap(const pmap<Key, Value, Compare> &copy) : base_class(copy) { }
59  pmap(const Compare &comp, TypeHandle type_handle = pmap_type_handle) : base_class(comp, allocator(type_handle)) { }
60 
61 #ifdef USE_TAU
62  TYPENAME base_class::mapped_type &
63  operator [] (const TYPENAME base_class::key_type &k) {
64  TAU_PROFILE("pmap::operator [] (const key_type &)", " ", TAU_USER);
65  return base_class::operator [] (k);
66  }
67 
68  std::pair<TYPENAME base_class::iterator, bool>
69  insert(const TYPENAME base_class::value_type &x) {
70  TAU_PROFILE("pmap::insert(const value_type &)", " ", TAU_USER);
71  return base_class::insert(x);
72  }
73 
74  TYPENAME base_class::iterator
75  insert(TYPENAME base_class::iterator position,
76  const TYPENAME base_class::value_type &x) {
77  TAU_PROFILE("pmap::insert(iterator, const value_type &)", " ", TAU_USER);
78  return base_class::insert(position, x);
79  }
80 
81  void
82  erase(TYPENAME base_class::iterator position) {
83  TAU_PROFILE("pmap::erase(iterator)", " ", TAU_USER);
84  base_class::erase(position);
85  }
86 
87  TYPENAME base_class::size_type
88  erase(const TYPENAME base_class::key_type &x) {
89  TAU_PROFILE("pmap::erase(const key_type &)", " ", TAU_USER);
90  return base_class::erase(x);
91  }
92 
93  void
94  clear() {
95  TAU_PROFILE("pmap::clear()", " ", TAU_USER);
96  base_class::clear();
97  }
98 
99  TYPENAME base_class::iterator
100  find(const TYPENAME base_class::key_type &x) {
101  TAU_PROFILE("pmap::find(const key_type &)", " ", TAU_USER);
102  return base_class::find(x);
103  }
104 
105  TYPENAME base_class::const_iterator
106  find(const TYPENAME base_class::key_type &x) const {
107  TAU_PROFILE("pmap::find(const key_type &)", " ", TAU_USER);
108  return base_class::find(x);
109  }
110 
111 #endif // USE_TAU
112 };
113 
114 ////////////////////////////////////////////////////////////////////
115 // Class : pmultimap
116 // Description : This is our own Panda specialization on the default
117 // STL multimap. Its main purpose is to call the hooks
118 // for MemoryUsage to properly track STL-allocated
119 // memory.
120 ////////////////////////////////////////////////////////////////////
121 template<class Key, class Value, class Compare = less<Key> >
122 class pmultimap : public multimap<Key, Value, Compare, pallocator_single<pair<const Key, Value> > > {
123 public:
125  pmultimap(TypeHandle type_handle = pmap_type_handle) : multimap<Key, Value, Compare, allocator>(Compare(), allocator(type_handle)) { }
126  pmultimap(const pmultimap<Key, Value, Compare> &copy) : multimap<Key, Value, Compare, allocator>(copy) { }
127  pmultimap(const Compare &comp, TypeHandle type_handle = pmap_type_handle) : multimap<Key, Value, Compare, allocator>(comp, allocator(type_handle)) { }
128 };
129 
130 #ifdef HAVE_STL_HASH
131 ////////////////////////////////////////////////////////////////////
132 // Class : phash_map
133 // Description : This is our own Panda specialization on the default
134 // STL hash_map. Its main purpose is to call the hooks
135 // for MemoryUsage to properly track STL-allocated
136 // memory.
137 ////////////////////////////////////////////////////////////////////
138 template<class Key, class Value, class Compare = method_hash<Key, less<Key> > >
139 class phash_map : public stdext::hash_map<Key, Value, Compare, pallocator_array<pair<const Key, Value> > > {
140 public:
141  phash_map() : stdext::hash_map<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >() { }
142  phash_map(const phash_map<Key, Value, Compare> &copy) : stdext::hash_map<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >(copy) { }
143  phash_map(const Compare &comp) : stdext::hash_map<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >(comp) { }
144 };
145 
146 ////////////////////////////////////////////////////////////////////
147 // Class : phash_multimap
148 // Description : This is our own Panda specialization on the default
149 // STL hash_multimap. Its main purpose is to call the hooks
150 // for MemoryUsage to properly track STL-allocated
151 // memory.
152 ////////////////////////////////////////////////////////////////////
153 template<class Key, class Value, class Compare = method_hash<Key, less<Key> > >
154 class phash_multimap : public stdext::hash_multimap<Key, Value, Compare, pallocator_array<pair<const Key, Value> > > {
155 public:
156  phash_multimap() : stdext::hash_multimap<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >() { }
157  phash_multimap(const phash_multimap<Key, Value, Compare> &copy) : stdext::hash_multimap<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >(copy) { }
158  phash_multimap(const Compare &comp) : stdext::hash_multimap<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >(comp) { }
159 };
160 
161 #else // HAVE_STL_HASH
162 #define phash_map pmap
163 #define phash_multimap pmultimap
164 #endif // HAVE_STL_HASH
165 
166 #endif // USE_STL_ALLOCATOR
167 #endif
This is our own Panda specialization on the default STL map.
Definition: pmap.h:52
This is our own Panda specialization on the default STL allocator.
Definition: pallocator.h:50
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85
This is our own Panda specialization on the default STL multimap.
Definition: pmap.h:122