SystemC  2.3.2
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 */
34 #ifndef SC_EVENT_FINDER
35 #define SC_EVENT_FINDER
36 
37 
39 
40 namespace sc_core {
41 
49 {
50  friend class sc_simcontext;
51 
52 public:
53 
54  const sc_port_base& port() const
55  { return m_port; }
56 
57  // destructor (does nothing)
58  virtual ~sc_event_finder();
59 
60  virtual const sc_event& find_event( sc_interface* if_p = 0 ) const = 0;
61 
62 protected:
63 
64  // constructor
65  sc_event_finder( const sc_port_base& );
66 
67  // error reporting
68  void report_error( const char* id, const char* add_msg = 0 ) const;
69 
70 
71 private:
72  const sc_port_base& m_port; // port providing the event.
73 
74 private:
75 
76  // disabled
79  sc_event_finder& operator = ( const sc_event_finder& );
80 };
81 
82 
89 template <class IF>
91 : public sc_event_finder
92 {
93 public:
94 
95  // constructor
96 
98  const sc_event& (IF::*event_method_) () const )
99  : sc_event_finder( port_ ), m_event_method( event_method_ )
100  {}
101 
102  // destructor (does nothing)
103 
105  {}
106 
107  virtual const sc_event& find_event( sc_interface* if_p = 0 ) const;
108 
109 private:
110 
111  const sc_event& (IF::*m_event_method) () const;
112 
113 private:
114 
115  // disabled
118  sc_event_finder_t<IF>& operator = ( const sc_event_finder_t<IF>& );
119 };
120 
121 
122 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
123 
124 template <class IF>
125 inline
126 const sc_event&
128 {
129  const IF* iface = ( if_p ) ? dynamic_cast<const IF*>( if_p ) :
130  dynamic_cast<const IF*>( port().get_interface() );
131  if( iface == 0 ) {
132  report_error( SC_ID_FIND_EVENT_, "port is not bound" );
133  return sc_event::none;
134  }
135  return (const_cast<IF*>( iface )->*m_event_method) ();
136 }
137 
138 } // namespace sc_core
139 
140 //$Log: sc_event_finder.h,v $
141 //Revision 1.3 2011/08/26 20:45:39 acg
142 // Andy Goodrich: moved the modification log to the end of the file to
143 // eliminate source line number skew when check-ins are done.
144 //
145 //Revision 1.2 2011/02/18 20:23:45 acg
146 // Andy Goodrich: Copyright update.
147 //
148 //Revision 1.1.1.1 2006/12/15 20:20:04 acg
149 //SystemC 2.3
150 //
151 //Revision 1.4 2006/02/02 23:42:37 acg
152 // Andy Goodrich: implemented a much better fix to the sc_event_finder
153 // proliferation problem. This new version allocates only a single event
154 // finder for each port for each type of event, e.g., pos(), neg(), and
155 // value_change(). The event finder persists as long as the port does,
156 // which is what the LRM dictates. Because only a single instance is
157 // allocated for each event type per port there is not a potential
158 // explosion of storage as was true in the 2.0.1/2.1 versions.
159 //
160 //Revision 1.3 2006/02/02 20:43:09 acg
161 // Andy Goodrich: Added an existence linked list to sc_event_finder so that
162 // the dynamically allocated instances can be freed after port binding
163 // completes. This replaces the individual deletions in ~sc_bind_ef, as these
164 // caused an exception if an sc_event_finder instance was used more than
165 // once, due to a double freeing of the instance.
166 //
167 //Revision 1.2 2006/01/03 23:18:26 acg
168 //Changed copyright to include 2006.
169 //
170 //Revision 1.1.1.1 2005/12/19 23:16:43 acg
171 //First check in of SystemC 2.1 into its own archive.
172 //
173 //Revision 1.10 2005/09/15 23:01:51 acg
174 //Added std:: prefix to appropriate methods and types to get around
175 //issues with the Edison Front End.
176 //
177 //Revision 1.9 2005/06/10 22:43:55 acg
178 //Added CVS change log annotation.
179 //
180 
181 #endif
182 
183 // Taf!
Interface specific event finder class.
Base classes of all port classes.
Event finder base class.
Abstract base class for class sc_port_b.
Definition: sc_port.h:81
The event class.
Definition: sc_event.h:256
static const sc_event none
Definition: sc_event.h:306
Abstract base class of all interface classes.
Definition: sc_interface.h:51
The simulation context.
virtual const sc_event & find_event(sc_interface *if_p=0) const
const sc_port_base & port() const
sc_event_finder_t(const sc_port_base &port_, const sc_event &(IF::*event_method_)() const)
#define SC_API
Definition: sc_cmnhdr.h:168