SystemC  2.3.1
Accellera SystemC proof-of-concept library
sc_buffer.h
Go to the documentation of this file.
1 /*****************************************************************************
2 
3  The following code is derived, directly or indirectly, from the SystemC
4  source code Copyright (c) 1996-2014 by all Contributors.
5  All Rights reserved.
6 
7  The contents of this file are subject to the restrictions and limitations
8  set forth in the SystemC Open Source License (the "License");
9  You may not use this file except in compliance with such restrictions and
10  limitations. You may obtain instructions on how to receive a copy of the
11  License at http://www.accellera.org/. Software distributed by Contributors
12  under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF
13  ANY KIND, either express or implied. See the License for the specific
14  language governing rights and limitations under the License.
15 
16  *****************************************************************************/
17 
18 /*****************************************************************************
19 
20  sc_buffer.h -- The sc_buffer<T> primitive channel class.
21  Like sc_signal<T>, but *every* write causes an event.
22 
23  Original Author: Martin Janssen, Synopsys, Inc., 2001-05-21
24 
25  CHANGE LOG IS AT THE END OF THE FILE
26  *****************************************************************************/
27 
28 #ifndef SC_BUFFER_H
29 #define SC_BUFFER_H
30 
31 
33 
34 namespace sc_core {
35 
36 // ----------------------------------------------------------------------------
37 // CLASS : sc_buffer<T>
38 //
39 // The sc_buffer<T> primitive channel class.
40 // ----------------------------------------------------------------------------
41 
42 template< typename T, sc_writer_policy POL = SC_DEFAULT_WRITER_POLICY >
43 class sc_buffer
44 : public sc_signal<T,POL>
45 {
46 public:
47 
48  // typedefs
49 
52 
53 public:
54 
55  // constructors
56 
58  : base_type( sc_gen_unique_name( "buffer" ) )
59  {}
60 
61  explicit sc_buffer( const char* name_ )
62  : base_type( name_ )
63  {}
64 
65  sc_buffer( const char* name_, const T& initial_value_ )
66  : base_type( name_, initial_value_ )
67  {}
68 
69  // interface methods
70 
71  // write the new value
72  virtual void write( const T& );
73 
74 
75  // other methods
76 
77  this_type& operator = ( const T& a )
78  { write( a ); return *this; }
79 
81  { write( a.read() ); return *this; }
82 
84  { write( a.read() ); return *this; }
85 
86  virtual const char* kind() const
87  { return "sc_buffer"; }
88 
89 protected:
90 
91  virtual void update();
92 
93 private:
94 
95  // disabled
96  sc_buffer( const this_type& );
97 };
98 
99 
100 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
101 
102 // write the new value
103 
104 template< typename T, sc_writer_policy POL >
105 inline
106 void
107 sc_buffer<T,POL>::write( const T& value_ )
108 {
109  if( !base_type::policy_type::check_write(this,true) )
110  return;
111 
112  this->m_new_val = value_;
113  this->request_update();
114 }
115 
116 
117 template< typename T, sc_writer_policy POL >
118 inline
119 void
121 {
122  base_type::policy_type::update();
123  base_type::do_update();
124 }
125 
126 } // namespace sc_core
127 
128 #endif
129 
130 //$Log: sc_buffer.h,v $
131 //Revision 1.7 2011/08/26 20:45:39 acg
132 // Andy Goodrich: moved the modification log to the end of the file to
133 // eliminate source line number skew when check-ins are done.
134 //
135 //Revision 1.6 2011/04/08 18:22:45 acg
136 // Philipp A. Hartmann: use the context of the primitive channel to get
137 // the change stamp value.
138 //
139 //Revision 1.5 2011/04/05 20:48:09 acg
140 // Andy Goodrich: changes to make sure that event(), posedge() and negedge()
141 // only return true if the clock has not moved.
142 //
143 //Revision 1.4 2011/04/05 06:15:18 acg
144 // Philipp A. Hartmann: sc_writer_policy: ignore no-ops in delta check.
145 //
146 //Revision 1.3 2011/02/18 20:23:45 acg
147 // Andy Goodrich: Copyright update.
148 //
149 //Revision 1.2 2010/12/07 19:50:36 acg
150 // Andy Goodrich: addition of writer policies, courtesy of Philipp Hartmann.
151 //
152 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
153 //SystemC 2.3
154 //
155 //Revision 1.8 2006/03/13 20:19:43 acg
156 // Andy Goodrich: changed sc_event instances into pointers to sc_event instances
157 // that are allocated as needed. This saves considerable storage for large
158 // numbers of signals, etc.
159 //
160 //Revision 1.7 2006/01/26 21:00:49 acg
161 // Andy Goodrich: conversion to use sc_event::notify(SC_ZERO_TIME) instead of
162 // sc_event::notify_delayed()
163 //
164 //Revision 1.6 2006/01/24 20:46:31 acg
165 //Andy Goodrich: changes to eliminate use of deprecated features. For instance,
166 //using notify(SC_ZERO_TIME) in place of notify_delayed().
167 //
168 //Revision 1.5 2006/01/19 19:18:25 acg
169 //Andy Goodrich: eliminated check_writer in favor of inline code within the
170 //write() method since we always execute the check_writer code even when
171 //check writing is turned off.
172 //
173 //Revision 1.4 2006/01/19 00:30:57 acg
174 //Andy Goodrich: Yet another implementation for disabling write checks on
175 //signals. This version uses an environment variable, SC_SIGNAL_WRITE_CHECK,
176 //that when set to DISABLE will turn off write checking.
177 //
178 //Revision 1.3 2006/01/13 18:47:20 acg
179 //Reversed sense of multiwriter signal check. It now defaults to ON unless the
180 //user defines SC_NO_WRITE_CHEK before inclusion of the file.
181 //
182 //Revision 1.2 2006/01/03 23:18:26 acg
183 //Changed copyright to include 2006.
184 //
185 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
186 //First check in of SystemC 2.1 into its own archive.
187 //
188 //Revision 1.9 2005/06/10 22:43:55 acg
189 //Added CVS change log annotation.
190 //
191 
192 // Taf!
sc_signal< T, POL > base_type
Definition: sc_buffer.h:51
virtual const char * kind() const
Definition: sc_buffer.h:86
sc_buffer< T, POL > this_type
Definition: sc_buffer.h:50
this_type & operator=(const T &a)
Definition: sc_buffer.h:77
const char * sc_gen_unique_name(const char *, bool preserve_first)
virtual const T & read() const =0
sc_buffer(const char *name_, const T &initial_value_)
Definition: sc_buffer.h:65
virtual void write(const T &)
Definition: sc_buffer.h:107
virtual void update()
Definition: sc_buffer.h:120
virtual const T & read() const
Definition: sc_signal.h:130
sc_buffer(const char *name_)
Definition: sc_buffer.h:61