Panda3D
pset.h
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pset.h
10  * @author drose
11  * @date 2001-06-05
12  */
13 
14 #ifndef PSET_H
15 #define PSET_H
16 
17 #include "dtoolbase.h"
18 #include "pallocator.h"
19 #include "stl_compares.h"
20 #include "register_type.h"
21 
22 #include <set>
23 #ifdef HAVE_STL_HASH
24 #include <hash_set>
25 #endif
26 
27 #if !defined(USE_STL_ALLOCATOR) || defined(CPPPARSER)
28 // If we're not using custom allocators, just use the standard class
29 // definition.
30 #define pset std::set
31 #define pmultiset std::multiset
32 
33 #ifdef HAVE_STL_HASH
34 #define phash_set stdext::hash_set
35 #define phash_multiset stdext::hash_multiset
36 #else // HAVE_STL_HASH
37 #define phash_set std::set
38 #define phash_multiset std::multiset
39 #endif // HAVE_STL_HASH
40 
41 #else // USE_STL_ALLOCATOR
42 
43 /**
44  * This is our own Panda specialization on the default STL set. Its main
45  * purpose is to call the hooks for MemoryUsage to properly track STL-
46  * allocated memory.
47  */
48 template<class Key, class Compare = std::less<Key> >
49 class pset : public std::set<Key, Compare, pallocator_single<Key> > {
50 public:
52  typedef std::set<Key, Compare, allocator> base_class;
53  pset(TypeHandle type_handle = pset_type_handle) : base_class(Compare(), allocator(type_handle)) { }
54  pset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : base_class(comp, type_handle) { }
55 
56 #ifdef USE_TAU
57  std::pair<typename base_class::iterator, bool>
58  insert(const typename base_class::value_type &x) {
59  TAU_PROFILE("pset::insert(const value_type &)", " ", TAU_USER);
60  return base_class::insert(x);
61  }
62 
63  typename base_class::iterator
64  insert(typename base_class::iterator position,
65  const typename base_class::value_type &x) {
66  TAU_PROFILE("pset::insert(iterator, const value_type &)", " ", TAU_USER);
67  return base_class::insert(position, x);
68  }
69 
70  void
71  erase(typename base_class::iterator position) {
72  TAU_PROFILE("pset::erase(iterator)", " ", TAU_USER);
73  base_class::erase(position);
74  }
75 
76  typename base_class::size_type
77  erase(const typename base_class::key_type &x) {
78  TAU_PROFILE("pset::erase(const key_type &)", " ", TAU_USER);
79  return base_class::erase(x);
80  }
81 
82  void
83  clear() {
84  TAU_PROFILE("pset::clear()", " ", TAU_USER);
85  base_class::clear();
86  }
87 
88  typename base_class::iterator
89  find(const typename base_class::key_type &x) {
90  TAU_PROFILE("pset::find(x)", " ", TAU_USER);
91  return base_class::find(x);
92  }
93 
94  typename base_class::const_iterator
95  find(const typename base_class::key_type &x) const {
96  TAU_PROFILE("pset::find(x)", " ", TAU_USER);
97  return base_class::find(x);
98  }
99 #endif // USE_TAU
100 };
101 
102 /**
103  * This is our own Panda specialization on the default STL multiset. Its main
104  * purpose is to call the hooks for MemoryUsage to properly track STL-
105  * allocated memory.
106  */
107 template<class Key, class Compare = std::less<Key> >
108 class pmultiset : public std::multiset<Key, Compare, pallocator_single<Key> > {
109 public:
111  pmultiset(TypeHandle type_handle = pset_type_handle) : std::multiset<Key, Compare, allocator>(Compare(), allocator(type_handle)) { }
112  pmultiset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : std::multiset<Key, Compare, allocator>(comp, type_handle) { }
113 };
114 
115 #ifdef HAVE_STL_HASH
116 /**
117  * This is our own Panda specialization on the default STL hash_set. Its main
118  * purpose is to call the hooks for MemoryUsage to properly track STL-
119  * allocated memory.
120  */
121 template<class Key, class Compare = method_hash<Key, std::less<Key> > >
122 class phash_set : public stdext::hash_set<Key, Compare, pallocator_array<Key> > {
123 public:
124  phash_set() : stdext::hash_set<Key, Compare, pallocator_array<Key> >() { }
125  phash_set(const Compare &comp) : stdext::hash_set<Key, Compare, pallocator_array<Key> >(comp) { }
126 };
127 
128 /**
129  * This is our own Panda specialization on the default STL hash_multiset. Its
130  * main purpose is to call the hooks for MemoryUsage to properly track STL-
131  * allocated memory.
132  */
133 template<class Key, class Compare = method_hash<Key, std::less<Key> > >
134 class phash_multiset : public stdext::hash_multiset<Key, Compare, pallocator_array<Key> > {
135 public:
136  phash_multiset() : stdext::hash_multiset<Key, Compare, pallocator_array<Key> >() { }
137  phash_multiset(const Compare &comp) : stdext::hash_multiset<Key, Compare, pallocator_array<Key> >(comp) { }
138 };
139 
140 #else // HAVE_STL_HASH
141 #define phash_set pset
142 #define phash_multiset pmultiset
143 #endif // HAVE_STL_HASH
144 
145 #endif // USE_STL_ALLOCATOR
146 #endif
This is our own Panda specialization on the default STL allocator.
Definition: pallocator.h:45
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL multiset.
Definition: pset.h:108
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
This is our own Panda specialization on the default STL set.
Definition: pset.h:49
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.