Panda3D
 All Classes Functions Variables Enumerations
pmap.h
00001 // Filename: pmap.h
00002 // Created by:  drose (05Jun01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 #ifndef PMAP_H
00016 #define PMAP_H
00017 
00018 #include "dtoolbase.h"
00019 #include "pallocator.h"
00020 #include "stl_compares.h"
00021 #include "register_type.h"
00022 
00023 #include <map>
00024 #ifdef HAVE_STL_HASH
00025 #include <hash_map>
00026 #endif
00027 
00028 #ifndef USE_STL_ALLOCATOR
00029 // If we're not using custom allocators, just use the standard class
00030 // definition.
00031 #define pmap map
00032 #define pmultimap multimap
00033 
00034 #ifdef HAVE_STL_HASH
00035 #define phash_map stdext::hash_map
00036 #define phash_multimap stdext::hash_multimap
00037 #else  // HAVE_STL_HASH
00038 #define phash_map map
00039 #define phash_multimap multimap
00040 #endif  // HAVE_STL_HASH
00041 
00042 #else  // USE_STL_ALLOCATOR
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //       Class : pmap
00046 // Description : This is our own Panda specialization on the default
00047 //               STL map.  Its main purpose is to call the hooks
00048 //               for MemoryUsage to properly track STL-allocated
00049 //               memory.
00050 ////////////////////////////////////////////////////////////////////
00051 template<class Key, class Value, class Compare = less<Key> >
00052 class pmap : public map<Key, Value, Compare, pallocator_single<pair<const Key, Value> > > {
00053 public:
00054   typedef pallocator_single<pair<const Key, Value> > allocator;
00055   typedef map<Key, Value, Compare, allocator> base_class;
00056 
00057   pmap(TypeHandle type_handle = pmap_type_handle) : base_class(Compare(), allocator(type_handle)) { }
00058   pmap(const pmap<Key, Value, Compare> &copy) : base_class(copy) { }
00059   pmap(const Compare &comp, TypeHandle type_handle = pmap_type_handle) : base_class(comp, allocator(type_handle)) { }
00060 
00061 #ifdef USE_TAU
00062   TYPENAME base_class::mapped_type &
00063   operator [] (const TYPENAME base_class::key_type &k) {
00064     TAU_PROFILE("pmap::operator [] (const key_type &)", " ", TAU_USER);
00065     return base_class::operator [] (k);
00066   }
00067 
00068   std::pair<TYPENAME base_class::iterator, bool>
00069   insert(const TYPENAME base_class::value_type &x) { 
00070     TAU_PROFILE("pmap::insert(const value_type &)", " ", TAU_USER);
00071     return base_class::insert(x); 
00072   }
00073 
00074   TYPENAME base_class::iterator
00075   insert(TYPENAME base_class::iterator position, 
00076          const TYPENAME base_class::value_type &x) {
00077     TAU_PROFILE("pmap::insert(iterator, const value_type &)", " ", TAU_USER);
00078     return base_class::insert(position, x);
00079   }
00080 
00081   void
00082   erase(TYPENAME base_class::iterator position) {
00083     TAU_PROFILE("pmap::erase(iterator)", " ", TAU_USER);
00084     base_class::erase(position);
00085   }
00086 
00087   TYPENAME base_class::size_type
00088   erase(const TYPENAME base_class::key_type &x) {
00089     TAU_PROFILE("pmap::erase(const key_type &)", " ", TAU_USER);
00090     return base_class::erase(x);
00091   }
00092 
00093   void
00094   clear() {
00095     TAU_PROFILE("pmap::clear()", " ", TAU_USER);
00096     base_class::clear();
00097   }
00098 
00099   TYPENAME base_class::iterator
00100   find(const TYPENAME base_class::key_type &x) {
00101     TAU_PROFILE("pmap::find(const key_type &)", " ", TAU_USER);
00102     return base_class::find(x);
00103   }
00104 
00105   TYPENAME base_class::const_iterator
00106   find(const TYPENAME base_class::key_type &x) const {
00107     TAU_PROFILE("pmap::find(const key_type &)", " ", TAU_USER);
00108     return base_class::find(x);
00109   }
00110 
00111 #endif  // USE_TAU
00112 };
00113 
00114 ////////////////////////////////////////////////////////////////////
00115 //       Class : pmultimap
00116 // Description : This is our own Panda specialization on the default
00117 //               STL multimap.  Its main purpose is to call the hooks
00118 //               for MemoryUsage to properly track STL-allocated
00119 //               memory.
00120 ////////////////////////////////////////////////////////////////////
00121 template<class Key, class Value, class Compare = less<Key> >
00122 class pmultimap : public multimap<Key, Value, Compare, pallocator_single<pair<const Key, Value> > > {
00123 public:
00124   typedef pallocator_single<pair<const Key, Value> > allocator;
00125   pmultimap(TypeHandle type_handle = pmap_type_handle) : multimap<Key, Value, Compare, allocator>(Compare(), allocator(type_handle)) { }
00126   pmultimap(const pmultimap<Key, Value, Compare> &copy) : multimap<Key, Value, Compare, allocator>(copy) { }
00127   pmultimap(const Compare &comp, TypeHandle type_handle = pmap_type_handle) : multimap<Key, Value, Compare, allocator>(comp, allocator(type_handle)) { }
00128 };
00129 
00130 #ifdef HAVE_STL_HASH
00131 ////////////////////////////////////////////////////////////////////
00132 //       Class : phash_map
00133 // Description : This is our own Panda specialization on the default
00134 //               STL hash_map.  Its main purpose is to call the hooks
00135 //               for MemoryUsage to properly track STL-allocated
00136 //               memory.
00137 ////////////////////////////////////////////////////////////////////
00138 template<class Key, class Value, class Compare = method_hash<Key, less<Key> > >
00139 class phash_map : public stdext::hash_map<Key, Value, Compare, pallocator_array<pair<const Key, Value> > > {
00140 public:
00141   phash_map() : stdext::hash_map<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >() { }
00142   phash_map(const phash_map<Key, Value, Compare> &copy) : stdext::hash_map<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >(copy) { }
00143   phash_map(const Compare &comp) : stdext::hash_map<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >(comp) { }
00144 };
00145 
00146 ////////////////////////////////////////////////////////////////////
00147 //       Class : phash_multimap
00148 // Description : This is our own Panda specialization on the default
00149 //               STL hash_multimap.  Its main purpose is to call the hooks
00150 //               for MemoryUsage to properly track STL-allocated
00151 //               memory.
00152 ////////////////////////////////////////////////////////////////////
00153 template<class Key, class Value, class Compare = method_hash<Key, less<Key> > >
00154 class phash_multimap : public stdext::hash_multimap<Key, Value, Compare, pallocator_array<pair<const Key, Value> > > {
00155 public:
00156   phash_multimap() : stdext::hash_multimap<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >() { }
00157   phash_multimap(const phash_multimap<Key, Value, Compare> &copy) : stdext::hash_multimap<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >(copy) { }
00158   phash_multimap(const Compare &comp) : stdext::hash_multimap<Key, Value, Compare, pallocator_array<pair<const Key, Value> > >(comp) { }
00159 };
00160 
00161 #else // HAVE_STL_HASH
00162 #define phash_map pmap
00163 #define phash_multimap pmultimap
00164 #endif  // HAVE_STL_HASH
00165 
00166 #endif  // USE_STL_ALLOCATOR
00167 #endif
 All Classes Functions Variables Enumerations