getField() type checking #17

Closed
mpgerlek opened this Issue Aug 27, 2011 · 2 comments

2 participants

@mpgerlek
PDAL member

One day, I wrote this:

double z = data.getField<boost::int32_t>(pointIndex, indexZ);

where of course I really meant this:

double z = data.getField<double>(pointIndex, indexZ);

Note the wrong template type. The problem here is that there's no way to typecheck the return type T is the type we want.

Hobu suggests decltype might help ( http://en.wikipedia.org/wiki/Decltype).

mpg alternatively suggests changing the function from this:

T getField(std::size_t ptIdx, boost::int32_t fieldIdx)

to this:

void getField(std::size_t ptIdx, boost::int32_t fieldIdx, T& ret)

Neither suggestion is very palatable, though.

@hobu
PDAL member

getField is slightly better now (you must pass in the actual dimension instance, not just a dimension position), but this same issue can still happen.

getField is the critical path, however, and any checking in here causes things to be slow. I don't know that we want to try to do type checking.

@hobu
PDAL member

Closing. get/setField now take in a Dimension object, which while not eliminating the type mismatch thing, lessens it greatly.

@hobu hobu closed this Aug 28, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment