Tomographer
v1.0a
Tomographer C++ Framework Documentation
|
Specializable template which takes care of decoding values. More...
#include <tomographer/tools/ezmatio.h>
Public Types | |
typedef T | RetType |
Type returned by decodeValue() More... | |
Static Public Member Functions | |
static void | checkShape (const Var &var) |
Check that the type and shape of the var are compatible with T. More... | |
static RetType | decodeValue (const Var &var) |
Decode the variable var into the C++ type T. More... | |
Specializable template which takes care of decoding values.
Specialize this template to your favorite return type to define a decoder for that type.
This class does two things:
It may be that the decoding routine might not want to have directly T as a return type, but rather return a type which is convertible to T or which can be used as an initializer for a T. (Think, for example, an Eigen mapped type.)
Another reason for not returning T directly is if T is a proxy type which describes which type is requested along with some parameters (e.g. storage order). See for example GetStdVector.
This default class template does nothing. Specialize it for your C++ type or use one of the available specializations.
The Enabled template parameter is provided for convenience, if you wish to employ SFINAE to conditionally enable specializations. See the VarValueDecoder<T> for simple numeric values for an example.
typedef T Tomographer::MAT::VarValueDecoder< T, Enabled >::RetType |
Type returned by decodeValue()
The specialization of VarValueDecoder<T> should explicitly specify which type is returned by the main decoding routine (see class doc).
|
inlinestatic |
Check that the type and shape of the var are compatible with T.
Specializations of VarValueDecoder<T> should implement this function and check whether the given variable can be decoded into the requested C++ type T. If there is any error, throw a VarTypeError exception.
|
inlinestatic |
Decode the variable var into the C++ type T.
Specializations of VarValueDecoder<T> should implement this function to read data in the MATLAB variable var and return an instance of the requested C++ type T.
Note the return type of this function need not be T itself, but any type you like, presumably one that is convertible to T, assignable to T, or which can be used as initializer for T. You may find this useful if you want to return an initializer type such as, e.g., an Eigen generator expression.
Do note, though, that with modern compilers performing return value optimization (RVO), in most cases there shouldn't be any real overhead in returning a T directly.