Jump to content
katang

How to define a FIFO of custom structure

Recommended Posts

I want to define a FIFO of user-defined structures. The program below presents with message:

no match for 'operator <<'

If I change <Transfer> to <int>, int compiles fine.
 

#ifndef scMWE_h
#define scMWE_h
#include <systemc>
#include <iostream>
typedef struct {
    int Select;
    int Content;
} Transfer, *TransferPtr;

SC_MODULE(scMWE) {
    scMWE(sc_core::sc_module_name nm);
    sc_core::sc_fifo<Transfer> from;
};
#endif


#include "scMWE.h"

SC_HAS_PROCESS(scMWE);
scMWE::scMWE(sc_core::sc_module_name nm)
: sc_core::sc_module(nm)
{}

 

Share this post


Link to post
Share on other sites

The type you pass as a template argument to sc_core::sc_fifo<T> has to fulfill a couple of rules, which are described in detail in clause 6.23.3 of the IEEE Std 1666-2011. In summary, your type Transfer needs to provide:

a) The output stream operator:

std::ostream& operator<<(std::ostream&, const Transfer&);

This one is missing, which is hinted to you by the compiler error.

b) The assignment operator (not missing as auto-generated by the compiler for a struct):

const Transfer& operator=(const Transfer&);

c) The default constructor if any other constructor is defined for your type Transfer (not necessary for a pure struct as in your code snippet):

Transfer::Transfer();

 

Share this post


Link to post
Share on other sites

 

In my enhanced version, the compiler said the operator must take exactly one argument. I really cannot find out why.

#ifndef scMWE_h
#define scMWE_h
#include <systemc>
#include <iostream>

struct Transfer_Type
{
    int Select;
    int Content;
    std::ostream& operator << (std::ostream& os, const Transfer_Type& I)
    {
      return os;
    }

};

SC_MODULE(scMWE) {
    scMWE(sc_core::sc_module_name nm);
    sc_core::sc_fifo<Transfer_Type> from;
};
#endif

 

Share this post


Link to post
Share on other sites

Hello @katang,

You need to declare the method as a friend method and the definition has to be moved to corresponding source file.

For e.g.:

// scMWE.h
#ifndef scMWE_h
#define scMWE_h
#include <systemc>
#include <iostream>

struct Transfer_Type
{
    int Select;
    int Content;
    friend std::ostream& operator << (std::ostream& os, const Transfer_Type& I); //< Declaration for the friend method.
};

SC_MODULE(scMWE) {
    scMWE(sc_core::sc_module_name nm);
    sc_core::sc_fifo<Transfer_Type> from;
};
#endif

scMwe.cpp:

// scMWE.cpp
#include "scMWE.h"

// Definition for the friend method.
std::ostream& operator << (std::ostream& os, const Transfer_Type& I)
{
  return os;
}

Hope it helps.

Regards,

Ameya Vikram Singh

Share this post


Link to post
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...