Help for multiple class involved definition

Discussion in 'C++' started by fl, Dec 23, 2010.

  1. fl

    fl Guest

    Hi,
    I am new to C++. I do not understand why the following definition of
    "request_in_port" is a pointer:
    ..............................
    typedef tlm::tlm_generic_payload *gp_ptr; // generic payload
    .. . . . .

    sc_core::sc_port<sc_core::sc_fifo_in_if <gp_ptr> >
    request_in_port;
    .............................
    because I find that "request_in_port->read()" is used in this way:

    .............................
    tlm::tlm_generic_payload *transaction_ptr; // transaction pointer
    .. . . . . .
    transaction_ptr = request_in_port->read(); // get request from
    input fifo
    .............................

    I know that "gp_ptr" is a pointer, but what type does
    "sc_core::sc_fifo_in_if <gp_ptr>" return?

    "<sc_core::sc_fifo_in_if <gp_ptr> >" should be a class type?



    "sc_fifo_in_if<T>" is given below:
    .............................
    //
    ----------------------------------------------------------------------------
    // CLASS : sc_fifo_in_if<T>
    //
    // The sc_fifo<T> input interface class.
    //
    ----------------------------------------------------------------------------

    template <class T>
    class sc_fifo_in_if
    : public sc_fifo_nonblocking_in_if<T>,
    public sc_fifo_blocking_in_if<T>
    {
    public:

    // get the number of available samples
    virtual int num_available() const = 0;

    protected:
    }
    .........................
    I am puzzled on why "request_in_port" is a pointer. Could you help me?
    Thanks.



    BTW, the fifo read() is as below.

    .............................
    // blocking read

    template <class T>
    inline
    void
    sc_fifo<T>::read( T& val_ )
    {
    while( num_available() == 0 ) {
    sc_core::wait( m_data_written_event );
    }
    m_num_read ++;
    buf_read( val_ );
    request_update();
    }

    template <class T>
    inline
    T
    sc_fifo<T>::read()
    {
    T tmp;
    read( tmp );
    return tmp;
    }
    .................................
    fl, Dec 23, 2010
    #1
    1. Advertising

  2. fl

    fl Guest

    On 22 déc, 19:26, fl <> wrote:
    > Hi,
    > I am new to C++. I do not understand why the following definition of
    > "request_in_port" is a pointer:
    > .............................
    >   typedef tlm::tlm_generic_payload  *gp_ptr;        // generic payload
    > . . . . .
    >
    >     sc_core::sc_port<sc_core::sc_fifo_in_if  <gp_ptr> >
    > request_in_port;
    > ............................
    > because I find that "request_in_port->read()" is used in this way:
    >
    > ............................
    >   tlm::tlm_generic_payload *transaction_ptr;    // transaction pointer
    > . . . . . .
    >     transaction_ptr = request_in_port->read();  // get request from
    > input fifo
    > ............................
    >
    > I know that "gp_ptr" is a pointer, but what type does
    > "sc_core::sc_fifo_in_if  <gp_ptr>" return?
    >
    > "<sc_core::sc_fifo_in_if  <gp_ptr> >" should be a class type?
    >
    > "sc_fifo_in_if<T>" is given below:
    > ............................
    > //
    > ---------------------------------------------------------------------------­-
    > //  CLASS : sc_fifo_in_if<T>
    > //
    > //  The sc_fifo<T> input interface class.
    > //
    > ---------------------------------------------------------------------------­-
    >
    > template <class T>
    > class sc_fifo_in_if
    > : public sc_fifo_nonblocking_in_if<T>,
    >   public sc_fifo_blocking_in_if<T>
    > {
    > public:
    >
    >     // get the number of available samples
    >     virtual int num_available() const = 0;
    >
    > protected:}
    >
    > ........................
    > I am puzzled on why "request_in_port" is a pointer. Could you help me?
    > Thanks.
    >
    > BTW, the fifo read() is as below.
    >
    > ............................
    > // blocking read
    >
    > template <class T>
    > inline
    > void
    > sc_fifo<T>::read( T& val_ )
    > {
    >     while( num_available() == 0 ) {
    >         sc_core::wait( m_data_written_event );
    >     }
    >     m_num_read ++;
    >     buf_read( val_ );
    >     request_update();
    >
    > }
    >
    > template <class T>
    > inline
    > T
    > sc_fifo<T>::read()
    > {
    >     T tmp;
    >     read( tmp );
    >     return tmp;}
    >
    > ................................




    Hi,
    I just find that there is a redefinenition of -> for:
    "
    sc_core::sc_port
    "
    See below please. So, the '->" in my original post does not mean
    "request_in_port" is a pointer?
    "->" has been redefined as a method indicator? Is it so used? Am I
    right now? Thanks.






    ...................................

    //
    ----------------------------------------------------------------------------
    // CLASS : sc_port_b
    //
    // Abstract base class for class sc_port.
    //
    ----------------------------------------------------------------------------

    // allow to call methods provided by the first interface

    template <class IF>
    inline
    IF*
    sc_port_b<IF>::eek:perator -> ()
    {
    if( m_interface == 0 ) {
    report_error( SC_ID_GET_IF_, "port is not bound" );
    }
    return m_interface;
    }
    .....................................................................
    fl, Dec 23, 2010
    #2
    1. Advertising

  3. On Dec 23, 12:26 am, fl <> wrote:

    > I am new to C++. I do not understand why the following definition of
    > "request_in_port" is a pointer:
    > .............................
    >   typedef tlm::tlm_generic_payload  *gp_ptr;        // generic payload
    > . . . . .
    >
    >     sc_core::sc_port<sc_core::sc_fifo_in_if  <gp_ptr> >
    > request_in_port;
    > ............................
    > because I find that "request_in_port->read()" is used in this way:
    >
    > ............................
    >   tlm::tlm_generic_payload *transaction_ptr;    // transaction pointer
    > . . . . . .
    >     transaction_ptr = request_in_port->read();  // get request from
    > input fifo
    > ............................
    >
    > I know that "gp_ptr" is a pointer, but what type does
    > "sc_core::sc_fifo_in_if  <gp_ptr>" return?


    it doesn't return anything. It's a template type not a function.

    > "<sc_core::sc_fifo_in_if  <gp_ptr> >" should be a class type?


    well a type anyway

    > "sc_fifo_in_if<T>" is given below:
    > ............................
    > //
    > ---------------------------------------------------------------------------­-
    > //  CLASS : sc_fifo_in_if<T>
    > //
    > //  The sc_fifo<T> input interface class.
    > //
    > ---------------------------------------------------------------------------­-
    >
    > template <class T>
    > class sc_fifo_in_if
    > : public sc_fifo_nonblocking_in_if<T>,
    >   public sc_fifo_blocking_in_if<T>
    > {
    > public:
    >
    >     // get the number of available samples
    >     virtual int num_available() const = 0;
    >
    > protected:}
    >
    > ........................
    > I am puzzled on why "request_in_port" is a pointer. Could you help me?
    > Thanks.
    >
    > BTW, the fifo read() is as below.
    >
    > ............................
    > // blocking read
    >
    > template <class T>
    > inline
    > void
    > sc_fifo<T>::read( T& val_ )
    > {
    >     while( num_available() == 0 ) {
    >         sc_core::wait( m_data_written_event );
    >     }
    >     m_num_read ++;
    >     buf_read( val_ );
    >     request_update();
    >
    > }
    >
    > template <class T>
    > inline
    > T
    > sc_fifo<T>::read()
    > {
    >     T tmp;
    >     read( tmp );
    >     return tmp;}
    >
    > ................................
    Nick Keighley, Dec 30, 2010
    #3
  4. On Dec 23, 12:49 am, fl <> wrote:
    > On 22 déc, 19:26, fl <> wrote:



    > > I am new to C++. I do not understand why the following definition of
    > > "request_in_port" is a pointer:
    > > .............................
    > >   typedef tlm::tlm_generic_payload  *gp_ptr;        // generic payload
    > > . . . . .

    >
    > >     sc_core::sc_port<sc_core::sc_fifo_in_if  <gp_ptr> >
    > > request_in_port;
    > > ............................
    > > because I find that "request_in_port->read()" is used in this way:

    >
    > > ............................
    > >   tlm::tlm_generic_payload *transaction_ptr;    // transaction pointer
    > > . . . . . .
    > >     transaction_ptr = request_in_port->read();  // get request from
    > > input fifo
    > > ............................

    >
    > > I know that "gp_ptr" is a pointer,


    <snip>

    > > I am puzzled on why "request_in_port" is a pointer. Could you help me?


    <snip>

    > I just find that there is a redefinenition of -> for:
    > "
    >     sc_core::sc_port
    > "
    > See below please. So, the '->" in my original post does not mean
    > "request_in_port" is a pointer?


    not necessarily, though it ought to have "pointer like" semantics
    (that is is it should act like a pointer)

    > "->" has been redefined as a method indicator? Is it so used? Am I
    > right now? Thanks.


    well, the -> operator has been redefined for this class. It's better
    to think of all classes having a default operator->() (IMO)


    > //
    > ---------------------------------------------------------------------------­-
    > //  CLASS : sc_port_b
    > //
    > //  Abstract base class for class sc_port.
    > //
    > ---------------------------------------------------------------------------­-
    >
    > // allow to call methods provided by the first interface
    >
    > template <class IF>
    > inline
    > IF*
    > sc_port_b<IF>::eek:perator -> ()
    > {
    >     if( m_interface == 0 ) {
    >         report_error( SC_ID_GET_IF_, "port is not bound" );
    >     }
    >     return m_interface;}
    >



    this is probably what C++ calls a "smart pointer". Your C++ reference
    should be able to answer basic questions about templates and smart
    pointers
    Nick Keighley, Dec 30, 2010
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jianli Shen
    Replies:
    1
    Views:
    568
    Victor Bazarov
    Mar 13, 2005
  2. Ark
    Replies:
    1
    Views:
    405
    Chris Torek
    Aug 7, 2004
  3. Tony Young
    Replies:
    8
    Views:
    266
    Tomás
    Mar 16, 2006
  4. cyber science
    Replies:
    0
    Views:
    245
    cyber science
    Aug 25, 2009
  5. Paul  Moore
    Replies:
    5
    Views:
    186
    Paul Moore
    Dec 6, 2011
Loading...

Share This Page