This is Unofficial EPICS BASE Doxygen Site
autoPtrFreeList.h
Go to the documentation of this file.
1 /*************************************************************************\
2 * Copyright (c) 2002 The University of Chicago, as Operator of Argonne
3 * National Laboratory.
4 * Copyright (c) 2002 The Regents of the University of California, as
5 * Operator of Los Alamos National Laboratory.
6 * EPICS BASE is distributed subject to a Software License Agreement found
7 * in file LICENSE that is included with this distribution.
8 \*************************************************************************/
9 
10 /*
11  *
12  *
13  * L O S A L A M O S
14  * Los Alamos National Laboratory
15  * Los Alamos, New Mexico 87545
16  *
17  * Copyright, The Regents of the University of California.
18  *
19  *
20  * Author Jeffrey O. Hill
21  * johill@lanl.gov
22  * 505 665 1831
23  */
24 
25 #ifndef INC_autoPtrFreeList_H
26 #define INC_autoPtrFreeList_H
27 
28 #include "tsFreeList.h"
29 #include "compilerDependencies.h"
30 
31 template < class T, unsigned N = 0x400, class MUTEX = epicsMutex >
33 public:
36  T & operator * () const;
37  T * operator -> () const;
38  T * get () const;
39  T * release ();
40 private:
41  T * p;
42  tsFreeList < T, N, MUTEX > & freeList;
43  // not implemented
44  autoPtrFreeList & operator = ( const autoPtrFreeList & );
46 };
47 
48 template < class T, unsigned N, class MUTEX >
50  tsFreeList < T, N, MUTEX > & freeListIn, T * pIn ) :
51  p ( pIn ), freeList ( freeListIn ) {}
52 
53 template < class T, unsigned N, class MUTEX >
55 {
56  if ( this->p ) {
57  this->p->~T();
58  // its probably a good idea to require that the class has placement delete
59  // by calling it during cleanup if the compiler supports it
60 # if defined ( CXX_PLACEMENT_DELETE )
61  T::operator delete ( this->p, this->freeList );
62 # else
63  this->freeList.release ( this->p );
64 # endif
65  }
66 }
67 
68 template < class T, unsigned N, class MUTEX >
70 {
71  return * this->p;
72 }
73 
74 template < class T, unsigned N, class MUTEX >
76 {
77  return this->p;
78 }
79 
80 template < class T, unsigned N, class MUTEX >
82 {
83  return this->p;
84 }
85 
86 template < class T, unsigned N, class MUTEX >
88 {
89  T *pTmp = this->p;
90  this->p = 0;
91  return pTmp;
92 }
93 
94 #endif // #ifndef INC_autoPtrFreeList_H
autoPtrFreeList(tsFreeList< T, N, MUTEX > &, T *)
T & operator*() const
T * operator->() const
Compiler specific declarations.