CoreLinux++  0.4.32
Proxy.hpp
1 #if !defined(__PROXY_HPP)
2 #define __PROXY_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 
25 #if !defined(__COMMON_HPP)
26 #include <Common.hpp>
27 #endif
28 
29 namespace corelinux
30 {
36  template< class SubjectImpl >
37  class Proxy
38  {
39  public:
40 
41  //
42  // Constructors and destructor
43  //
44 
46 
47  Proxy( void )
48  :
49  theSubject( NULLPTR )
50  {
51  ; // do nothing
52  }
53 
59  Proxy( SubjectImpl *aSubject )
61  :
62  theSubject( aSubject )
63  {
64  REQUIRE( aSubject != NULLPTR );
65  }
66 
72  Proxy( const Proxy &aProxy )
73  :
74  theSubject( aProxy.theSubject )
75  {
76  ; // do nothing
77  }
78 
80 
81  virtual ~Proxy( void )
82  {
83  theSubject = NULLPTR;
84  }
85 
86  //
87  // Operator overloads
88  //
89 
96  Proxy & operator=( const Proxy &aProxy )
97  {
98  if( (*this == aProxy) == false )
99  {
100  theSubject = aProxy.getSubject();
101  }
102  else
103  {
104  ; // do nothing
105  }
106 
107  return ( *this );
108  }
109 
116  bool operator==( const Proxy &aProxy ) const
117  {
118  return ( this == &aProxy &&
119  theSubject == aProxy.getSubject() );
120  }
121 
127  virtual SubjectImpl * operator->( void )
128  {
129  return theSubject;
130  }
131 
138  virtual SubjectImpl & operator*( void )
139  throw( Assertion )
140  {
141  REQUIRE( theSubject != NULLPTR );
142  return ( *theSubject );
143  }
144  //
145  // Accessors
146  //
147 
154  virtual const SubjectImpl &getSubject( void ) const
155  throw( Assertion )
156  {
157  REQUIRE( theSubject != NULLPTR );
158  return ( *theSubject );
159  }
160 
161  protected:
162 
163  //
164  // Mutators
165  //
166 
167  virtual void setSubject( SubjectImpl *aSubject )
168  {
169  theSubject = aSubject;
170  }
171 
172 
173  protected:
174 
176 
177  SubjectImpl *theSubject;
178  };
179 }
180 
181 #endif // if !defined(__PROXY_HPP)
182 
183 /*
184  Common rcs information do not modify
185  $Author: prudhomm $
186  $Revision: 1.1 $
187  $Date: 2000/04/23 20:43:13 $
188  $Locker: $
189 */
190 
Proxy & operator=(const Proxy &aProxy)
Assignment operator.
Definition: Proxy.hpp:96
SubjectImpl * theSubject
The subject pointer.
Definition: Proxy.hpp:177
virtual SubjectImpl & operator*(void)
Operator dereference overload.
Definition: Proxy.hpp:138
virtual SubjectImpl * operator->(void)
Operator selector overload.
Definition: Proxy.hpp:127
virtual ~Proxy(void)
Virtual destructor.
Definition: Proxy.hpp:81
Proxy(const Proxy &aProxy)
Copy constructor.
Definition: Proxy.hpp:72
Proxy(void)
Default constructor.
Definition: Proxy.hpp:47
throw(Assertion)
Constructor with SubjectImpl instance.
Definition: Proxy.hpp:60
Provide a surrogate or placeholder for another object to control access to it.
Definition: Proxy.hpp:37
bool operator==(const Proxy &aProxy) const
Equality operator.
Definition: Proxy.hpp:116
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
virtual const SubjectImpl & getSubject(void) const
Returns a reference to theSubjec.
Definition: Proxy.hpp:154

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