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

dtool/src/dtoolbase/dallocator.h

Go to the documentation of this file.
00001 // Filename: dallocator.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 DALLOCATOR_H
00020 #define DALLOCATOR_H
00021 #include <memory>
00022 
00023 #include "dtoolbase.h"
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //       Class : dallocator
00027 // Description : This is similar to pallocator, but always uses the
00028 //               default new and delete handlers defined in
00029 //               dtoolbase_cc.h; it never calls the hooks assigned by
00030 //               redefining global_operator_new, etc.
00031 //
00032 //               This is needed in those rare cases when we need to
00033 //               allocate memory for STL without going through the
00034 //               callback hooks, for instance to implement STL tables
00035 //               within the MemoryUsage class itself.
00036 ////////////////////////////////////////////////////////////////////
00037 
00038 #if defined(NO_STYLE_ALLOCATOR)
00039 // If we're not trying to make custom allocators (either we don't know
00040 // what kind of syntax this STL library wants, or we're compiling with
00041 // OPTIMIZE 4), then simply use the standard allocator.
00042 #define dallocator allocator
00043 
00044 #elif defined(OLD_STYLE_ALLOCATOR)
00045 // Early versions of gcc wanted to use their own kind of allocator,
00046 // somewhat different from the STL standard.  Irix uses this one too.
00047 // It might be inherited from an early draft of the STL standard.
00048 
00049 template<class Type>
00050 class dallocator : public alloc {
00051 public:
00052   INLINE static Type *allocate(size_t n);
00053   INLINE static void deallocate(void *p, size_t n);
00054 };
00055 
00056 #elif defined(GNU_STYLE_ALLOCATOR)
00057 // Later versions of gcc want to use a still different,
00058 // not-quite-standard definition.  Sheesh.
00059 
00060 template<class Type>
00061 class dallocator : public allocator<Type> {
00062 public:
00063   INLINE dallocator();
00064   template<class _Tp1>
00065   INLINE dallocator(const dallocator<_Tp1> &other);
00066 
00067   INLINE Type *allocate(size_t n);
00068   INLINE void deallocate(void *p, size_t n);
00069 
00070   template <class _Tp1> struct rebind {
00071     typedef dallocator<_Tp1> other;
00072   };
00073 };
00074 
00075 #elif defined(MODERN_STYLE_ALLOCATOR)
00076 
00077 // The final specification?
00078 template<class Type>
00079 class dallocator : public allocator<Type> {
00080 public:
00081   INLINE dallocator() throw();
00082 
00083   // template member functions in VC++ can only be defined in-class.
00084   template<class U>
00085   INLINE dallocator(const dallocator<U> &copy) throw() { }
00086 
00087   INLINE pointer allocate(size_type n, allocator<void>::const_pointer hint = 0);
00088   INLINE void deallocate(void *p, size_type n);
00089 
00090   template<class U> struct rebind { 
00091       typedef dallocator<U> other; 
00092   };
00093 };
00094 
00095 #else
00096 #error Unrecognized allocator symbol defined!
00097 #endif  // *_STYLE_ALLOCATOR
00098 
00099 #ifndef NO_STYLE_ALLOCATOR
00100 #include "dallocator.T"
00101 #endif
00102 
00103 #endif
00104 

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