rc_var.h

Go to the documentation of this file.
00001 // vim:set et sts=4 ts=4 tw=75 sw=4 ai ci cin cino=g0,t0:
00002 /*
00003  * Copyright (C) 2007, Technical Computer Science Group,
00004  *                     University of Bonn
00005  *
00006  * This file is part of the ReChannel library.
00007  *
00008  * The ReChannel library is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU 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  * This library is distributed in the hope that it will be
00014  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016  * General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU General Public License
00019  * along with this library; see the file COPYING. If not, write to the
00020  * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
00021  * Boston, MA 02110-1301, USA.
00022  *
00023  * Authors: Andreas Raabe and Armin Felke. Implementation by Armin Felke.
00024  *          {raabe, felke}@cs.uni-bonn.de
00025  */
00037 #ifndef RC_VAR_H_
00038 #define RC_VAR_H_
00039 
00040 #include "ReChannel/core/rc_common_header.h"
00041 #include "ReChannel/core/rc_resettable.h"
00042 #include "ReChannel/core/rc_reconfigurable.h"
00043 
00044 namespace ReChannel {
00045 namespace internals {
00046 namespace resettable_var {
00047 
00051 class resettable_var_base
00052     : virtual public rc_resettable
00053 {
00054 protected:
00055     resettable_var_base();
00056 
00057     template<class P> void init();
00058 
00059     void report_invalid_use_error();
00060 
00061 protected:
00062     // one void field for the parent to save memory
00063     // may only be changed by constructors!
00064     // caution: must be interpreted as P* after call of init<P>()!!!
00065     void* m_parent;
00066 
00067 private:
00068     class tmp_object : public sc_object {};
00069 
00070 private:
00071     // disabled
00072     resettable_var_base(const resettable_var_base& orig);
00073     resettable_var_base& operator=(const resettable_var_base& orig);
00074 };
00075 
00079 template<class T>
00080 class resettable_var_b
00081     : public resettable_var_base
00082 {
00083 protected:
00084     resettable_var_b();
00085 
00086     template<class P> void reset(T& (P::*get_ref)(void));
00087 
00088     template<class P> void init_reset(T& (P::*get_ref)(void));
00089 
00090 private:
00091     T m_reset_value;
00092 };
00093 
00097 template<class P, class T, T& (P::*get_ref)(void)>
00098 class resettable_var
00099     : public resettable_var_b<T>
00100 {
00101 public:
00102     resettable_var()
00103         : resettable_var_b<T>()
00104     {
00105         this->template init<P>();
00106     }
00107 
00108 protected:
00109 
00110 // MSVC .NET 2003 compiler bug workaround
00111 #if (defined(_MSC_VER) && _MSC_VER < 1400) /* Visual Studio .NET 2003 */
00112 
00113     virtual void rc_on_reset()
00114         { this->template reset<P>(get_ref); }
00115 
00116     virtual void rc_on_init_resettable()
00117         { this->template init_reset<P>(get_ref); }
00118 
00119 #else // all other compilers
00120 
00121     virtual void rc_on_reset();
00122 
00123     virtual void rc_on_init_resettable();
00124 
00125 #endif // (defined(_MSC_VER) && _MSC_VER < 1400)
00126 };
00127 
00128 /* template code */
00129 
00130 template<class P>
00131 void resettable_var_base::init()
00132 {
00133     sc_object* parent_obj = reinterpret_cast<sc_object*>(m_parent);
00134     m_parent = dynamic_cast<P*>(parent_obj);
00135     if (m_parent == NULL) {
00136         report_invalid_use_error();
00137     }
00138 }
00139 
00140 template<class T>
00141 resettable_var_b<T>::resettable_var_b()
00142     : resettable_var_base()
00143 { }
00144 
00145 template<class T>
00146 template<class P>
00147 void resettable_var_b<T>::reset(T& (P::*get_ref)(void))
00148 {
00149     (reinterpret_cast<P*>(m_parent)->*get_ref)() = m_reset_value;
00150 }
00151 
00152 template<class T>
00153 template<class P>
00154 void resettable_var_b<T>::init_reset(T& (P::*get_ref)(void))
00155 {
00156     m_reset_value = (reinterpret_cast<P*>(m_parent)->*get_ref)();
00157 }
00158 
00159 // MSVC .NET 2003 compiler bug workaround
00160 #if (defined(_MSC_VER) && _MSC_VER < 1400) /* Visual Studio .NET 2003 */
00161 
00162 /* definition of rc_on_reset() and rc_on_init_resettable moved
00163    to class declaration */
00164 
00165 #else // all other compilers
00166 
00167 template<class P, class T, T& (P::*get_ref)(void)>
00168 void resettable_var<P, T, get_ref>::rc_on_reset()
00169 {
00170     this->template reset<P>(get_ref);
00171 }
00172 
00173 template<class P, class T, T& (P::*get_ref)(void)>
00174 void resettable_var<P, T, get_ref>::rc_on_init_resettable()
00175 {
00176     this->template init_reset<P>(get_ref);
00177 }
00178 
00179 #endif // (defined(_MSC_VER) && _MSC_VER < 1400)
00180 
00181 } // namespace resettable_var
00182 } // namespace internals
00183 } // namespace ReChannel
00184 
00185 // MSVC .NET 2003 compiler bug workaround
00186 #if (defined(_MSC_VER) && _MSC_VER < 1400) /* Visual Studio .NET 2003 */
00187 
00188 /* MSVC .NET 2003 seems to ignore the member access restrictions anyway */
00189 #define RC_HAS_RECONFIGURABLE_VAR(user_module_name) \
00190     typedef user_module_name RC_CURRENT_VAR_CONTAINER
00191 
00192 #else // all other compilers
00193 
00194 #define RC_HAS_RECONFIGURABLE_VAR(user_module_name) \
00195     template< \
00196         class _rc_var_P, \
00197         class _rc_var_T, \
00198         _rc_var_T& (_rc_var_P::*_rc_var_get_ref)(void) \
00199     > \
00200     friend class ::ReChannel::internals::resettable_var::resettable_var; \
00201     typedef user_module_name RC_CURRENT_VAR_CONTAINER
00202 
00203 #endif // (defined(_MSC_VER) && _MSC_VER < 1400)
00204 
00205 #define RC_DECLARE_RECONFIGURABLE_VAR(var_type, var_name) \
00206     var_type& _rc_var_get_##var_name() { return this->var_name; } \
00207     ::ReChannel::internals::resettable_var::resettable_var< \
00208         RC_CURRENT_VAR_CONTAINER, var_type, \
00209         &RC_CURRENT_VAR_CONTAINER::_rc_var_get_##var_name> \
00210             _rc_var_##var_name
00211 
00212 #define RC_RECONFIGURABLE_VAR(var_type, var_name) \
00213     var_type var_name; \
00214     RC_DECLARE_RECONFIGURABLE_VAR(var_type, var_name)
00215 
00216 #define RC_HAS_VAR(user_module_name) \
00217     RC_HAS_RECONFIGURABLE_VAR(user_module_name)
00218 
00219 #define RC_DECLARE_VAR(var_type, var_name) \
00220     RC_DECLARE_RECONFIGURABLE_VAR(var_type, var_name)
00221 #define rc_declare_var(var_type, var_name) \
00222     RC_DECLARE_RECONFIGURABLE_VAR(var_type, var_name)
00223 
00224 #define RC_VAR(var_type, var_name) \
00225     RC_RECONFIGURABLE_VAR(var_type, var_name)
00226 #define rc_var(var_type, var_name) \
00227     RC_RECONFIGURABLE_VAR(var_type, var_name)
00228 
00229 #define RC_RESETTABLE_VAR(var_type, var_name) \
00230     RC_RECONFIGURABLE_VAR(var_type, var_name)
00231 #define rc_resettable_var(var_type, var_name) \
00232     RC_RECONFIGURABLE_VAR(var_type, var_name)
00233 
00234 #define RC_PRESERVABLE_VAR(var_type, var_name) \
00235     var_type var_name;
00236 #define rc_preservable_var(var_type, var_name) \
00237     var_type var_name;
00238 
00239 #define RC_DECLARE_RESETTABLE_VAR(var_type, var_name) \
00240     RC_DECLARE_RECONFIGURABLE_VAR(var_type, var_name)
00241 #define rc_declare_resettable_var(var_type, var_name) \
00242     RC_DECLARE_RECONFIGURABLE_VAR(var_type, var_name)
00243 
00244 #define RC_DECLARE_PRESERVABLE_VAR(var_type, var_name) \
00245     /* nothing to do */
00246 #define rc_declare_preservable_var(var_type, var_name) \
00247     /* nothing to do */
00248 
00249 #endif // RC_VAR_H_
00250 
00251 //
00252 // $Id: rc_var.h,v 1.14 2007/11/23 13:25:45 felke Exp $
00253 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/components/rc_var.h,v $
00254 //

Generated on Tue Jan 1 23:14:06 2008 for ReChannel by  doxygen 1.5.3