src/sysc/communication/sc_buffer.h

Go to the documentation of this file.
00001 /*****************************************************************************
00002 
00003   The following code is derived, directly or indirectly, from the SystemC
00004   source code Copyright (c) 1996-2005 by all Contributors.
00005   All Rights reserved.
00006 
00007   The contents of this file are subject to the restrictions and limitations
00008   set forth in the SystemC Open Source License Version 2.4 (the "License");
00009   You may not use this file except in compliance with such restrictions and
00010   limitations. You may obtain instructions on how to receive a copy of the
00011   License at http://www.systemc.org/. Software distributed by Contributors
00012   under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
00013   ANY KIND, either express or implied. See the License for the specific
00014   language governing rights and limitations under the License.
00015 
00016  *****************************************************************************/
00017 
00018 /*****************************************************************************
00019 
00020   sc_buffer.h -- The sc_buffer<T> primitive channel class.
00021                  Like sc_signal<T>, but *every* write causes an event.
00022 
00023   Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
00024 
00025  *****************************************************************************/
00026 
00027 /*****************************************************************************
00028 
00029   MODIFICATION LOG - modifiers, enter your name, affiliation, date and
00030   changes you are making here.
00031 
00032       Name, Affiliation, Date:
00033   Description of Modification:
00034     
00035  *****************************************************************************/
00036 
00037 #ifndef SC_BUFFER_H
00038 #define SC_BUFFER_H
00039 
00040 
00041 #include "sysc/communication/sc_signal.h"
00042 
00043 namespace sc_core {
00044 
00045 // ----------------------------------------------------------------------------
00046 //  CLASS : sc_buffer<T>
00047 //
00048 //  The sc_buffer<T> primitive channel class.
00049 // ----------------------------------------------------------------------------
00050 
00051 template <class T>
00052 class sc_buffer
00053 : public sc_signal<T>
00054 {
00055 public:
00056 
00057     // typedefs
00058 
00059     typedef sc_buffer<T> this_type;
00060     typedef sc_signal<T> base_type;
00061 
00062 public:
00063 
00064     // constructors
00065 
00066     sc_buffer()
00067         : base_type( sc_gen_unique_name( "buffer" ) )
00068         {}
00069 
00070     explicit sc_buffer( const char* name_ )
00071         : base_type( name_ )
00072         {}
00073 
00074 
00075     // interface methods
00076 
00077     // write the new value
00078     virtual void write( const T& );
00079 
00080 
00081     // other methods
00082 
00083     sc_buffer<T>& operator = ( const T& a )
00084         { write( a ); return *this; }
00085 
00086     sc_buffer<T>& operator = ( const base_type& a )
00087         { write( a.read() ); return *this; }
00088 
00089     sc_buffer<T>& operator = ( const this_type& a )
00090         { write( a.read() ); return *this; }
00091 
00092     virtual const char* kind() const
00093         { return "sc_buffer"; }
00094 
00095 protected:
00096 
00097     virtual void update();
00098 
00099 private:
00100 
00101     // disabled
00102     sc_buffer( const sc_buffer<T>& );
00103 };
00104 
00105 
00106 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00107 
00108 // write the new value
00109 
00110 template <class T>
00111 inline
00112 void
00113 sc_buffer<T>::write( const T& value_ )
00114 {
00115 #ifdef DEBUG_SYSTEMC
00116     this->check_writer();
00117 #endif
00118     this->m_new_val = value_;
00119     this->request_update();
00120 }
00121 
00122 
00123 template <class T>
00124 inline
00125 void
00126 sc_buffer<T>::update()
00127 {
00128     this->m_cur_val = this->m_new_val;
00129     this->m_value_changed_event.notify_delayed();
00130     this->m_delta = this->simcontext()->delta_count();
00131 }
00132 
00133 } // namespace sc_core
00134 
00135 #endif
00136 
00137 // Taf!

Generated on Wed Apr 25 13:53:25 2007 for SystemC by  doxygen 1.5.1