diff options
author | Marcus Müller <mmueller@gnuradio.org> | 2020-06-20 19:31:23 +0200 |
---|---|---|
committer | mormj <34754695+mormj@users.noreply.github.com> | 2020-06-24 11:36:46 -0400 |
commit | 9d01e324c995ba31bddf2909d86f370fdb78bc53 (patch) | |
tree | 5491e570b41bdc3ea39e6cc0d0257d66cb7eb68a | |
parent | 4644dd50e99f390b0066e5f6692bc96d7a0d8cb4 (diff) |
modtool: make C++ blocks compile by default
Formerly, a freshly `gr_modtool add`ed block would not compile.
* replaced <+{MIN,MAX}_{IN,OUT}+> (which relatively rarely need adjustment in the
new user case) by sensible defaults (that being 1). Added in-line comment to
document the meaning of these values.
* replaced C-style casts with reinterpret_cast of the block in- and
output types
* only add these casts when appropriate (eg. no `input_type *in` in
sources; these were actually undefined behaviour in case you tried to
cast the [0] element of a in/output vector that didn't exist)
* defined above type in the _impl.cc quite up top, hard to miss.
* used said type in the io_signature
Not compiling by default sounds like a good idea to let the tooling
point out what you still have to implement. But then again, if you `add`
a new block, you probably know that you have to write a `work` etc.
However, preprocessor warnings are used to inform users that they need
to adjust/implement something.
-rw-r--r-- | gr-utils/modtool/templates/templates.py | 48 |
1 files changed, 36 insertions, 12 deletions
diff --git a/gr-utils/modtool/templates/templates.py b/gr-utils/modtool/templates/templates.py index 264fc698f1..ff8d483556 100644 --- a/gr-utils/modtool/templates/templates.py +++ b/gr-utils/modtool/templates/templates.py @@ -111,6 +111,14 @@ namespace gr { { } % else: + % if blocktype != "source": + #pragma message("set the following appropriately and remove this warning") + using input_type = float; + % endif + % if blocktype != "sink": + #pragma message("set the following appropriately and remove this warning") + using output_type = float; + % endif ${blockname}::sptr ${blockname}::make(${strip_default_values(arglist)}) { @@ -120,23 +128,26 @@ namespace gr { <% if blocktype == 'decimator': - decimation = ', <+decimation+>' + #pragma message("set the following appropriately and remove this warning") + decimation = ', 2 /*<+decimation+>*/' elif blocktype == 'interpolator': - decimation = ', <+interpolation+>' + #pragma message("set the following appropriately and remove this warning") + decimation = ', 2 /*<+interpolation+>*/' elif blocktype == 'tagged_stream': - decimation = ', <+len_tag_key+>' + #pragma message("set the following appropriately and remove this warning") + decimation = ', /*<+len_tag_key+>*/' else: decimation = '' endif if blocktype == 'source': inputsig = '0, 0, 0' else: - inputsig = '<+MIN_IN+>, <+MAX_IN+>, sizeof(<+ITYPE+>)' + inputsig = '1, 1/* min, max nr of inputs */, sizeof(input_type)' endif if blocktype == 'sink': outputsig = '0, 0, 0' else: - outputsig = '<+MIN_OUT+>, <+MAX_OUT+>, sizeof(<+OTYPE+>)' + outputsig = '1, 1/* min, max nr of outputs */, sizeof(output_type)' endif %> /* @@ -167,6 +178,7 @@ namespace gr { void ${blockname}_impl::forecast (int noutput_items, gr_vector_int &ninput_items_required) { + #pragma message("implement a forecast that fills in how many items on each input you need to produce noutput_items and remove this warning") /* <+forecast+> e.g. ninput_items_required[0] = noutput_items */ } @@ -176,9 +188,14 @@ namespace gr { gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - const <+ITYPE+> *in = (const <+ITYPE+> *) input_items[0]; - <+OTYPE+> *out = (<+OTYPE+> *) output_items[0]; + % if blocktype != 'source': + const input_type *in = reinterpret_cast<const input_type*>(input_items[0]); + % endif + % if blocktype != 'sink': + output_type *out = reinterpret_cast<output_type*>(output_items[0]); + % endif + #pragma message("Implement the signal processing in your block and remove this warning") // Do <+signal processing+> // Tell runtime system how many input items we consumed on // each input stream. @@ -191,7 +208,8 @@ namespace gr { int ${blockname}_impl::calculate_output_stream_length(const gr_vector_int &ninput_items) { - int noutput_items = /* <+set this+> */; + #pragma message("set the following appropriately and remove this warning") + int noutput_items = 0; return noutput_items ; } @@ -201,9 +219,14 @@ namespace gr { gr_vector_const_void_star &input_items, gr_vector_void_star &output_items) { - const <+ITYPE+> *in = (const <+ITYPE+> *) input_items[0]; - <+OTYPE+> *out = (<+OTYPE+> *) output_items[0]; + % if blocktype != 'source': + const input_type *in = reinterpret_cast<const input_type*>(input_items[0]); + % endif + % if blocktype != 'sink': + output_type *out = reinterpret_cast<output_type*>(output_items[0]); + % endif + #pragma message("Implement the signal processing in your block and remove this warning") // Do <+signal processing+> // Tell runtime system how many output items we produced. @@ -217,12 +240,13 @@ namespace gr { gr_vector_void_star &output_items) { % if blocktype != 'source': - const <+ITYPE+> *in = (const <+ITYPE+> *) input_items[0]; + const input_type *in = reinterpret_cast<const input_type*>(input_items[0]); % endif % if blocktype != 'sink': - <+OTYPE+> *out = (<+OTYPE+> *) output_items[0]; + output_type *out = reinterpret_cast<output_type*>(output_items[0]); % endif + #pragma message("Implement the signal processing in your block and remove this warning") // Do <+signal processing+> // Tell runtime system how many output items we produced. |