00001 // database field container proxy -*- C++ -*- 00002 // $Id: field_proxy.h,v 1.2 2004/05/10 19:45:42 roger Exp $ 00003 // 00004 // Copyright (C) 2004 Roger Leigh <rleigh@debian.org> 00005 // 00006 // 00007 // All rights reserved. 00008 // 00009 // Redistribution and use in source and binary forms, with or without 00010 // modification, are permitted provided that the following conditions 00011 // are met: 00012 // 00013 // * Redistributions of source code must retain the above copyright 00014 // notice, this list of conditions and the following disclaimer. 00015 // * Redistributions in binary form must reproduce the above 00016 // copyright notice, this list of conditions and the following 00017 // disclaimer in the documentation and/or other materials provided 00018 // with the distribution. 00019 // * Neither the name of the author, nor the names of other 00020 // contributors may be used to endorse or promote products derived 00021 // from this software without specific prior written permission. 00022 // 00023 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 00024 // CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 00025 // INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 00026 // MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00027 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS 00028 // BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 00029 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED 00030 // TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 00031 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 00032 // ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 00033 // TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF 00034 // THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 00035 // SUCH DAMAGE. 00036 // 00038 00039 #ifndef PQXXOBJECT_FIELD_PROXY_H 00040 #define PQXXOBJECT_FIELD_PROXY_H 00041 00042 #include <cassert> 00043 00044 #include <sigc++/object.h> 00045 #include <sigc++/signal.h> 00046 00047 #include <pqxxobject/field_base.h> 00048 00049 namespace pqxxobject 00050 { 00057 template< typename T > 00058 class field_proxy 00059 { 00060 public: 00061 typedef typename T::value_type value_type; 00062 00064 explicit field_proxy(T& value): 00065 m_value(value) 00066 { 00067 } 00068 00070 field_proxy(const field_proxy& rhs): 00071 m_value(rhs.m_value) 00072 { 00073 } 00074 00076 ~field_proxy() 00077 {} 00078 00080 field_proxy<T>& operator = (const value_type& rhs) 00081 { 00082 m_value = rhs; 00083 return *this; 00084 } 00085 00087 operator value_type () const 00088 { 00089 return *m_value; 00090 } 00091 00096 bool is_null() const 00097 { 00098 return m_value.is_null(); 00099 } 00100 00105 bool is_not_null() const 00106 { 00107 return m_value.is_not_null(); 00108 } 00109 00110 private: 00112 T& m_value; 00113 00114 }; // class field_proxy 00115 00116 template< typename T > 00117 class field_proxy_readonly : public field_proxy<T> 00118 { 00119 public: 00120 typedef typename field_proxy<T>::value_type value_type; 00121 00123 explicit field_proxy_readonly(T& value): 00124 field_proxy<T>(value) 00125 { 00126 } 00127 00128 field_proxy_readonly(const field_proxy_readonly& value): 00129 field_proxy<T>(value) 00130 { 00131 } 00132 00134 ~field_proxy_readonly() 00135 {} 00136 00137 private: 00139 field_proxy_readonly<T>& operator = (const value_type& rhs) 00140 { 00141 m_value = rhs; 00142 return *this; 00143 } 00144 00145 }; // class field_proxy_readonly 00146 00147 template< typename T > 00148 class field_proxy_writeonly : public field_proxy<T> 00149 { 00150 public: 00151 typedef typename field_proxy<T>::value_type value_type; 00152 00154 explicit field_proxy_writeonly(T& value): 00155 field_proxy<T>(value) 00156 { 00157 } 00158 00159 field_proxy_writeonly(const field_proxy_writeonly& value): 00160 field_proxy<T>(value) 00161 { 00162 } 00163 00165 ~field_proxy_writeonly() 00166 {} 00167 00168 private: 00170 operator value_type () const 00171 { 00172 return *m_value; 00173 } 00174 00175 }; // class field_proxy_writeonly 00176 00177 }; // namespace pqxxobject 00178 00179 #endif // PQXXOBJECT_FIELD_PROXY_H