Made most of the leaf node functions be templatized.

This templatizes them on the struct type.  The idea here is to allow
new versions of the leaf node to have a different struct layout (maybe
with an additional field) without having to worry about writing a
bunch of code that switches on the magic value fifty different times
on a single leaf node.