Panda3D

Loading...
Searching...
No Matches
pmap.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 pmap.h
10 * @author drose
11 * @date 2001-06-05
12 */
13
14#ifndef PMAP_H
15#define PMAP_H
16
17#include "dtoolbase.h"
18#include "pallocator.h"
19#include "stl_compares.h"
20#include "register_type.h"
21
22#include <map>
23#ifdef HAVE_STL_HASH
24#include <hash_map>
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 pmap std::map
31#define pmultimap std::multimap
32
33#ifdef HAVE_STL_HASH
34#define phash_map stdext::hash_map
35#define phash_multimap stdext::hash_multimap
36#else // HAVE_STL_HASH
37#define phash_map map
38#define phash_multimap multimap
39#endif // HAVE_STL_HASH
40
41#else // USE_STL_ALLOCATOR
42
43/**
44 * This is our own Panda specialization on the default STL map. Its main
45 * purpose is to call the hooks for MemoryUsage to properly track STL-
46 * allocated memory.
47 */
48 template<class Key, class Value, class Compare = std::less<Key> >
49 class pmap : public std::map<Key, Value, Compare, pallocator_single<std::pair<const Key, Value> > > {
50 public:
51 typedef pallocator_single<std::pair<const Key, Value> > allocator;
52 typedef std::map<Key, Value, Compare, allocator> base_class;
53
54 pmap(TypeHandle type_handle = pmap_type_handle) : base_class(Compare(), allocator(type_handle)) { }
55 pmap(const Compare &comp, TypeHandle type_handle = pmap_type_handle) : base_class(comp, allocator(type_handle)) { }
56
57#ifdef USE_TAU
58 typename base_class::mapped_type &
59 operator [] (const typename base_class::key_type &k) {
60 TAU_PROFILE("pmap::operator [] (const key_type &)", " ", TAU_USER);
61 return base_class::operator [] (k);
62 }
63
64 std::pair<typename base_class::iterator, bool>
65 insert(const typename base_class::value_type &x) {
66 TAU_PROFILE("pmap::insert(const value_type &)", " ", TAU_USER);
67 return base_class::insert(x);
68 }
69
70 typename base_class::iterator
71 insert(typename base_class::iterator position,
72 const typename base_class::value_type &x) {
73 TAU_PROFILE("pmap::insert(iterator, const value_type &)", " ", TAU_USER);
74 return base_class::insert(position, x);
75 }
76
77 void
78 erase(typename base_class::iterator position) {
79 TAU_PROFILE("pmap::erase(iterator)", " ", TAU_USER);
80 base_class::erase(position);
81 }
82
83 typename base_class::size_type
84 erase(const typename base_class::key_type &x) {
85 TAU_PROFILE("pmap::erase(const key_type &)", " ", TAU_USER);
86 return base_class::erase(x);
87 }
88
89 void
90 clear() {
91 TAU_PROFILE("pmap::clear()", " ", TAU_USER);
92 base_class::clear();
93 }
94
95 typename base_class::iterator
96 find(const typename base_class::key_type &x) {
97 TAU_PROFILE("pmap::find(const key_type &)", " ", TAU_USER);
98 return base_class::find(x);
99 }
100
101 typename base_class::const_iterator
102 find(const typename base_class::key_type &x) const {
103 TAU_PROFILE("pmap::find(const key_type &)", " ", TAU_USER);
104 return base_class::find(x);
105 }
106
107#endif // USE_TAU
108};
109
110/**
111 * This is our own Panda specialization on the default STL multimap. Its main
112 * purpose is to call the hooks for MemoryUsage to properly track STL-
113 * allocated memory.
114 */
115 template<class Key, class Value, class Compare = std::less<Key> >
116 class pmultimap : public std::multimap<Key, Value, Compare, pallocator_single<std::pair<const Key, Value> > > {
117 public:
118 typedef pallocator_single<std::pair<const Key, Value> > allocator;
119 pmultimap(TypeHandle type_handle = pmap_type_handle) : std::multimap<Key, Value, Compare, allocator>(Compare(), allocator(type_handle)) { }
120 pmultimap(const Compare &comp, TypeHandle type_handle = pmap_type_handle) : std::multimap<Key, Value, Compare, allocator>(comp, allocator(type_handle)) { }
121};
122
123#ifdef HAVE_STL_HASH
124/**
125 * This is our own Panda specialization on the default STL hash_map. Its main
126 * purpose is to call the hooks for MemoryUsage to properly track STL-
127 * allocated memory.
128 */
129 template<class Key, class Value, class Compare = method_hash<Key, std::less<Key> > >
130 class phash_map : public stdext::hash_map<Key, Value, Compare, pallocator_array<std::pair<const Key, Value> > > {
131 public:
132 phash_map() : stdext::hash_map<Key, Value, Compare, pallocator_array<std::pair<const Key, Value> > >() { }
133 phash_map(const Compare &comp) : stdext::hash_map<Key, Value, Compare, pallocator_array<std::pair<const Key, Value> > >(comp) { }
134};
135
136/**
137 * This is our own Panda specialization on the default STL hash_multimap. Its
138 * main purpose is to call the hooks for MemoryUsage to properly track STL-
139 * allocated memory.
140 */
141 template<class Key, class Value, class Compare = method_hash<Key, std::less<Key> > >
142 class phash_multimap : public stdext::hash_multimap<Key, Value, Compare, pallocator_array<std::pair<const Key, Value> > > {
143 public:
144 phash_multimap() : stdext::hash_multimap<Key, Value, Compare, pallocator_array<std::pair<const Key, Value> > >() { }
145 phash_multimap(const Compare &comp) : stdext::hash_multimap<Key, Value, Compare, pallocator_array<std::pair<const Key, Value> > >(comp) { }
146};
147
148#else // HAVE_STL_HASH
149#define phash_map pmap
150#define phash_multimap pmultimap
151#endif // HAVE_STL_HASH
152
153#endif // USE_STL_ALLOCATOR
154#endif
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition typeHandle.h:81
pair
STL class.
pallocator_array
Definition pallocator.h:74
pallocator_single
This is our own Panda specialization on the default STL allocator.
Definition pallocator.h:45
dtoolbase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
std
STL namespace.
pallocator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
stl_compares.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.