00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00039 #ifndef RC_PORT_HANDLE_H_
00040 #define RC_PORT_HANDLE_H_
00041
00042 #include <systemc.h>
00043
00044 #include "ReChannel/util/rc_hash_map.h"
00045 #include "ReChannel/util/rc_report.h"
00046
00047 namespace ReChannel {
00048
00049 namespace internals {
00050 namespace port_handle {
00051
00056 class port_ref
00057 {
00058 public:
00059 virtual sc_interface* get_interface() const = 0;
00060
00061 virtual sc_port_base& get_port_base() const = 0;
00062
00063 protected:
00064 virtual ~port_ref() { }
00065 };
00066
00070 template<class PORT>
00071 class port_ref_t
00072 : virtual public port_ref
00073 {
00074 public:
00075 port_ref_t(PORT& port_)
00076 : p_port(port_)
00077 { }
00078 virtual sc_interface* get_interface() const
00079 { return p_port.get_interface(); }
00080 virtual sc_port_base& get_port_base() const
00081 { return p_port; }
00082
00083 private:
00085 mutable PORT& p_port;
00086 };
00087
00088 }
00089 }
00090
00099 class rc_port_handle
00100 {
00101 private:
00104 typedef internals::port_handle::port_ref port_ref;
00108 typedef rc_hash_map<sc_port_base*, port_ref*> portmap;
00109
00110 public:
00112 rc_port_handle()
00113 : p_port_base(NULL), p_port_ref(NULL)
00114 { }
00115
00117 template<class IF, int N, sc_port_policy POL>
00118 rc_port_handle(sc_port<IF, N, POL>& port_);
00119
00125 bool valid() const
00126 { return (p_port_base != NULL); }
00127
00130 void reset()
00131 { p_port_base = NULL; p_port_ref = NULL; }
00132
00136 sc_interface* get_interface() const
00137 { return p_port_ref->get_interface(); }
00138
00142 sc_object* get_object() const
00143 { return p_port_base; }
00144
00148 sc_port_base* operator->() const
00149 { return p_port_base; }
00150
00154 sc_port_base* operator*() const
00155 { return p_port_base; }
00156
00157 operator sc_port_base*() const
00158 { return p_port_base; }
00159
00160 operator sc_object*() const
00161 { return p_port_base; }
00162
00166 bool operator==(const rc_port_handle& other) const
00167 { return p_port_base == other.p_port_base; }
00168
00173 bool operator<(const rc_port_handle& other) const
00174 { return p_port_base < other.p_port_base; }
00175
00176 private:
00181 sc_port_base* p_port_base;
00186 port_ref* p_port_ref;
00187
00188 private:
00191 static portmap p_portmap;
00192 };
00193
00194
00195
00196 template<class IF, int N, sc_port_policy POL>
00197 rc_port_handle::rc_port_handle(sc_port<IF, N, POL>& port_)
00198 : p_port_base(&port_)
00199 {
00200 typedef sc_port<IF, N, POL> port_type;
00201
00202 port_ref*& pref = p_portmap[&port_];
00203
00204 if (pref == NULL) {
00205
00206 pref = new internals::port_handle::port_ref_t<port_type>(port_);
00207 }
00208
00209 p_port_ref = pref;
00210 }
00211
00212 }
00213
00214 #endif // RC_PORT_HANDLE_H_
00215
00216
00217
00218
00219