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-2006 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 //$Log: sc_buffer.h,v $
00037 //Revision 1.1.1.1  2006/12/15 20:31:35  acg
00038 //SystemC 2.2
00039 //
00040 //Revision 1.8  2006/03/13 20:19:43  acg
00041 // Andy Goodrich: changed sc_event instances into pointers to sc_event instances
00042 // that are allocated as needed. This saves considerable storage for large
00043 // numbers of signals, etc.
00044 //
00045 //Revision 1.7  2006/01/26 21:00:49  acg
00046 // Andy Goodrich: conversion to use sc_event::notify(SC_ZERO_TIME) instead of
00047 // sc_event::notify_delayed()
00048 //
00049 //Revision 1.6  2006/01/24 20:46:31  acg
00050 //Andy Goodrich: changes to eliminate use of deprecated features. For instance,
00051 //using notify(SC_ZERO_TIME) in place of notify_delayed().
00052 //
00053 //Revision 1.5  2006/01/19 19:18:25  acg
00054 //Andy Goodrich: eliminated check_writer in favor of inline code within the
00055 //write() method since we always execute the check_writer code even when
00056 //check writing is turned off.
00057 //
00058 //Revision 1.4  2006/01/19 00:30:57  acg
00059 //Andy Goodrich: Yet another implementation for disabling write checks on
00060 //signals. This version uses an environment variable, SC_SIGNAL_WRITE_CHECK,
00061 //that when set to DISABLE will turn off write checking.
00062 //
00063 //Revision 1.3  2006/01/13 18:47:20  acg
00064 //Reversed sense of multiwriter signal check. It now defaults to ON unless the
00065 //user defines SC_NO_WRITE_CHEK before inclusion of the file.
00066 //
00067 //Revision 1.2  2006/01/03 23:18:26  acg
00068 //Changed copyright to include 2006.
00069 //
00070 //Revision 1.1.1.1  2005/12/19 23:16:43  acg
00071 //First check in of SystemC 2.1 into its own archive.
00072 //
00073 //Revision 1.9  2005/06/10 22:43:55  acg
00074 //Added CVS change log annotation.
00075 //
00076 
00077 #ifndef SC_BUFFER_H
00078 #define SC_BUFFER_H
00079 
00080 
00081 #include "sysc/communication/sc_signal.h"
00082 
00083 namespace sc_core {
00084 
00085 // ----------------------------------------------------------------------------
00086 //  CLASS : sc_buffer<T>
00087 //
00088 //  The sc_buffer<T> primitive channel class.
00089 // ----------------------------------------------------------------------------
00090 
00091 template <class T>
00092 class sc_buffer
00093 : public sc_signal<T>
00094 {
00095 public:
00096 
00097     // typedefs
00098 
00099     typedef sc_buffer<T> this_type;
00100     typedef sc_signal<T> base_type;
00101 
00102 public:
00103 
00104     // constructors
00105 
00106     sc_buffer()
00107     : base_type( sc_gen_unique_name( "buffer" ) )
00108     {}
00109 
00110     explicit sc_buffer( const char* name_ )
00111     : base_type( name_ )
00112     {}
00113 
00114 
00115     // interface methods
00116 
00117     // write the new value
00118     virtual void write( const T& );
00119 
00120 
00121     // other methods
00122 
00123     sc_buffer<T>& operator = ( const T& a )
00124     { write( a ); return *this; }
00125 
00126     sc_buffer<T>& operator = ( const base_type& a )
00127     { write( a.read() ); return *this; }
00128 
00129     sc_buffer<T>& operator = ( const this_type& a )
00130     { write( a.read() ); return *this; }
00131 
00132     virtual const char* kind() const
00133         { return "sc_buffer"; }
00134 
00135 protected:
00136 
00137     virtual void update();
00138 
00139 private:
00140 
00141     // disabled
00142     sc_buffer( const sc_buffer<T>& );
00143 };
00144 
00145 
00146 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00147 
00148 // write the new value
00149 
00150 template <class T>
00151 inline
00152 void
00153 sc_buffer<T>::write( const T& value_ )
00154 {
00155     sc_object* writer = sc_get_curr_simcontext()->get_current_writer();
00156     if( sc_signal<T>::m_writer == 0 ) {
00157     sc_signal<T>::m_writer = writer;
00158     } else if( sc_signal<T>::m_writer != writer ) {
00159     sc_signal_invalid_writer( this, sc_signal<T>::m_writer, writer );
00160     }
00161 
00162     this->m_new_val = value_;
00163     this->request_update();
00164 }
00165 
00166 
00167 template <class T>
00168 inline
00169 void
00170 sc_buffer<T>::update()
00171 {
00172     this->m_cur_val = this->m_new_val;
00173     if ( sc_signal<T>::m_change_event_p )
00174         sc_signal<T>::m_change_event_p->notify(SC_ZERO_TIME);
00175     this->m_delta = sc_delta_count();
00176 }
00177 
00178 } // namespace sc_core
00179 
00180 #endif
00181 
00182 // Taf!

Generated on Wed Jan 21 15:32:06 2009 for SystemC by  doxygen 1.5.5