SystemC 3.0.0
Accellera SystemC proof-of-concept library
sc_event_finder.h
Go to the documentation of this file.
1/*****************************************************************************
2
3 Licensed to Accellera Systems Initiative Inc. (Accellera) under one or
4 more contributor license agreements. See the NOTICE file distributed
5 with this work for additional information regarding copyright ownership.
6 Accellera licenses this file to you under the Apache License, Version 2.0
7 (the "License"); you may not use this file except in compliance with the
8 License. You may obtain a copy of the License at
9
10 http://www.apache.org/licenses/LICENSE-2.0
11
12 Unless required by applicable law or agreed to in writing, software
13 distributed under the License is distributed on an "AS IS" BASIS,
14 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
15 implied. See the License for the specific language governing
16 permissions and limitations under the License.
17
18 *****************************************************************************/
19
20/*****************************************************************************
21
22 sc_event_finder.h --
23
24 Original Author: Martin Janssen, Synopsys, Inc.
25 Stan Y. Liao, Synopsys, Inc., 2001-05-21
26
27 CHANGE LOG IS AT THE END OF THE FILE
28 *****************************************************************************/
29
30#ifndef SC_EVENT_FINDER
31#define SC_EVENT_FINDER
32
33
35
36namespace sc_core {
37
38// ----------------------------------------------------------------------------
39// CLASS : sc_event_finder
40//
41// Event finder base class.
42// ----------------------------------------------------------------------------
43
45{
46 friend class sc_simcontext;
47
48public:
49 // helper to create an event finder on demand and cache in given pointer
50 // - if cache_p is NULL, allocate a new sc_event_finder_t<IF>
51 // for the given function, save allocated pointer in cache_p
52 // - returns dereferenced cache_p pointer
53 template<typename IF>
54 static sc_event_finder&
55 cached_create( sc_event_finder*& cache_p, const sc_port_base& port_
56 , const sc_event& (IF::*ef_p)() const );
57
58 const sc_port_base& port() const
59 { return m_port; }
60
61 // destructor (does nothing)
63
64 virtual const sc_event& find_event( sc_interface* if_p = 0 ) const = 0;
65
66protected:
67
68 // constructor
70
71 // error reporting
72 void report_error( const char* id, const char* add_msg = 0 ) const;
73
74
75private:
76 const sc_port_base& m_port; // port providing the event.
77
78private:
79
80 // disabled
83 sc_event_finder& operator = ( const sc_event_finder& );
84};
85
86
87// ----------------------------------------------------------------------------
88// CLASS : sc_event_finder_t<IF>
89//
90// Interface specific event finder class.
91// ----------------------------------------------------------------------------
92
93template <class IF>
95: public sc_event_finder
96{
97public:
98
99 // constructor
100
102 const sc_event& (IF::*event_method_) () const )
103 : sc_event_finder( port_ ), m_event_method( event_method_ )
104 {}
105
106 // destructor (does nothing)
107
109 {}
110
111 virtual const sc_event& find_event( sc_interface* if_p = 0 ) const;
112
113private:
114
115 const sc_event& (IF::*m_event_method) () const;
116
117private:
118
119 // disabled
122 sc_event_finder_t<IF>& operator = ( const sc_event_finder_t<IF>& );
123};
124
125
126// IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
127
128
129template <class IF>
130inline
131sc_event_finder&
133 , const sc_port_base& port_
134 , const sc_event& (IF::*ef_p)() const )
135{
136 if( !cache_p ) {
137 cache_p = new sc_event_finder_t<IF>( port_, ef_p );
138 }
139 sc_assert( &port_ == &cache_p->port() );
140 return *cache_p;
141}
142
143
144template <class IF>
145inline
146const sc_event&
148{
149 const IF* iface = ( if_p ) ? dynamic_cast<const IF*>( if_p ) :
150 dynamic_cast<const IF*>( port().get_interface() );
151 if( iface == 0 ) {
152 report_error( SC_ID_FIND_EVENT_, "port is not bound" );
153 return sc_event::none();
154 }
155 return (const_cast<IF*>( iface )->*m_event_method) ();
156}
157
158} // namespace sc_core
159
160//$Log: sc_event_finder.h,v $
161//Revision 1.3 2011/08/26 20:45:39 acg
162// Andy Goodrich: moved the modification log to the end of the file to
163// eliminate source line number skew when check-ins are done.
164//
165//Revision 1.2 2011/02/18 20:23:45 acg
166// Andy Goodrich: Copyright update.
167//
168//Revision 1.1.1.1 2006/12/15 20:20:04 acg
169//SystemC 2.3
170//
171//Revision 1.4 2006/02/02 23:42:37 acg
172// Andy Goodrich: implemented a much better fix to the sc_event_finder
173// proliferation problem. This new version allocates only a single event
174// finder for each port for each type of event, e.g., pos(), neg(), and
175// value_change(). The event finder persists as long as the port does,
176// which is what the LRM dictates. Because only a single instance is
177// allocated for each event type per port there is not a potential
178// explosion of storage as was true in the 2.0.1/2.1 versions.
179//
180//Revision 1.3 2006/02/02 20:43:09 acg
181// Andy Goodrich: Added an existence linked list to sc_event_finder so that
182// the dynamically allocated instances can be freed after port binding
183// completes. This replaces the individual deletions in ~sc_bind_ef, as these
184// caused an exception if an sc_event_finder instance was used more than
185// once, due to a double freeing of the instance.
186//
187//Revision 1.2 2006/01/03 23:18:26 acg
188//Changed copyright to include 2006.
189//
190//Revision 1.1.1.1 2005/12/19 23:16:43 acg
191//First check in of SystemC 2.1 into its own archive.
192//
193//Revision 1.10 2005/09/15 23:01:51 acg
194//Added std:: prefix to appropriate methods and types to get around
195//issues with the Edison Front End.
196//
197//Revision 1.9 2005/06/10 22:43:55 acg
198//Added CVS change log annotation.
199//
200
201#endif
202
203// Taf!
#define SC_API
Definition: sc_cmnhdr.h:148
#define sc_assert(expr)
Definition: sc_report.h:248
const char SC_ID_FIND_EVENT_[]
void report_error(const char *id, const char *add_msg=0) const
const sc_port_base & port() const
static sc_event_finder & cached_create(sc_event_finder *&cache_p, const sc_port_base &port_, const sc_event &(IF::*ef_p)() const)
virtual const sc_event & find_event(sc_interface *if_p=0) const =0
sc_event_finder(const sc_port_base &)
sc_event_finder_t(const sc_port_base &port_, const sc_event &(IF::*event_method_)() const)
virtual const sc_event & find_event(sc_interface *if_p=0) const
static const sc_event & none()
Definition: sc_event.h:309