要将用户定义的数据类型传递到 SystemC 通道模板中,需要将这些数据类型定义为一个类,该类还实现了不同类型的运算符<<
、=
、==
。
我需要定义一个sc_fifo
例如:
sc_fifo<route_t>
为此,必须route_t
按照以下示例编写数据类型。
class route_t
{
public:
route_dir_t route_dir;
unsigned int vc_index;
// methods allowing the structure to be passed into SystemC channels
// constructor
route_t(route_dir_t _route_dir, unsigned int _vc_index) {
route_dir = _route_dir;
vc_index = _vc_index;
}
inline bool operator == (const route_t& _route) const {
return (route_dir == _route.route_dir && vc_index == _route.vc_index);
}
inline route_t& operator = (const route_t& _route) {
route_dir = _route.route_dir;
vc_index = _route.vc_index;
return *this;
}
}; // end class route_t
- 为什么 SystemC 需要这样的实现?
- 为什么
operator=
需要返回对对象本身的引用?它只是更新内部成员。 - 可以将数据类型定义为 a
struct
而不是使用实现所需运算符的内部方法吗? - 为什么
inline
在这种情况下使用? - 返回如何
*this
等同于在方法声明中返回对对象的引用?