rc_buffer.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_BUFFER_H_
00038 #define RC_BUFFER_H_
00039 
00040 #include "ReChannel/components/rc_signal.h"
00041 
00042 namespace ReChannel {
00043 
00047 template<class T>
00048 class rc_buffer
00049     : public rc_signal<T>
00050 {
00051 private:
00052     typedef rc_buffer<T> this_type;
00053     typedef rc_signal<T> base_type;
00054 
00055     using base_type::m_current_value;
00056     using base_type::m_new_value;
00057     using base_type::m_notify_value_changed_event;
00058     using base_type::m_value_changed_event;
00059     using base_type::m_delta;
00060     using base_type::m_driver_proc;
00061 
00062 public:
00063     explicit rc_buffer(
00064         const sc_module_name& name_=sc_gen_unique_name("buffer"))
00065         : base_type(name_)
00066     { }
00067 
00068     virtual const char* kind() const
00069         { return "rc_buffer"; }
00070 
00071     virtual void write(const T& value);
00072 
00073     operator const T&() const
00074         { return this->read(); }
00075 
00076     this_type& operator=(const T& value)
00077         { this->write(value); return *this; }
00078 
00079     this_type& operator=(const this_type& buffer_)
00080         { this->write(buffer_); return *this; }
00081 
00082 protected:
00083 
00084     virtual void update();
00085 };
00086 
00087 /* template code */
00088 
00089 template<class T>
00090 void rc_buffer<T>::write(const T& value)
00091 {
00092     if (this->rc_is_active() || !sc_is_running())
00093     {
00094         if (this->rc_is_constr_done()) {
00095             sc_object* const driver_proc =
00096                 sc_get_current_process_handle().get_process_object();
00097             if (m_driver_proc == NULL) {
00098                 m_driver_proc = driver_proc;
00099             } else if (m_driver_proc != driver_proc && driver_proc != NULL) {
00100                 internals::signals::report_driver_conflict(
00101                     *this, *m_driver_proc, *driver_proc);
00102             }
00103         }
00104         m_new_value = value;
00105         this->request_update();
00106     }
00107 }
00108 
00109 template<class T>
00110 void rc_buffer<T>::update()
00111 {
00112     if (this->rc_is_active()) {
00113         m_current_value = m_new_value;
00114         if (m_notify_value_changed_event) {
00115             m_value_changed_event.notify(SC_ZERO_TIME);
00116         }
00117         m_delta = sc_delta_count();
00118     }
00119 }
00120 
00121 } // namespace ReChannel
00122 
00123 #endif // RC_BUFFER_H_
00124 
00125 //
00126 // $Id: rc_buffer.h,v 1.8 2007/12/20 20:22:57 felke Exp $
00127 // $Source: /var/cvs/projekte/ReChannel-v2/src/ReChannel/components/rc_buffer.h,v $
00128 //

Generated on Tue Jan 1 23:13:31 2008 for ReChannel by  doxygen 1.5.3