discuss-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Discuss-gnuradio] Initialize a pointer - object


From: Jose Torres Diaz
Subject: Re: [Discuss-gnuradio] Initialize a pointer - object
Date: Fri, 5 Oct 2012 10:21:54 +0930

Many thanks for the information Ben, I will check again. However, I would like to point out that the work function is implemented in my .cc file (I've attached the file for you). Thanks again!

.cc file:


#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <asrp_fec_encoder.h>
#include <asrp_utility.h>
#include <gr_io_signature.h>
#include <stdio.h>
#include <boost/format.hpp>
#include <boost/foreach.hpp>
#include <assert.h>
#include <iostream>

//Need it for extras. 4 Oct
#include <gnuradio/extras/api.h>

/*
 * Create a new instance of asrp_fec_encoder and return
 * a boost shared_ptr.  This is effectively the public constructor.
 */
//asrp_ra_encoder_bb_sptr
//asrp_make_ra_encoder_bb (const char *code_filename)
//Change on 4/October/2012
asrp_fec_encoder_sptr
asrp_make_fec_encoder (const char *code_filename)
//asrp_make_fec_encoder (const char &code_filename)
{
  //return asrp_ra_encoder_bb_sptr (new asrp_ra_encoder_bb (code_filename));
  return asrp_fec_encoder_sptr (new asrp_fec_encoder (code_filename)); //"New" cannot allocate for the virtual function
}

/*
 * Specify constraints on number of input and output streams.
 * This info is used to construct the input and output signatures
 * (2nd & 3rd args to gr_block's constructor).  The input and
 * output signatures are used by the runtime system to
 * check that a valid number and type of inputs and outputs
 * are connected to this block.  In this case, we accept
 * only 1 input and 1 output.
 */
static const int MIN_IN = 1;    // mininum number of input streams
static const int MAX_IN = 1;    // maximum number of input streams
static const int MIN_OUT = 1;    // minimum number of output streams
static const int MAX_OUT = 1;    // maximum number of output streams

/*
 * The private constructor
 */
asrp_fec_encoder::asrp_fec_encoder (const char *code_filename)
   : block ("fec_encoder",
              gr_make_io_signature (0, 0, 0),
              gr_make_io_signature (0, 0, 0),
      msg_signature(true,1)
      ),
     _code_filename(code_filename)  //New object, this is still failing
{
  d_burst_start_key = pmt::pmt_string_to_symbol("burst_start");

    assert(d_ra_encoder->readDecoder(_code_filename)==1); //Using this new object


  // Don't automatically propagate tags, we'll do it in work()
  //set_tag_propagation_policy(TPP_DONT); // 4 Oct. Not need it

}

/*
 * Our virtual destructor.
 */
asrp_fec_encoder::~asrp_fec_encoder ()

{
  delete d_ra_encoder;
  delete [] d_info_p;
  delete [] d_parity_p;
  delete [] d_info_bytes;
  delete [] d_parity_bytes;
}


int
asrp_fec_encoder::work (int noutput_items,
              gr_vector_const_void_star &input_items,
              gr_vector_void_star &output_items)
{
 
//My work function is here
    }
 

  // Number of items read so far on input buffer
  uint64_t in_start = nitems_read(0);
  // The number of items written on our output stream so far.
  // Used to place the start/end of burst tags.
  uint64_t out_start = nitems_written(0);

  // Get all tags in the input buffer
  std::vector<gr_tag_t> all_tags;
  get_tags_in_range(all_tags, 0, in_start, in_start+num_inputs);


  // Loop through all tags and output what they are along with their value
  BOOST_FOREACH(const gr_tag_t &current_tag, all_tags) {
    const uint64_t offset = current_tag.offset;
    const pmt::pmt_t &value = current_tag.value;

    // Calculate position of output tag
    uint64_t out_tag_pos = out_start + (current_tag.offset - in_start)*d_interp_factor;

    // If we find a burst_start key, we modify the burst length appropriately
    if (current_tag.key == d_burst_start_key) {
      unsigned long new_len = pmt::pmt_to_long(current_tag.value) * d_interp_factor;
      // add_item_tag(0,            // stream ID
      //            out_tag_pos,    
      //            current_tag.key,
      //            pmt::pmt_from_long(new_len),     
      //            current_tag.srcid);
    }
    // else
    //   // output new tag unchanged except for updated position
    //   add_item_tag(0,            // stream ID
    //            out_tag_pos,    
    //            current_tag.key,
    //            current_tag.value,     
    //            current_tag.srcid);
   
  }


  // Tell runtime system how many output items we produced.
  return num_outputs;
}

Regards,

Jose




On Fri, Oct 5, 2012 at 3:58 AM, Ben Hilburn <address@hidden> wrote:
Your error message states that the issue isn't your _impl function, but rather the fact that you haven't implemented 'work'

cannot allocate an object of abstract type 'asrp_fec_encoder'
because the following virtual functions are pure within 'asrp_fec_encoder':
/usr/local/include/gnuradio/block.h:236:17: note:     virtual int gnuradio::block::work(const InputItems&, const OutputItems&)
asrp_fec_encoder.cc: In constructor 'asrp_fec_encoder::asrp_fec_encoder(const char*)':

You may find reading up on virtual inheritance helpful:
http://www.cplusplus.com/doc/tutorial/polymorphism/
http://www.learncpp.com/cpp-tutorial/118-virtual-base-classes/

Cheers,
Ben

 


Regards,

Jose




On Wed, Oct 3, 2012 at 3:03 PM, Jose Torres Diaz <address@hidden> wrote:
Hi,

I'm modifying the block BLOB_TO_STREAM and I would like to pass a pointer to that function. The original file (blob_to_stream.cc) is like this:

class blob_to_stream_impl : public blob_to_stream{
public:
    blob_to_stream_impl(const size_t item_size):
        block(
            "blob_to_stream",
            gr_make_io_signature(0, 0, 0),
            gr_make_io_signature(1, 1, item_size),
            msg_signature(true, 0)
        ),
        _item_size(item_size)
    {
        _offset = 0;
    }

//Work function here
       
private:
    const size_t _item_size;
    gr_tag_t _msg;
    size_t _offset;
};

My new version, it will be something like this:

class blob_to_stream_impl : public blob_to_stream{
public:
    blob_to_stream_impl(const size_t *file):
        block(
            "blob_to_stream",
            gr_make_io_signature(0, 0, 0),
            gr_make_io_signature(1, 1, item_size),
            msg_signature(true, 0)
        ),
    
    {
        _offset = 0;
    }

But my question is, how can I initialize the pointer *file here?. I tried different methods, but I always get an error.

Any comment will be highly appreciate it,

Cheers,

Jose




_______________________________________________
Discuss-gnuradio mailing list
address@hidden
https://lists.gnu.org/mailman/listinfo/discuss-gnuradio






reply via email to

[Prev in Thread] Current Thread [Next in Thread]