|
From: | Marcus Müller |
Subject: | Re: [Discuss-gnuradio] Proper block inheritance |
Date: | Wed, 11 Sep 2013 12:44:28 +0200 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130804 Thunderbird/17.0.8 |
Hi Nemanja,
I don't think deriving from two blocks will work; C++ allows you two have multiple superclasses, sure enough, but what deriving from two subclasses of the same base class (at least gr::block in this case) will give you is the so-called diamond problem. As an example let's say you've got something of the like: class Nemajas_Block public gr::awesome_block, gr::coolness_block; with both awesome_block and coolness_block not being abstract classes (thus, you can create instances of awesome_block and coolness_block). As a matter of fact, an instance of Nemajas_Block will *contain* the data of an awesome_block and the coolness_block, and those two each contain an own gr::block object.* So there's two basic_block s that represent your instance of Nemajas_Block, of which only one will be connected... I haven't tried this, but I'd think this will lead to the GR runtime telling you to connect the unconnected parts. So long answer short: No, I don't think there is an example where a block is derived from two isolated working blocks, because that's not a good idea. There are, however, examples, where, using the virtual inheritance method, a block is derived from a base block and gr::block directly; take gr::analog::pwr_squelch_ff. Look closely where they use the virtual inheritance method! I'm not quite sure however, why, for your particular problem, you can't take either a) the gr::blocks::file_sink way (inherit from gr::block and from a non-block class) or b) just put your algorithmic implementation into subclasses of a common (non-block) deframer_algorithm_base_class, and have your block hold a pointer to an arbitrary one of those, calling that to deframe when needed. Hope that was helpful Marcus *unless inheritance was defined as ":(public|private|protected|) virtual superclass" all the inheritance chain down, but from looking at the source, I'd think this is not usually the case (especially not for sync_block). Am 11.09.2013 10:41, schrieb Nemanja Savic:
|
[Prev in Thread] | Current Thread | [Next in Thread] |