I'm trying to create a base gr_constellation class, which would be a
helper object for
doing QAM-like modulations. It would contain a list of the
constellation points, and
a decision_maker function for demodulation. To implement different
QAM-like modulations you
would subclass gr_constellation.
I thought I should try to use shared pointers for the gr_constellation
objects (since that's what's used
for the blocks and presumably there are good reasons). I can get
everything working fine
until I subclass gr_constellation and then pass a shared pointer to
the subclass to a function expecting
the parent shared pointer object.
i.e. B is a subclass of A
sA is a shared pointer to A
sB is a shared pointer to B
f(sA) is a function expecting a shared pointer to A
If I pass sB to f() then an error is raised.
This error only occurs at the python level.
At the C++ level I can pass sB to f() without a problem.
This problem appears to have been solved in gnuradio already, since
the connect functions accept a shared
pointer to any of the blocks. However, I haven't been able to work
out how it's done. Does anyone know
how to do this? I thought perhaps gr_basic_block::basic_block() has
something to do with this but
haven't been able to track it down.
I'm now including the contents of a few files that reproduce this
problem independently of gnuradio, although
they require the gr_shared_ptr.i file.
To compile I run:
swig -c++ -python -Iboost blah.i
python setup.py build_ext --inplace
And then test with:
python test.py
Cheers,
Ben
---blah.h------------------------------------
#ifndef INCLUDED_BLAH_H
#define INCLUDED_BLAH_H
#include <boost/shared_ptr.hpp>
class Blah {};
class Bloop : public Blah {};
typedef boost::shared_ptr<Blah> blah_sptr;
typedef boost::shared_ptr<Bloop> bloop_sptr;
void do_something (blah_sptr bls);
blah_sptr make_blah();
bloop_sptr make_bloop();
No comments:
Post a Comment