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

Valuator_Class_Tie.hxx

00001 
00002 // 
00003 // Copyright (C) 2006 James M. Lawrence.  All rights reserved.
00004 // 
00005 // software: esve-1.0.3
00006 // file: esve/components/dimn/Valuator_Class_Tie.hxx
00007 // 
00008 // Redistribution and use in source and binary forms, with or without
00009 // modification, are permitted provided that the following conditions
00010 // are met:
00011 // 
00012 // 1. Redistributions of source code must retain the above copyright
00013 //    notice, this list of conditions and the following disclaimer.
00014 // 
00015 // 2. The origin of this software must not be misrepresented; you must
00016 //    not claim that you wrote the original software.  If you use this
00017 //    software in a product, an acknowledgment in the product 
00018 //    documentation would be appreciated but is not required.
00019 // 
00020 // 3. Altered source versions must be plainly marked as such, and must
00021 //    not be misrepresented as being the original software.
00022 // 
00023 // 4. The name of the author may not be used to endorse or promote
00024 //    products derived from this software without specific prior written
00025 //    permission.
00026 // 
00027 // THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY,
00028 // AND WITH NO CLAIM AS TO ITS SUITABILITY FOR ANY PURPOSE.  IN NO EVENT
00029 // SHALL THE AUTHOR BE LIABLE FOR ANY CLAIM WHATSOEVER MADE IN CONNECTION
00030 // TO THIS SOFTWARE.
00031 // 
00033 
00034 #ifndef esve_components_dimn_Valuator_Class_Tie_hxx
00035 #define esve_components_dimn_Valuator_Class_Tie_hxx
00036 
00037 #include <esve/components/dimn/Valuator_Handler.hxx>
00038 #include <esve/types/real.hxx>
00039 #include <string>
00040 #include <map>
00041 
00042 namespace esve { namespace components { namespace dimn {
00043 
00044 template< typename T_Value > class Valuator_Creator ;
00045 
00046 //
00047 // @class Valuator_Class_Tie esve/components/dimn/Valuator_Class_Tie.hxx
00048 // @brief Tie valuators to a class.
00049 //
00050 // Whenever a valuator changes, the corresponding writer method is
00051 // called.  The initial value is taken from the reader method.
00052 //
00053 // Make sure the tie is able to receive handle_valuator() messages.
00054 //
00055 
00056 template< typename T_Target,
00057           typename T_Value_Type >
00058 class Valuator_Class_Tie
00059     : public Valuator_Handler<T_Value_Type>
00060 {
00061 private:
00062     typedef Valuator_Handler<T_Value_Type> super ;
00063 
00064     typedef T_Target m_Target ;
00065     typedef T_Value_Type m_Value_Type ;
00066 
00067     typedef const m_Value_Type & (m_Target::*m_Reader)() const ;
00068     typedef void (m_Target::*m_Writer)( const m_Value_Type & ) ;
00069 
00070     struct m_Node
00071     {
00072         m_Reader reader ;
00073         m_Writer writer ;
00074 
00075         m_Node( m_Reader r,
00076                 m_Writer w )
00077             : reader(r),
00078               writer(w) { }
00079     } ;
00080 
00081     typedef std::map<Valuator<m_Value_Type>*, m_Node> m_Map ;
00082     typedef std::pair<Valuator<m_Value_Type>*, m_Node> m_Pair ;
00083     typedef typename m_Map::iterator m_Map_iterator ;
00084     typedef typename m_Map::const_iterator m_Map_const_iterator ;
00085 
00086     Valuator_Class_Tie( const Valuator_Class_Tie & ) ;
00087     Valuator_Class_Tie & operator=( const Valuator_Class_Tie & ) ;
00088 
00089     Valuator_Creator<m_Value_Type> & m_ui ;
00090     m_Target & m_target ;
00091     m_Map m_map ;
00092 
00093 public:
00094     typedef m_Target Target ;
00095     typedef m_Reader Reader ;
00096     typedef m_Writer Writer ;
00097     typedef m_Value_Type Value_Type ;
00098 
00100     Valuator_Class_Tie( Valuator_Creator<Value_Type> & ui,
00101                         Target & data ) ;
00102 
00104     Valuator<Value_Type> &
00105     create_valuator( Reader,
00106                      Writer,
00107                      const std::string & name = "" ) ;
00108 
00110     void tie( Valuator<Value_Type> &, Reader, Writer ) ;
00111 
00112     ~Valuator_Class_Tie() ;
00113 
00114 protected:
00115     bool handle_valuator( const Valuator<Value_Type> & ) ;
00116 } ;
00117 
00118 //
00119 // Specialization for real.
00120 //
00121 // We want
00122 //
00123 //    real foo() const ;
00124 //    void foo( real ) ;
00125 //
00126 // and not
00127 //
00128 //    const real & foo() const ;
00129 //    void foo( const real & ) ;
00130 //
00131 template< typename T_Target >
00132 class Valuator_Class_Tie<T_Target, types::real>
00133     : public Valuator_Handler<types::real>
00134 {
00135 private:
00136     typedef Valuator_Handler<types::real> super ;
00137 
00138     typedef T_Target m_Target ;
00139 
00140     typedef types::real (m_Target::*m_Reader)() const ;
00141     typedef void (m_Target::*m_Writer)( types::real ) ;
00142 
00143     struct m_Node
00144     {
00145         m_Reader reader ;
00146         m_Writer writer ;
00147 
00148         m_Node( m_Reader r,
00149                 m_Writer w )
00150             : reader(r),
00151               writer(w) { }
00152     } ;
00153 
00154     typedef std::map<Valuator<types::real>*, m_Node> m_Map ;
00155     typedef std::pair<Valuator<types::real>*, m_Node> m_Pair ;
00156     typedef typename m_Map::iterator m_Map_iterator ;
00157     typedef typename m_Map::const_iterator m_Map_const_iterator ;
00158 
00159     Valuator_Class_Tie( const Valuator_Class_Tie & ) ;
00160     Valuator_Class_Tie & operator=( const Valuator_Class_Tie & ) ;
00161 
00162     Valuator_Creator<types::real> & m_ui ;
00163     m_Target & m_target ;
00164     m_Map m_map ;
00165 
00166 public:
00167     typedef m_Target Target ;
00168     typedef m_Reader Reader ;
00169     typedef m_Writer Writer ;
00170 
00172     Valuator_Class_Tie( Valuator_Creator<types::real> & ui,
00173                         Target & data ) ;
00174 
00176     Valuator<types::real> &
00177     create_valuator( Reader,
00178                      Writer,
00179                      const std::string & name = "" ) ;
00180 
00182     void tie( Valuator<types::real> &, Reader, Writer ) ;
00183 
00184     ~Valuator_Class_Tie() ;
00185 
00186 protected:
00187     bool handle_valuator( const Valuator<types::real> & ) ;
00188 } ;
00189 
00190 }}} // namespace esve::components::dimn
00191 
00192 #include <esve/components/dimn/Valuator_Class_Tie.template.cxx>
00193 
00194 #endif
00195 

Generated on Tue May 30 11:40:53 2006 for esve by doxygen 1.3.4