karandeep963 Posted July 22, 2014 Report Posted July 22, 2014 Hello All, I am wandering for overloading sc_export. Lets say at the target side I have 3 exports(same transaction type), so how to implement their write functions? class abc : public sc_module, public tlm_analysis_if<T> { public: // defining port list // Analysis Ports sc_export<tlm::tlm_analysis_if<T > > exp_1; sc_export<tlm::tlm_analysis_if<T > > exp_2; //// In the constructor exp_1(*this); exp_2(*this); Declaration: void write (const T& t){ // What about implement exp_1 } void write (const T& t){ // What about exp_2 } Please help me how to overload the write function? Thanks, Karandeep Quote
Philipp A Hartmann Posted July 22, 2014 Report Posted July 22, 2014 You can't use the "implement interface and export" idiom in this case, as you obviously can implement each function only once (for each transaction type). You can use a small wrapper instead: SC_MODULE(abc) { typedef int T; sc_core::sc_export<tlm::tlm_analysis_if<T> > exp_1, exp_2; SC_CTOR(abc) : exp_1("exp_1") , exp_2("exp_2") , aw_1(*this,&abc::write_1) // create wrapper for each implementation , aw_2(*this,&abc::write_2) { exp_1(aw_1); // bind wrappers exp_2(aw_2); } private: void write_1( const T& ); // implementation for each export void write_2( const T& ); struct analysis_wrapper : sc_core::sc_object, tlm::tlm_analysis_if<T> { typedef void (abc::*write_func)( const T& ); // pointer to member function with implementation analysis_wrapper( abc& owner, write_func f ) : sc_core::sc_object(sc_core::sc_gen_unique_name("analysis_if")) , this_(owner), f_(f){} void write( const T& v ) { (this_.*f_)(v); } // forward call to registered implementation private: abc& this_; write_func f_; }; analysis_wrapper aw_1, aw_2; }; Hope that helps, Philipp David Black and karandeep963 2 Quote
karandeep963 Posted July 23, 2014 Author Report Posted July 23, 2014 Great Many Thanks Philipp !!!! This is all what desired. -Karandeep Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.