# How make a \*.t block

**URL:** <https://www.ruby-forum.com/t/how-make-a-t-block/241854>\
**Category:** GNU Radio\
**Created:** [May 6, 2015, 12:48am UTC](https://www.ruby-forum.com/t/how-make-a-t-block/241854 "2015-05-06T00:48:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Detlef\_R](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/58f4c7/32.png) [@Detlef\_R](https://www.ruby-forum.com/u/Detlef_R)\
**Post date:** [May 6, 2015, 12:48am UTC](https://www.ruby-forum.com/t/how-make-a-t-block/241854/1 "2015-05-06T00:48:40Z")

</div>

Looking inside gnuradio,I’ve found blocks like divide\_XX where relative  
files have an extension .t (like divide\_XX\_impl.cc.t )…in this way,is  
possible to manage different types for the same block.  
How is posssible to create blocks like them? is necessary to use  
particular  
parameters in gr\_modtools?

I ask this because I didn’t found other clever way to manage multiple  
data  
type at the same time. I’ve tried with template, but it doesn’t  
wotk(cmake/make work,but swig doesn’t work)…also making different  
blocks(same function,different data type) which invoke the same  
template(with different parameters) doesn’t work with swig,and crash  
aslo  
the others wrapper.

Thanks,  
marco

---

<div class="post-metadata">

**Author:** ![marco\_Ribero](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/e9c0ed/32.png) [@marco\_Ribero](https://www.ruby-forum.com/u/marco_Ribero)\
**Post date:** [May 6, 2015, 8:37am UTC](https://www.ruby-forum.com/t/how-make-a-t-block/241854/2 "2015-05-06T08:37:10Z")

</div>

Hi Marco,

.t is for template, and at build time, the full implementations of these  
blocks are generated, and then compiled.  
gr\_modtool doesn’t support that. However, the magic involved is not  
really of the overly complex kind:

- CMake writes a python program to do the substitutions
- In the CMakeLists.txt, that program is applied to all templates
- the resulting headers/C++ implementations are added to the list of  
files that need to be built and linked together

For reference, open up gr-blocks/lib/CMakeLists.txt, and have a look at  
all the _EXPAND_ lines; you’ll find the matching CMake routines in  
cmake/Modules/GrMiscUtils.cmake.

SWIG _should_ handle the templates well by now, but might be  
exceptionally hard to tell it what to wrap (and what not). Also, the  
classical templating problems arise: Unless you _use_ a specific  
template specialization, it never gets built – and in the end, SWIG  
might try to wrap things that aren’t there; maybe  
[SWIG and C++](http://www.swig.org/Doc1.3/SWIGPlus.html#SWIGPlus_nn30) has an approach  
that might work for you:

/\* Instantiate a few different versions of the template \*/  
%template(intList) List;  
%template(doubleList) List;

so in your case, maybe something like

%template(marco\_block\_cc) marco\_block\<gr\_complex\>;

I haven’t tested this for a while, though.

The reason there’s these expanding templates instead of proper C++  
templates in GNU Radio is for historical reasons (SWIG didn’t use to  
handle templates at all), and for the reason that a block typically  
doesn’t care about the data that it’s being handed at all (e.g. it just  
memcpy from A to B), in which case a simple passing of the item size as  
parameter is sufficient, or it cares a lot about the type, and needs a  
different specialization for basically almost all implementations (e.g.  
multiplying two floats is optimized differently than multiplying  
complexes). So the reasonable thing to ask here is: Does your block fit  
in either of these two categories?

Greetings,  
Marcus
