TLM-2.0  2.0.3
Accellera TLM-2.0 proof-of-concept library
tlm_analysis_port.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 #ifndef __TLM_ANALYSIS_PORT_H__
19 #define __TLM_ANALYSIS_PORT_H__
20 
22 #include <deque>
23 #include <algorithm>
24 
25 namespace tlm {
26 
27 
28 template < typename T>
30  public sc_core::sc_object ,
31  public virtual tlm_analysis_if< T >
32 {
33  public:
34  tlm_analysis_port() : sc_core::sc_object() {}
35  tlm_analysis_port( const char *nm ) : sc_core::sc_object( nm ) {}
36 
37  // bind and () work for both interfaces and analysis ports, since
38  // analysis ports implement the analysis interface
39 
40  virtual void bind( tlm_analysis_if<T> &_if ) {
41  m_interfaces.push_back( &_if );
42  }
43 
44  void operator() ( tlm_analysis_if<T> &_if ) { bind( _if ); }
45 
46  virtual bool unbind( tlm_analysis_if<T> &_if ) {
47 
48  typename std::deque< tlm_analysis_if<T> * >::iterator i
49  = std::remove( m_interfaces.begin(), m_interfaces.end(), &_if );
50 
51  if( i != m_interfaces.end() ) {
52  m_interfaces.erase(i, m_interfaces.end() );
53  return 1;
54  }
55 
56  return 0;
57 
58  }
59 
60  void write( const T &t ) {
61  typename std::deque< tlm_analysis_if<T> * >::iterator i;
62 
63  for( i = m_interfaces.begin();
64  i != m_interfaces.end();
65  i++ ) {
66 
67  (*i)->write( t );
68 
69  }
70 
71  }
72 
73  private:
74  std::deque< tlm_analysis_if<T> * > m_interfaces;
75 
76 };
77 
78 } // namespace tlm
79 
80 #endif
81 
82 
tlm_analysis_port(const char *nm)
void operator()(tlm_analysis_if< T > &_if)
virtual bool unbind(tlm_analysis_if< T > &_if)
void write(const T &t)
virtual void bind(tlm_analysis_if< T > &_if)