This is Unofficial EPICS BASE Doxygen Site
sgAutoPtr.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, 1986, 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_sgAutoPtr_H
26 #define INC_sgAutoPtr_H
27 
28 template < class T >
29 class sgAutoPtr {
30 public:
32  ~sgAutoPtr ();
34  T * operator -> ();
35  T & operator * ();
36  T * get ();
37  T * release ();
38 private:
39  T * pNotify;
40  struct CASG & sg;
42  sgAutoPtr & operator = ( const sgAutoPtr & );
43 };
44 
45 template < class T >
47  epicsGuard < epicsMutex > & guardIn, struct CASG & sgIn ) :
48  pNotify ( 0 ), sg ( sgIn ), guard ( guardIn )
49 {
50 }
51 
52 template < class T >
54 {
55  if ( this->pNotify ) {
56  this->sg.ioPendingList.remove ( *this->pNotify );
57  this->sg.client.
58  whenThereIsAnExceptionDestroySyncGroupIO ( this->guard, *this->pNotify );
59  }
60 }
61 
62 template < class T >
63 inline sgAutoPtr < T > & sgAutoPtr < T > :: operator = ( T * pNotifyIn )
64 {
65  if ( this->pNotify ) {
66  this->sg.ioPendingList.remove ( *this->pNotify );
67  this->sg.client.
68  whenThereIsAnExceptionDestroySyncGroupIO ( this->guard, *this->pNotify );
69  }
70  this->pNotify = pNotifyIn;
71  this->sg.ioPendingList.add ( *this->pNotify );
72  return *this;
73 }
74 
75 template < class T >
76 inline T * sgAutoPtr < T > :: operator -> ()
77 {
78  return this->pNotify;
79 }
80 
81 template < class T >
82 inline T & sgAutoPtr < T > :: operator * ()
83 {
84  assert ( this->pNotify );
85  return * this->pNotify;
86 }
87 
88 template < class T >
90 {
91  T * pTmp = this->pNotify;
92  this->pNotify = 0;
93  return pTmp;
94 }
95 
96 template < class T >
97 inline T * sgAutoPtr < T > :: get ()
98 {
99  return this->pNotify;
100 }
101 
102 #endif // ifndef INC_sgAutoPtr_H
T * operator->()
Definition: sgAutoPtr.h:76
#define assert(exp)
Declare that a condition should be true.
Definition: epicsAssert.h:70
T & operator*()
Definition: sgAutoPtr.h:82
sgAutoPtr(epicsGuard< epicsMutex > &, struct CASG &)
Definition: sgAutoPtr.h:46
sgAutoPtr< T > & operator=(T *)
Definition: sgAutoPtr.h:63
ca_client_context & client
Definition: syncGroup.h:190
~sgAutoPtr()
Definition: sgAutoPtr.h:53
T * get()
Definition: sgAutoPtr.h:97
T * release()
Definition: sgAutoPtr.h:89