| 1 | |
| 2 | #ifndef ANALYSIS_PORT_HEADER |
| 3 | #define ANALYSIS_PORT_HEADER |
| 4 | |
| 5 | #include "analysis/analysis_if.h" |
| 6 | #include <deque> |
| 7 | |
| 8 | |
| 9 | template < typename T> |
| 10 | class analysis_port : |
| 11 | public sc_object , |
| 12 | public virtual analysis_if< T > |
| 13 | { |
| 14 | public: |
| 15 | analysis_port() : sc_object() {} |
| 16 | analysis_port( const char *nm ) : sc_object( nm ) {} |
| 17 | |
| 18 | // bind and () work for both interfaces and analysis ports, since |
| 19 | // analysis ports implement the analysis interface |
| 20 | |
| 21 | void bind( analysis_if<T> &_if ) { |
| 22 | m_interfaces.push_back( &_if ); |
| 23 | } |
| 24 | |
| 25 | void operator() ( analysis_if<T> &_if ) { bind( _if ); } |
| 26 | |
| 27 | bool unbind( analysis_if<T> &_if ) { |
| 28 | |
| 29 | typename std::deque< analysis_if<T> *>::iterator i; |
| 30 | |
| 31 | for( i = m_interfaces.begin(); |
| 32 | i != m_interfaces.end(); |
| 33 | i++ ) { |
| 34 | |
| 35 | if( *i == &_if ) { |
| 36 | |
| 37 | m_interfaces.erase( i ); |
| 38 | return 1; |
| 39 | |
| 40 | } |
| 41 | |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | |
| 46 | } |
| 47 | |
| 48 | void write( const T &t ) { |
| 49 | typename std::deque< analysis_if<T> * >::iterator i; |
| 50 | |
| 51 | for( i = m_interfaces.begin(); |
| 52 | i != m_interfaces.end(); |
| 53 | i++ ) { |
| 54 | |
| 55 | (*i)->write( t ); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | |
| 61 | private: |
| 62 | std::deque< analysis_if<T> * > m_interfaces; |
| 63 | |
| 64 | }; |
| 65 | |
| 66 | #endif |