jinhuang12 Posted October 23, 2013 Report Share Posted October 23, 2013 Hello, I want to make a server module that outputs a user defined class through sc_fifo and I'm not sure if that is possible. So far, I have this Server module header ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- #include <systemc.h> #include "Gaze.h" #include "ImageObjects.h" #include "Image.h" #include "iostream.h" #include "fstream.h" #include "string.h" #include <sstream> SC_MODULE(Server) { //PORTS FOR SERVER sc_in_clk clk; //Clock sc_in<sc_uint<8> > check; //Signal for client to request new image sc_port<sc_fifo_in<Gaze >> inClient; // input from client sc_port<sc_fifo_out<Image >> output; //output to client void sendImage(sc_uint<8> img); //Function to send image to client std::vector<Image> getImages(); //Takes in annotation files and saves them as images //Local data structures std::vector<Image> ImageBuffer; SC_CTOR(Server) { SC_METHOD(sendImage); sensitive << check; } }; ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Would "sc_port<sc_fifo_out<Image >> output;" that line of code work? Image is just a class I created in c++ ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ #include "ImageObjects.h" #include <vector> class Image : public sc_interface { public: int imageNumber; std::vector<ImageObjects> obj; Image(int i, std::vector<ImageObjects> ob); //void setImage(int, Objects[]); virtual Image returnImage(); }; --------------------------------------------------------------------------------------------------------------------------------------------- Thanks for all the help! Annossyenudge 1 Quote Link to comment Share on other sites More sharing options...
maehne Posted October 23, 2013 Report Share Posted October 23, 2013 sc_fifo_in and sc_fifo_out are already specialized ports to be connected to an sc_fifo. So, you don't need to put them as a template argument to sc_port<IF>. Regarding what kind of operations a user-defined type has to support to be communicated through an sc_fifo, have a look to clause 6.23.3 in the freely available IEEE Std 1666-2011. Basically, the output stream operator<<, an assignment operator=, and a default constructor have to be defined for that it can work. Quote Link to comment Share on other sites More sharing options...
jinhuang12 Posted October 23, 2013 Author Report Share Posted October 23, 2013 Thank you for the reply, so in order for me to pass an Image over sc_fifo, would I have to change my Image class code to something like this? template <typename T>class Image;template <typename T>ostream& operator<<(ostream &, const Image<T> &);template<typename T>class Image{public:friend ostream& operator<< <>(ostream & output, const Image<T> & theImage);...};template<typename T>ostream& operator<<(ostream & output, const Image<T> & theImage){...return output;} Can you show an example of how I would use the assignment operator and would I have to change the Image.cpp file to accommodate this change? Image.cpp ________________________________________________________________________________________________________________________________________________________________________________________ #include "Image.h" //void Image::setImage(int imageNumber, Objects objects[]) //{ // this->imageNumber = imageNumber; // // int i = 0; // while (i < sizeof(*objects)) // { // this->objects = objects; // i++; // } // //} Image::Image(int imageNumber, std::vector<ImageObjects> obj) { this->imageNumber = imageNumber; this->obj = obj; } ____________________________________________________________________________________________________________________________________________________________________________________________ Thanks again! Quote Link to comment Share on other sites More sharing options...
maehne Posted October 23, 2013 Report Share Posted October 23, 2013 The assignment operator just implements the copy operation when you want to assign the value of a variable to another one of the same type. By default, C++ generates a copy constructor and assignment operator, which will simply use member-wise assignment. This usually won't be enough if you use internally pointers and dynamic memory allocation. The sc_fifo uses the assignment operation to copy the value passed into its input into the internal buffer of the FIFO. Have a look to the Doulos FAQ on SystemC to know more about how to use user-defined data types with SystemC channels: http://www.doulos.com/knowhow/systemc/faq/#q1 For examples how to implement correctly the copy constructor and assignment operation, have a look into a good C++ book or the C++ FAQ. Here are some helpful URLs: http://www.isocpp.org/ http://www.cplusplus.com http://www.parashift.com/c++-faq/ Quote Link to comment Share on other sites More sharing options...
jinhuang12 Posted October 23, 2013 Author Report Share Posted October 23, 2013 Okay thanks again, and one more question if you dont mind, are vectors allowed to be used in a sc_module as a data structure? Quote Link to comment Share on other sites More sharing options...
apfitch Posted October 24, 2013 Report Share Posted October 24, 2013 sc_module is just a c++ class, so it can have data members of type vector, regards Alan Quote Link to comment Share on other sites More sharing options...
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.