Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

pqxx-object/field.h

Go to the documentation of this file.
00001 // database field container                                      -*- C++ -*-
00002 // $Id: field.h,v 1.1 2004/01/28 21:21:07 roger Exp $
00003 //
00004 // Copyright (C) 2003  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 PQXX_OBJECT_FIELD_H
00040 #define PQXX_OBJECT_FIELD_H
00041 
00042 #include <sigc++/signal.h>
00043 
00044 namespace pqxxobject
00045 {
00057   template<typename T>
00058   class field
00059   {
00060   public:
00061     typedef T value_type;
00062 
00064     field():
00065       m_value()
00066     {}
00067 
00069     field(const value_type& value):
00070       m_value(value)
00071     {}
00072 
00074     field(const field<value_type>& rhs):
00075       m_value(rhs.m_value),
00076       m_signal_changed()
00077     {}
00078 
00079     virtual ~field()
00080     {}
00081 
00083     const value_type *operator -> () const
00084     {
00085       return &m_value;
00086     }
00087 
00088     const value_type& operator * () const
00089     {
00090       return m_value;
00091     }
00092 
00094     field<value_type>& operator = (const field<value_type>& rhs)
00095     {
00096       set_value(rhs.m_value);
00097       return *this;
00098     }
00099 
00101     field<value_type>& operator = (const value_type& rhs)
00102     {
00103       set_value(rhs);
00104       return *this;
00105     }
00106 
00108     operator const value_type& () const
00109     {
00110       return m_value;
00111     }
00112 
00117     value_type& get_value()
00118     {
00119       return m_value;
00120     }
00121 
00126     const value_type& get_value() const
00127     {
00128       return m_value;
00129     }
00130 
00135     void set_value(const value_type& value)
00136     {
00137       m_value = value;
00138       m_signal_changed.emit();
00139     }
00140 
00155     SigC::Signal0<void>& signal_changed()
00156     {
00157       return m_signal_changed;
00158     }
00159 
00160   private:
00162     value_type m_value;
00164     SigC::Signal0<void> m_signal_changed;
00165 
00166   }; // class field
00167 
00168 }; // namespace pqxxobject
00169 
00170 #endif // PQXX_OBJECT_FIELD_H

Generated on Wed Jan 28 21:22:48 2004 for pqxx-object API Reference by doxygen 1.3.4