Panda3D

pset.h

00001 // Filename: pset.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 PSET_H
00016 #define PSET_H
00017 
00018 #include "dtoolbase.h"
00019 #include "pallocator.h"
00020 #include "stl_compares.h"
00021 #include "register_type.h"
00022 
00023 #include <set>
00024 #ifdef HAVE_STL_HASH
00025 #include <hash_set>
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 pset set
00032 #define pmultiset multiset
00033 
00034 #ifdef HAVE_STL_HASH
00035 #define phash_set stdext::hash_set
00036 #define phash_multiset stdext::hash_multiset
00037 #else  // HAVE_STL_HASH
00038 #define phash_set set
00039 #define phash_multiset multiset
00040 #endif  // HAVE_STL_HASH
00041 
00042 #else  // USE_STL_ALLOCATOR
00043 
00044 ////////////////////////////////////////////////////////////////////
00045 //       Class : pset
00046 // Description : This is our own Panda specialization on the default
00047 //               STL set.  Its main purpose is to call the hooks
00048 //               for MemoryUsage to properly track STL-allocated
00049 //               memory.
00050 ////////////////////////////////////////////////////////////////////
00051 template<class Key, class Compare = less<Key> >
00052 class pset : public set<Key, Compare, pallocator_single<Key> > {
00053 public:
00054   typedef pallocator_single<Key> allocator;
00055   typedef set<Key, Compare, allocator> base_class;
00056   pset(TypeHandle type_handle = pset_type_handle) : base_class(Compare(), allocator(type_handle)) { }
00057   pset(const pset<Key, Compare> &copy) : base_class(copy) { }
00058   pset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : base_class(comp, type_handle) { }
00059 
00060 #ifdef USE_TAU
00061   std::pair<TYPENAME base_class::iterator, bool>
00062   insert(const TYPENAME base_class::value_type &x) {
00063     TAU_PROFILE("pset::insert(const value_type &)", " ", TAU_USER);
00064     return base_class::insert(x);
00065   }
00066 
00067   TYPENAME base_class::iterator
00068   insert(TYPENAME base_class::iterator position, 
00069          const TYPENAME base_class::value_type &x) {
00070     TAU_PROFILE("pset::insert(iterator, const value_type &)", " ", TAU_USER);
00071     return base_class::insert(position, x);
00072   }
00073 
00074   void
00075   erase(TYPENAME base_class::iterator position) {
00076     TAU_PROFILE("pset::erase(iterator)", " ", TAU_USER);
00077     base_class::erase(position);
00078   }
00079 
00080   TYPENAME base_class::size_type
00081   erase(const TYPENAME base_class::key_type &x) {
00082     TAU_PROFILE("pset::erase(const key_type &)", " ", TAU_USER);
00083     return base_class::erase(x);
00084   }
00085   
00086   void
00087   clear() {
00088     TAU_PROFILE("pset::clear()", " ", TAU_USER);
00089     base_class::clear();
00090   }
00091 
00092   TYPENAME base_class::iterator
00093   find(const TYPENAME base_class::key_type &x) {
00094     TAU_PROFILE("pset::find(x)", " ", TAU_USER);
00095     return base_class::find(x);
00096   }
00097 
00098   TYPENAME base_class::const_iterator
00099   find(const TYPENAME base_class::key_type &x) const {
00100     TAU_PROFILE("pset::find(x)", " ", TAU_USER);
00101     return base_class::find(x);
00102   }
00103 #endif  // USE_TAU
00104 };
00105 
00106 ////////////////////////////////////////////////////////////////////
00107 //       Class : pmultiset
00108 // Description : This is our own Panda specialization on the default
00109 //               STL multiset.  Its main purpose is to call the hooks
00110 //               for MemoryUsage to properly track STL-allocated
00111 //               memory.
00112 ////////////////////////////////////////////////////////////////////
00113 template<class Key, class Compare = less<Key> >
00114 class pmultiset : public multiset<Key, Compare, pallocator_single<Key> > {
00115 public:
00116   typedef pallocator_single<Key> allocator;
00117   pmultiset(TypeHandle type_handle = pset_type_handle) : multiset<Key, Compare, allocator>(Compare(), allocator(type_handle)) { }
00118   pmultiset(const pmultiset<Key, Compare> &copy) : multiset<Key, Compare, allocator>(copy) { }
00119   pmultiset(const Compare &comp, TypeHandle type_handle = pset_type_handle) : multiset<Key, Compare, allocator>(comp, type_handle) { }
00120 };
00121 
00122 #ifdef HAVE_STL_HASH
00123 ////////////////////////////////////////////////////////////////////
00124 //       Class : phash_set
00125 // Description : This is our own Panda specialization on the default
00126 //               STL hash_set.  Its main purpose is to call the hooks
00127 //               for MemoryUsage to properly track STL-allocated
00128 //               memory.
00129 ////////////////////////////////////////////////////////////////////
00130 template<class Key, class Compare = method_hash<Key, less<Key> > >
00131 class phash_set : public stdext::hash_set<Key, Compare, pallocator_array<Key> > {
00132 public:
00133   phash_set() : stdext::hash_set<Key, Compare, pallocator_array<Key> >() { }
00134   phash_set(const phash_set<Key, Compare> &copy) : stdext::hash_set<Key, Compare, pallocator_array<Key> >(copy) { }
00135   phash_set(const Compare &comp) : stdext::hash_set<Key, Compare, pallocator_array<Key> >(comp) { }
00136 };
00137 
00138 ////////////////////////////////////////////////////////////////////
00139 //       Class : phash_multiset
00140 // Description : This is our own Panda specialization on the default
00141 //               STL hash_multiset.  Its main purpose is to call the hooks
00142 //               for MemoryUsage to properly track STL-allocated
00143 //               memory.
00144 ////////////////////////////////////////////////////////////////////
00145 template<class Key, class Compare = method_hash<Key, less<Key> > >
00146 class phash_multiset : public stdext::hash_multiset<Key, Compare, pallocator_array<Key> > {
00147 public:
00148   phash_multiset() : stdext::hash_multiset<Key, Compare, pallocator_array<Key> >() { }
00149   phash_multiset(const phash_multiset<Key, Compare> &copy) : stdext::hash_multiset<Key, Compare, pallocator_array<Key> >(copy) { }
00150   phash_multiset(const Compare &comp) : stdext::hash_multiset<Key, Compare, pallocator_array<Key> >(comp) { }
00151 };
00152 
00153 #else // HAVE_STL_HASH
00154 #define phash_set pset
00155 #define phash_multiset pmultiset
00156 #endif  // HAVE_STL_HASH
00157 
00158 #endif  // USE_STL_ALLOCATOR
00159 #endif
 All Classes Functions Variables Enumerations