00001 #if !defined(__PROXY_HPP)
00002 #define __PROXY_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
00025 #if !defined(__COMMON_HPP)
00026 #include <Common.hpp>
00027 #endif
00028
00029 namespace corelinux
00030 {
00036 template< class SubjectImpl >
00037 class Proxy
00038 {
00039 public:
00040
00041 //
00042 // Constructors and destructor
00043 //
00044
00046
00047 Proxy( void )
00048 :
00049 theSubject( NULLPTR )
00050 {
00051 ; // do nothing
00052 }
00053
00059 Proxy( SubjectImpl *aSubject )
00060 throw(Assertion)
00061 :
00062 theSubject( aSubject )
00063 {
00064 REQUIRE( aSubject != NULLPTR );
00065 }
00066
00072 Proxy( const Proxy &aProxy )
00073 :
00074 theSubject( aProxy.theSubject )
00075 {
00076 ; // do nothing
00077 }
00078
00080
00081 virtual ~Proxy( void )
00082 {
00083 theSubject = NULLPTR;
00084 }
00085
00086 //
00087 // Operator overloads
00088 //
00089
00096 Proxy & operator=( const Proxy &aProxy )
00097 {
00098 if( (*this == aProxy) == false )
00099 {
00100 theSubject = aProxy.getSubject();
00101 }
00102 else
00103 {
00104 ; // do nothing
00105 }
00106
00107 return ( *this );
00108 }
00109
00116 bool operator==( const Proxy &aProxy ) const
00117 {
00118 return ( this == &aProxy &&
00119 theSubject == aProxy.getSubject() );
00120 }
00121
00127 virtual SubjectImpl * operator->( void )
00128 {
00129 return theSubject;
00130 }
00131
00138 virtual SubjectImpl & operator*( void )
00139 throw( Assertion )
00140 {
00141 REQUIRE( theSubject != NULLPTR );
00142 return ( *theSubject );
00143 }
00144 //
00145 // Accessors
00146 //
00147
00154 virtual const SubjectImpl &getSubject( void ) const
00155 throw( Assertion )
00156 {
00157 REQUIRE( theSubject != NULLPTR );
00158 return ( *theSubject );
00159 }
00160
00161 protected:
00162
00163 //
00164 // Mutators
00165 //
00166
00167 virtual void setSubject( SubjectImpl *aSubject )
00168 {
00169 theSubject = aSubject;
00170 }
00171
00172
00173 protected:
00174
00176
00177 SubjectImpl *theSubject;
00178 };
00179 }
00180
00181 #endif // if !defined(__PROXY_HPP)
00182
00183 /*
00184 Common rcs information do not modify
00185 $Author: prudhomm $
00186 $Revision: 1.1 $
00187 $Date: 2000/04/23 20:43:13 $
00188 $Locker: $
00189 */
00190