|
STK++ 1.0
|
00001 /*--------------------------------------------------------------------*/ 00002 /* Copyright (C) 2004-2007 Serge Iovleff 00003 00004 This program is free software; you can redistribute it and/or modify 00005 it under the terms of the GNU Lesser General Public License as 00006 published by the Free Software Foundation; either version 2 of the 00007 License, or (at your option) any later version. 00008 00009 This program is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU Lesser General Public License for more details. 00013 00014 You should have received a copy of the GNU Lesser General Public 00015 License along with this program; if not, write to the 00016 Free Software Foundation, Inc., 00017 59 Temple Place, 00018 Suite 330, 00019 Boston, MA 02111-1307 00020 USA 00021 00022 Contact : Serge.Iovleff@stkpp.org 00023 */ 00024 00025 /* 00026 * Project: stkpp::STKernel::Base 00027 * Purpose: Define the Proxy classes for wrapping any types. 00028 * Author: Serge Iovleff, serge.iovleff@stkpp.org 00029 * 00030 **/ 00031 00037 #ifndef STK_PROXY_H 00038 #define STK_PROXY_H 00039 00040 namespace STK 00041 { 00042 00047 struct IProxy 00048 { 00049 virtual ~IProxy() {} 00050 }; 00051 00062 template<class TYPE> 00063 class ConstProxy : public IProxy 00064 { 00065 protected: 00066 TYPE const& x_; 00067 00068 public: 00072 inline ConstProxy(TYPE const& x) : x_(x) 00073 { ;} 00074 00077 virtual ~ConstProxy() {} 00078 00081 inline operator TYPE const &() const 00082 { return x_;} 00083 }; 00084 00095 template<class TYPE> 00096 class Proxy : public IProxy 00097 { 00098 protected: 00099 TYPE& x_; 00100 00101 public: 00105 inline Proxy(TYPE &x) : x_(x) 00106 { ;} 00107 00111 inline Proxy& operator=(TYPE const& x) 00112 { 00113 x_ = x; 00114 return *this; 00115 } 00116 00119 virtual ~Proxy() {} 00120 00124 inline Proxy& operator=(const Proxy<TYPE>& x) 00125 { 00126 x_ = x; 00127 return *this; 00128 } 00129 00133 inline Proxy& operator=(const ConstProxy<TYPE>& x) 00134 { 00135 x_ = x; 00136 return *this; 00137 } 00138 00141 inline operator TYPE &() 00142 { return x_;} 00143 00146 inline operator TYPE const &() const 00147 { return x_;} 00148 }; 00149 00150 } // namespace STK 00151 00152 #endif /*STK_PROXY_H*/