Panda3D
pset.h
1 // Filename: pset.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 PSET_H
16 #define PSET_H
17 
18 #include "dtoolbase.h"
19 #include "pallocator.h"
20 #include "stl_compares.h"
21 #include "register_type.h"
22 
23 #include <set>
24 #ifdef HAVE_STL_HASH
25 #include <hash_set>
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 pset set
32 #define pmultiset multiset
33 
34 #ifdef HAVE_STL_HASH
35 #define phash_set stdext::hash_set
36 #define phash_multiset stdext::hash_multiset
37 #else // HAVE_STL_HASH
38 #define phash_set set
39 #define phash_multiset multiset
40 #endif // HAVE_STL_HASH
41 
42 #else // USE_STL_ALLOCATOR
43 
44 ////////////////////////////////////////////////////////////////////
45 // Class : pset
46 // Description : This is our own Panda specialization on the default
47 // STL set. Its main purpose is to call the hooks
48 // for MemoryUsage to properly track STL-allocated
49 // memory.
50 ////////////////////////////////////////////////////////////////////
51 template<class Key, class Compare = less<Key> >
52 class pset : public set<Key, Compare, pallocator_single<Key> > {
53 public:
55  typedef set<Key, Compare, allocator> base_class;
56  pset(TypeHandle type_handle = pset_type_handle) : base_class(Compare(), allocator(type_handle)) { }
57  pset(const pset<Key, Compare> &copy) : base_class(copy) { }
58  pset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : base_class(comp, type_handle) { }
59 
60 #ifdef USE_TAU
61  std::pair<TYPENAME base_class::iterator, bool>
62  insert(const TYPENAME base_class::value_type &x) {
63  TAU_PROFILE("pset::insert(const value_type &)", " ", TAU_USER);
64  return base_class::insert(x);
65  }
66 
67  TYPENAME base_class::iterator
68  insert(TYPENAME base_class::iterator position,
69  const TYPENAME base_class::value_type &x) {
70  TAU_PROFILE("pset::insert(iterator, const value_type &)", " ", TAU_USER);
71  return base_class::insert(position, x);
72  }
73 
74  void
75  erase(TYPENAME base_class::iterator position) {
76  TAU_PROFILE("pset::erase(iterator)", " ", TAU_USER);
77  base_class::erase(position);
78  }
79 
80  TYPENAME base_class::size_type
81  erase(const TYPENAME base_class::key_type &x) {
82  TAU_PROFILE("pset::erase(const key_type &)", " ", TAU_USER);
83  return base_class::erase(x);
84  }
85 
86  void
87  clear() {
88  TAU_PROFILE("pset::clear()", " ", TAU_USER);
89  base_class::clear();
90  }
91 
92  TYPENAME base_class::iterator
93  find(const TYPENAME base_class::key_type &x) {
94  TAU_PROFILE("pset::find(x)", " ", TAU_USER);
95  return base_class::find(x);
96  }
97 
98  TYPENAME base_class::const_iterator
99  find(const TYPENAME base_class::key_type &x) const {
100  TAU_PROFILE("pset::find(x)", " ", TAU_USER);
101  return base_class::find(x);
102  }
103 #endif // USE_TAU
104 };
105 
106 ////////////////////////////////////////////////////////////////////
107 // Class : pmultiset
108 // Description : This is our own Panda specialization on the default
109 // STL multiset. Its main purpose is to call the hooks
110 // for MemoryUsage to properly track STL-allocated
111 // memory.
112 ////////////////////////////////////////////////////////////////////
113 template<class Key, class Compare = less<Key> >
114 class pmultiset : public multiset<Key, Compare, pallocator_single<Key> > {
115 public:
117  pmultiset(TypeHandle type_handle = pset_type_handle) : multiset<Key, Compare, allocator>(Compare(), allocator(type_handle)) { }
118  pmultiset(const pmultiset<Key, Compare> &copy) : multiset<Key, Compare, allocator>(copy) { }
119  pmultiset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : multiset<Key, Compare, allocator>(comp, type_handle) { }
120 };
121 
122 #ifdef HAVE_STL_HASH
123 ////////////////////////////////////////////////////////////////////
124 // Class : phash_set
125 // Description : This is our own Panda specialization on the default
126 // STL hash_set. Its main purpose is to call the hooks
127 // for MemoryUsage to properly track STL-allocated
128 // memory.
129 ////////////////////////////////////////////////////////////////////
130 template<class Key, class Compare = method_hash<Key, less<Key> > >
131 class phash_set : public stdext::hash_set<Key, Compare, pallocator_array<Key> > {
132 public:
133  phash_set() : stdext::hash_set<Key, Compare, pallocator_array<Key> >() { }
134  phash_set(const phash_set<Key, Compare> &copy) : stdext::hash_set<Key, Compare, pallocator_array<Key> >(copy) { }
135  phash_set(const Compare &comp) : stdext::hash_set<Key, Compare, pallocator_array<Key> >(comp) { }
136 };
137 
138 ////////////////////////////////////////////////////////////////////
139 // Class : phash_multiset
140 // Description : This is our own Panda specialization on the default
141 // STL hash_multiset. Its main purpose is to call the hooks
142 // for MemoryUsage to properly track STL-allocated
143 // memory.
144 ////////////////////////////////////////////////////////////////////
145 template<class Key, class Compare = method_hash<Key, less<Key> > >
146 class phash_multiset : public stdext::hash_multiset<Key, Compare, pallocator_array<Key> > {
147 public:
148  phash_multiset() : stdext::hash_multiset<Key, Compare, pallocator_array<Key> >() { }
149  phash_multiset(const phash_multiset<Key, Compare> &copy) : stdext::hash_multiset<Key, Compare, pallocator_array<Key> >(copy) { }
150  phash_multiset(const Compare &comp) : stdext::hash_multiset<Key, Compare, pallocator_array<Key> >(comp) { }
151 };
152 
153 #else // HAVE_STL_HASH
154 #define phash_set pset
155 #define phash_multiset pmultiset
156 #endif // HAVE_STL_HASH
157 
158 #endif // USE_STL_ALLOCATOR
159 #endif
This is our own Panda specialization on the default STL allocator.
Definition: pallocator.h:50
This is our own Panda specialization on the default STL multiset.
Definition: pset.h:114
This is our own Panda specialization on the default STL set.
Definition: pset.h:52
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85