Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members  

dtool/src/dtoolbase/pallocator.h

Go to the documentation of this file.
00001 // Filename: pallocator.h
00002 // Created by:  drose (05Jun01)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #ifndef PALLOCATOR_H
00020 #define PALLOCATOR_H
00021 
00022 #include <memory>
00023 #include "dtoolbase.h"
00024 
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : pallocator
00028 // Description : This is our own Panda specialization on the default
00029 //               STL allocator.  Its main purpose is to call the hooks
00030 //               for MemoryUsage to properly track STL-allocated
00031 //               memory.
00032 //
00033 //               pvector, pmap, etc. are all defined in this directory
00034 //               to use a pallocator.
00035 ////////////////////////////////////////////////////////////////////
00036 
00037 #if defined(NO_STYLE_ALLOCATOR)
00038 // If we're not trying to make custom allocators (either we don't know
00039 // what kind of syntax this STL library wants, or we're compiling with
00040 // OPTIMIZE 4), then simply use the standard allocator.
00041 #define pallocator allocator
00042 
00043 #elif defined(OLD_STYLE_ALLOCATOR)
00044 // Early versions of gcc wanted to use their own kind of allocator,
00045 // somewhat different from the STL standard.  Irix uses this one too.
00046 // It might be inherited from an early draft of the STL standard.
00047 
00048 template<class Type>
00049 class pallocator : public alloc {
00050 public:
00051   INLINE static Type *allocate(size_t n);
00052   INLINE static void deallocate(void *p, size_t n);
00053 };
00054 
00055 #elif defined(GNU_STYLE_ALLOCATOR)
00056 // Later versions of gcc want to use a still different,
00057 // not-quite-standard definition.  Sheesh.
00058 
00059 template<class Type>
00060 class pallocator : public allocator<Type> {
00061 public:
00062   INLINE pallocator();
00063   template<class _Tp1>
00064   INLINE pallocator(const pallocator<_Tp1> &other);
00065 
00066   INLINE Type *allocate(size_t n);
00067   INLINE void deallocate(void *p, size_t n);
00068 
00069   template <class _Tp1> struct rebind {
00070     typedef pallocator<_Tp1> other;
00071   };
00072 };
00073 
00074 #elif defined(VC6_STYLE_ALLOCATOR)
00075 
00076 // The VC6-era definition.
00077 template<class Type>
00078 class pallocator : public allocator<Type> {
00079 public:
00080   INLINE pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
00081   INLINE void deallocate(void *p, size_type n);
00082 };
00083 
00084 #elif defined(MODERN_STYLE_ALLOCATOR)
00085 
00086 // The final specification?
00087 template<class Type>
00088 class pallocator : public allocator<Type> {
00089 public:
00090   INLINE pallocator() throw();
00091 
00092   // template member functions in VC++ can only be defined in-class.
00093   template<class U>
00094   INLINE pallocator(const pallocator<U> &copy) throw() { }
00095 
00096   INLINE pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
00097   INLINE void deallocate(void *p, size_type n);
00098 
00099   template<class U> struct rebind { 
00100       typedef pallocator<U> other;
00101   };
00102 };
00103 
00104 #else
00105 #error Unrecognized allocator symbol defined!
00106 #endif  // *_STYLE_ALLOCATOR
00107 
00108 #ifndef NO_STYLE_ALLOCATOR
00109 #include "pallocator.T"
00110 #endif
00111 
00112 #endif
00113 

Generated on Thu May 1 22:12:58 2003 for DTool by doxygen1.3