00001 // Allocators -*- C++ -*- 00002 00003 // Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the 00007 // terms of the GNU General Public License as published by the 00008 // Free Software Foundation; either version 2, or (at your option) 00009 // any later version. 00010 00011 // This library is distributed in the hope that it will be useful, 00012 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 // GNU General Public License for more details. 00015 00016 // You should have received a copy of the GNU General Public License along 00017 // with this library; see the file COPYING. If not, write to the Free 00018 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, 00019 // USA. 00020 00021 // As a special exception, you may use this file as part of a free software 00022 // library without restriction. Specifically, if other files instantiate 00023 // templates or use macros or inline functions from this file, or you compile 00024 // this file and link it with other files to produce an executable, this 00025 // file does not by itself cause the resulting executable to be covered by 00026 // the GNU General Public License. This exception does not however 00027 // invalidate any other reasons why the executable file might be covered by 00028 // the GNU General Public License. 00029 00030 /* 00031 * Copyright (c) 1996-1997 00032 * Silicon Graphics Computer Systems, Inc. 00033 * 00034 * Permission to use, copy, modify, distribute and sell this software 00035 * and its documentation for any purpose is hereby granted without fee, 00036 * provided that the above copyright notice appear in all copies and 00037 * that both that copyright notice and this permission notice appear 00038 * in supporting documentation. Silicon Graphics makes no 00039 * representations about the suitability of this software for any 00040 * purpose. It is provided "as is" without express or implied warranty. 00041 */ 00042 00043 /** @file allocator.h 00044 * This is an internal header file, included by other library headers. 00045 * You should not attempt to use it directly. 00046 */ 00047 00048 #ifndef _ALLOCATOR_H 00049 #define _ALLOCATOR_H 1 00050 00051 // Define the base class to std::allocator. 00052 #include <bits/c++allocator.h> 00053 00054 namespace std 00055 { 00056 template<typename _Tp> 00057 class allocator; 00058 00059 template<> 00060 class allocator<void> 00061 { 00062 public: 00063 typedef size_t size_type; 00064 typedef ptrdiff_t difference_type; 00065 typedef void* pointer; 00066 typedef const void* const_pointer; 00067 typedef void value_type; 00068 00069 template<typename _Tp1> 00070 struct rebind 00071 { typedef allocator<_Tp1> other; }; 00072 }; 00073 00074 /** 00075 * @brief The "standard" allocator, as per [20.4]. 00076 * 00077 * (See @link Allocators allocators info @endlink for more.) 00078 */ 00079 template<typename _Tp> 00080 class allocator: public ___glibcxx_base_allocator<_Tp> 00081 { 00082 public: 00083 typedef size_t size_type; 00084 typedef ptrdiff_t difference_type; 00085 typedef _Tp* pointer; 00086 typedef const _Tp* const_pointer; 00087 typedef _Tp& reference; 00088 typedef const _Tp& const_reference; 00089 typedef _Tp value_type; 00090 00091 template<typename _Tp1> 00092 struct rebind 00093 { typedef allocator<_Tp1> other; }; 00094 00095 allocator() throw() { } 00096 00097 allocator(const allocator& a) throw() 00098 : ___glibcxx_base_allocator<_Tp>(a) { } 00099 00100 template<typename _Tp1> 00101 allocator(const allocator<_Tp1>&) throw() { } 00102 00103 ~allocator() throw() { } 00104 00105 // Inherit everything else. 00106 }; 00107 00108 template<typename _T1, typename _T2> 00109 inline bool 00110 operator==(const allocator<_T1>&, const allocator<_T2>&) 00111 { return true; } 00112 00113 template<typename _T1, typename _T2> 00114 inline bool 00115 operator!=(const allocator<_T1>&, const allocator<_T2>&) 00116 { return false; } 00117 00118 // Inhibit implicit instantiations for required instantiations, 00119 // which are defined via explicit instantiations elsewhere. 00120 // NB: This syntax is a GNU extension. 00121 #if _GLIBCXX_EXTERN_TEMPLATE 00122 extern template class allocator<char>; 00123 extern template class allocator<wchar_t>; 00124 #endif 00125 00126 // Undefine. 00127 #undef ___glibcxx_base_allocator 00128 } // namespace std 00129 00130 #endif