Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Examples

AbstractAllocator.hpp

00001 #if !defined(__ABSTRACTALLOCATOR_HPP) 00002 #define __ABSTRACTALLOCATOR_HPP 00003 00004 /* 00005 CoreLinux++ 00006 Copyright (C) 1999,2000 CoreLinux Consortium 00007 00008 The CoreLinux++ Library is free software; you can redistribute it and/or 00009 modify it under the terms of the GNU Library General Public License as 00010 published by the Free Software Foundation; either version 2 of the 00011 License, or (at your option) any later version. 00012 00013 The CoreLinux++ Library Library is distributed in the hope that it will 00014 be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 Library General Public License for more details. 00017 00018 You should have received a copy of the GNU Library General Public 00019 License along with the GNU C Library; see the file COPYING.LIB. If not, 00020 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, 00021 Boston, MA 02111-1307, USA. 00022 */ 00023 00024 #if !defined(__COMMON_HPP) 00025 #include <Common.hpp> 00026 #endif 00027 00028 #if !defined(__ALLOCATOR_HPP) 00029 #include <Allocator.hpp> 00030 #endif 00031 00032 namespace corelinux 00033 { 00043 template< class TypeImpl > 00044 class AbstractAllocator : public Allocator 00045 { 00046 public: 00047 00048 // 00049 // Constructors and destructor 00050 // 00051 00053 00054 AbstractAllocator( void ) 00055 : 00056 Allocator( ) 00057 { 00058 ; // do nothing 00059 } 00060 00066 AbstractAllocator 00067 ( 00068 const AbstractAllocator & aRef 00069 ) 00070 : 00071 Allocator( aRef ) 00072 { 00073 ; // do nothing 00074 } 00075 00077 00078 virtual ~AbstractAllocator( void ) 00079 { 00080 ; // do nothing 00081 } 00082 00083 // 00084 // Operator overloads 00085 // 00086 00093 AbstractAllocator & operator= 00094 ( 00095 const AbstractAllocator & aRef 00096 ) 00097 { 00098 Allocator::operator=(aRef); 00099 return (*this); 00100 } 00101 00108 bool operator==( const AbstractAllocator & aRef ) const 00109 { 00110 return Allocator::operator==(aRef); 00111 } 00112 00113 00114 // 00115 // Factory methods 00116 // 00117 00128 TypeImpl *createType( void ) 00129 { 00130 TypeImpl *aPtr( NULLPTR ); 00131 try 00132 { 00133 aPtr = allocateObject(); 00134 incrementAllocates(); 00135 } 00136 catch( ... ) 00137 { 00138 decrementAllocates(); 00139 throw; 00140 } 00141 return aPtr; 00142 } 00143 00154 void destroyType( TypeImpl *aPtr ) 00155 { 00156 try 00157 { 00158 deallocateObject( aPtr ); 00159 incrementDeallocates(); 00160 } 00161 catch( ... ) 00162 { 00163 decrementDeallocates(); 00164 throw; 00165 } 00166 } 00167 00168 protected: 00169 00170 // 00171 // Factory virtual declarations 00172 // 00173 00179 virtual TypeImpl *allocateObject( void ) = 0; 00180 00186 virtual void deallocateObject( TypeImpl * ) = 0; 00187 00188 00189 }; 00190 00191 } 00192 00200 #define CORELINUX_DEFAULT_ALLOCATOR( nameTag, typeTag ) \ 00201 class nameTag : public CORELINUX(AbstractAllocator<typeTag>) \ 00202 { \ 00203 public: \ 00204 nameTag( void ) \ 00205 : \ 00206 CORELINUX(AbstractAllocator<typeTag>)()\ 00207 { \ 00208 ; \ 00209 } \ 00210 \ 00211 virtual ~nameTag( void ) \ 00212 { \ 00213 ; \ 00214 } \ 00215 protected: \ 00216 \ 00217 \ 00218 virtual typeTag *allocateObject( void ) \ 00219 { \ 00220 return ::new typeTag; \ 00221 } \ 00222 \ 00223 virtual void deallocateObject( typeTag *aPtr ) \ 00224 { \ 00225 ::delete aPtr; \ 00226 } \ 00227 }; \ 00228 typedef nameTag * nameTag ## Ptr; \ 00229 typedef const nameTag * nameTag ## Cptr; \ 00230 typedef nameTag & nameTag ## Ref; \ 00231 typedef const nameTag & nameTag ## Cref; 00232 00233 #endif // if !defined(__ABSTRACTALLOCATOR_HPP) 00234 00235 /* 00236 Common rcs information do not modify 00237 $Author: prudhomm $ 00238 $Revision: 1.2 $ 00239 $Date: 2001/02/15 16:34:05 $ 00240 $Locker: $ 00241 */ 00242

This is the CoreLinux++ reference manual
Provided by The CoreLinux Consortium