sc_buffer.h revision 12027
112855Sgabeblack@google.com/*****************************************************************************
212855Sgabeblack@google.com
312855Sgabeblack@google.com  Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
412855Sgabeblack@google.com  more contributor license agreements.  See the NOTICE file distributed
512855Sgabeblack@google.com  with this work for additional information regarding copyright ownership.
612855Sgabeblack@google.com  Accellera licenses this file to you under the Apache License, Version 2.0
712855Sgabeblack@google.com  (the "License"); you may not use this file except in compliance with the
812855Sgabeblack@google.com  License.  You may obtain a copy of the License at
912855Sgabeblack@google.com
1012855Sgabeblack@google.com    http://www.apache.org/licenses/LICENSE-2.0
1112855Sgabeblack@google.com
1212855Sgabeblack@google.com  Unless required by applicable law or agreed to in writing, software
1312855Sgabeblack@google.com  distributed under the License is distributed on an "AS IS" BASIS,
1412855Sgabeblack@google.com  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
1512855Sgabeblack@google.com  implied.  See the License for the specific language governing
1612855Sgabeblack@google.com  permissions and limitations under the License.
1712855Sgabeblack@google.com
1812855Sgabeblack@google.com *****************************************************************************/
1912855Sgabeblack@google.com
2012855Sgabeblack@google.com/*****************************************************************************
2112855Sgabeblack@google.com
2212855Sgabeblack@google.com  sc_buffer.h -- The sc_buffer<T> primitive channel class.
2312855Sgabeblack@google.com                 Like sc_signal<T>, but *every* write causes an event.
2412855Sgabeblack@google.com
2512855Sgabeblack@google.com  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
2612855Sgabeblack@google.com
2712855Sgabeblack@google.com  CHANGE LOG IS AT THE END OF THE FILE
2812855Sgabeblack@google.com *****************************************************************************/
2912855Sgabeblack@google.com
3012855Sgabeblack@google.com#ifndef SC_BUFFER_H
3112855Sgabeblack@google.com#define SC_BUFFER_H
3212855Sgabeblack@google.com
3312855Sgabeblack@google.com
3412855Sgabeblack@google.com#include "sysc/communication/sc_signal.h"
3512855Sgabeblack@google.com
3612855Sgabeblack@google.comnamespace sc_core {
3712855Sgabeblack@google.com
3812855Sgabeblack@google.com// ----------------------------------------------------------------------------
3912855Sgabeblack@google.com//  CLASS : sc_buffer<T>
4012855Sgabeblack@google.com//
4112855Sgabeblack@google.com//  The sc_buffer<T> primitive channel class.
4212855Sgabeblack@google.com// ----------------------------------------------------------------------------
4312855Sgabeblack@google.com
4412855Sgabeblack@google.comtemplate< typename T, sc_writer_policy POL = SC_DEFAULT_WRITER_POLICY >
4512855Sgabeblack@google.comclass sc_buffer
4612855Sgabeblack@google.com: public sc_signal<T,POL>
4712855Sgabeblack@google.com{
4812855Sgabeblack@google.compublic:
4912855Sgabeblack@google.com
5012855Sgabeblack@google.com    // typedefs
51
52    typedef sc_buffer<T,POL> this_type;
53    typedef sc_signal<T,POL> base_type;
54
55public:
56
57    // constructors
58
59    sc_buffer()
60	: base_type( sc_gen_unique_name( "buffer" ) )
61	{}
62
63    explicit sc_buffer( const char* name_ )
64	: base_type( name_ )
65	{}
66
67    sc_buffer( const char* name_, const T& initial_value_ )
68      : base_type( name_, initial_value_ )
69    {}
70
71    // interface methods
72
73    // write the new value
74    virtual void write( const T& );
75
76
77    // other methods
78
79    this_type& operator = ( const T& a )
80	{ write( a ); return *this; }
81
82    this_type& operator = ( const sc_signal_in_if<T>& a )
83	{ write( a.read() ); return *this; }
84
85    this_type& operator = ( const this_type& a )
86	{ write( a.read() ); return *this; }
87
88    virtual const char* kind() const
89        { return "sc_buffer"; }
90
91protected:
92
93    virtual void update();
94
95private:
96
97    // disabled
98    sc_buffer( const this_type& );
99};
100
101
102// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
103
104// write the new value
105
106template< typename T, sc_writer_policy POL >
107inline
108void
109sc_buffer<T,POL>::write( const T& value_ )
110{
111    if( !base_type::policy_type::check_write(this,true) )
112      return;
113
114    this->m_new_val = value_;
115    this->request_update();
116}
117
118
119template< typename T, sc_writer_policy POL >
120inline
121void
122sc_buffer<T,POL>::update()
123{
124    base_type::policy_type::update();
125    base_type::do_update();
126}
127
128} // namespace sc_core
129
130#endif
131
132//$Log: sc_buffer.h,v $
133//Revision 1.7  2011/08/26 20:45:39  acg
134// Andy Goodrich: moved the modification log to the end of the file to
135// eliminate source line number skew when check-ins are done.
136//
137//Revision 1.6  2011/04/08 18:22:45  acg
138// Philipp A. Hartmann: use the context of the primitive channel to get
139// the change stamp value.
140//
141//Revision 1.5  2011/04/05 20:48:09  acg
142// Andy Goodrich: changes to make sure that event(), posedge() and negedge()
143// only return true if the clock has not moved.
144//
145//Revision 1.4  2011/04/05 06:15:18  acg
146// Philipp A. Hartmann: sc_writer_policy: ignore no-ops in delta check.
147//
148//Revision 1.3  2011/02/18 20:23:45  acg
149// Andy Goodrich: Copyright update.
150//
151//Revision 1.2  2010/12/07 19:50:36  acg
152// Andy Goodrich: addition of writer policies, courtesy of Philipp Hartmann.
153//
154//Revision 1.1.1.1  2006/12/15 20:20:04  acg
155//SystemC 2.3
156//
157//Revision 1.8  2006/03/13 20:19:43  acg
158// Andy Goodrich: changed sc_event instances into pointers to sc_event instances
159// that are allocated as needed. This saves considerable storage for large
160// numbers of signals, etc.
161//
162//Revision 1.7  2006/01/26 21:00:49  acg
163// Andy Goodrich: conversion to use sc_event::notify(SC_ZERO_TIME) instead of
164// sc_event::notify_delayed()
165//
166//Revision 1.6  2006/01/24 20:46:31  acg
167//Andy Goodrich: changes to eliminate use of deprecated features. For instance,
168//using notify(SC_ZERO_TIME) in place of notify_delayed().
169//
170//Revision 1.5  2006/01/19 19:18:25  acg
171//Andy Goodrich: eliminated check_writer in favor of inline code within the
172//write() method since we always execute the check_writer code even when
173//check writing is turned off.
174//
175//Revision 1.4  2006/01/19 00:30:57  acg
176//Andy Goodrich: Yet another implementation for disabling write checks on
177//signals. This version uses an environment variable, SC_SIGNAL_WRITE_CHECK,
178//that when set to DISABLE will turn off write checking.
179//
180//Revision 1.3  2006/01/13 18:47:20  acg
181//Reversed sense of multiwriter signal check. It now defaults to ON unless the
182//user defines SC_NO_WRITE_CHEK before inclusion of the file.
183//
184//Revision 1.2  2006/01/03 23:18:26  acg
185//Changed copyright to include 2006.
186//
187//Revision 1.1.1.1  2005/12/19 23:16:43  acg
188//First check in of SystemC 2.1 into its own archive.
189//
190//Revision 1.9  2005/06/10 22:43:55  acg
191//Added CVS change log annotation.
192//
193
194// Taf!
195