CoreLinux++  0.4.32
AbstractAllocator.hpp
1 #if !defined(__ABSTRACTALLOCATOR_HPP)
2 #define __ABSTRACTALLOCATOR_HPP
3 
4 /*
5  CoreLinux++
6  Copyright (C) 1999,2000 CoreLinux Consortium
7 
8  The CoreLinux++ Library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12 
13  The CoreLinux++ Library Library is distributed in the hope that it will
14  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public
19  License along with the GNU C Library; see the file COPYING.LIB. If not,
20  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA 02111-1307, USA.
22 */
23 
24 #if !defined(__COMMON_HPP)
25 #include <Common.hpp>
26 #endif
27 
28 #if !defined(__ALLOCATOR_HPP)
29 #include <Allocator.hpp>
30 #endif
31 
32 namespace corelinux
33 {
43  template< class TypeImpl >
45  {
46  public:
47 
48  //
49  // Constructors and destructor
50  //
51 
53 
55  :
56  Allocator( )
57  {
58  ; // do nothing
59  }
60 
67  (
68  const AbstractAllocator & aRef
69  )
70  :
71  Allocator( aRef )
72  {
73  ; // do nothing
74  }
75 
77 
78  virtual ~AbstractAllocator( void )
79  {
80  ; // do nothing
81  }
82 
83  //
84  // Operator overloads
85  //
86 
93  AbstractAllocator & operator=
94  (
95  const AbstractAllocator & aRef
96  )
97  {
99  return (*this);
100  }
101 
108  bool operator==( const AbstractAllocator & aRef ) const
109  {
110  return Allocator::operator==(aRef);
111  }
112 
113 
114  //
115  // Factory methods
116  //
117 
128  TypeImpl *createType( void )
129  {
130  TypeImpl *aPtr( NULLPTR );
131  try
132  {
133  aPtr = allocateObject();
135  }
136  catch( ... )
137  {
139  throw;
140  }
141  return aPtr;
142  }
143 
154  void destroyType( TypeImpl *aPtr )
155  {
156  try
157  {
158  deallocateObject( aPtr );
160  }
161  catch( ... )
162  {
164  throw;
165  }
166  }
167 
168  protected:
169 
170  //
171  // Factory virtual declarations
172  //
173 
179  virtual TypeImpl *allocateObject( void ) = 0;
180 
186  virtual void deallocateObject( TypeImpl * ) = 0;
187 
188 
189  };
190 
191 }
192 
200 #define CORELINUX_DEFAULT_ALLOCATOR( nameTag, typeTag ) \
201  class nameTag : public CORELINUX(AbstractAllocator<typeTag>) \
202  { \
203  public: \
204  nameTag( void ) \
205  : \
206  CORELINUX(AbstractAllocator<typeTag>)()\
207  { \
208  ; \
209  } \
210  \
211  virtual ~nameTag( void ) \
212  { \
213  ; \
214  } \
215  protected: \
216  \
217  \
218  virtual typeTag *allocateObject( void ) \
219  { \
220  return ::new typeTag; \
221  } \
222  \
223  virtual void deallocateObject( typeTag *aPtr ) \
224  { \
225  ::delete aPtr; \
226  } \
227  }; \
228 typedef nameTag * nameTag ## Ptr; \
229 typedef const nameTag * nameTag ## Cptr; \
230 typedef nameTag & nameTag ## Ref; \
231 typedef const nameTag & nameTag ## Cref;
232 
233 #endif // if !defined(__ABSTRACTALLOCATOR_HPP)
234 
235 /*
236  Common rcs information do not modify
237  $Author: prudhomm $
238  $Revision: 1.2 $
239  $Date: 2001/02/15 16:34:05 $
240  $Locker: $
241 */
242 
Allocator & operator=(AllocatorCref)
Assingment operator overload.
Definition: Allocator.cpp:72
bool operator==(const AbstractAllocator &aRef) const
Equality operator overload.
Definition: AbstractAllocator.hpp:108
AbstractAllocator is a abstract template which provides for the extension of memory managment on a Ty...
Definition: AbstractAllocator.hpp:44
virtual void incrementDeallocates(void)
Increment the deallocates.
Definition: Allocator.cpp:122
virtual void incrementAllocates(void)
Increment the allocates.
Definition: Allocator.cpp:117
void destroyType(TypeImpl *aPtr)
Destroy type will invoke the deallocateObject method of the derivation and will increment the number ...
Definition: AbstractAllocator.hpp:154
virtual void decrementAllocates(void)
Decrement the allocates.
Definition: Allocator.cpp:127
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
AbstractAllocator(void)
Default constructor.
Definition: AbstractAllocator.hpp:54
Allocator is a Strategy class used by AbstractAllocator and AbstractFactory.Each Allocator instance t...
Definition: Allocator.hpp:43
virtual ~AbstractAllocator(void)
Virtual destructor.
Definition: AbstractAllocator.hpp:78
virtual void decrementDeallocates(void)
Decrement the deallocates.
Definition: Allocator.cpp:132
virtual TypeImpl * allocateObject(void)=0
allocates a object in the subclass
virtual void deallocateObject(TypeImpl *)=0
de-allocates a object in the subclass
bool operator==(AllocatorCref) const
Equality operator overload.
Definition: Allocator.cpp:90
TypeImpl * createType(void)
Create type will invoke the allocateObject method of the derivation and will increment the number of ...
Definition: AbstractAllocator.hpp:128
Allocator(void)
Default constructor.
Definition: Allocator.cpp:37

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