34 #ifndef CARTOBASE_TYPE_CONVERTER_H 35 #define CARTOBASE_TYPE_CONVERTER_H 78 template<
typename INP,
typename OUTP>
82 void convert(
const INP &in, OUTP & out )
const;
86 template <
typename OUTP>
97 template <
typename INP>
116 template<
typename INP,
typename OUTP>
127 OUTP getScaledValue( INP value )
const;
130 double getscale()
const;
141 template<
typename INP,
typename OUTP>
147 void convert(
const INP &in, OUTP & out )
const;
157 template<
typename INP,
typename OUTP,
bool MODE>
163 template<
typename INP,
typename OUTP>
167 static OUTP* alloc(
const INP &in );
172 template<
typename INP,
typename OUTP>
191 template<
typename INP,
typename OUTP>
204 template<
typename INP,
typename OUTP>
207 std::numeric_limits<INP>::is_specialized
208 && std::numeric_limits<OUTP>::is_bounded >
213 std::numeric_limits<INP>::is_specialized
214 &&
std::numeric_limits<OUTP>::is_bounded >( info ) {}
219 template <
class INP,
class OUTP>
223 Converter(
bool rescale =
false ) : _rescale( rescale ), _info() {}
225 : _rescale( rescale ), _info(info) {}
237 OUTP* operator () (
const INP &in )
const;
243 virtual void convert(
const INP &in, OUTP & out )
const;
256 template <
typename INP,
typename OUTP>
263 :
Converter<INP, OUTP>( rescale, info ) {}
267 template<
typename INP,
typename OUTP>
273 template<
typename INP,
typename OUTP>
276 _defaulted_info(info)
280 template<
typename INP,
typename OUTP>
286 out = _defaulted_info.getScaledValue(in);
290 #define CARTO_SPECIALIZED_RAWCONVERTER_ROUNDED_CONVERT( INP , OUTP ) \ 293 void RawConverter< INP , OUTP >::convert( const INP &in, OUTP & out ) const \ 295 out = static_cast<OUTP>( rint( in ) ); \ 312 #undef CARTO_SPECIALIZED_RAWCONVERTER_ROUNDED_CONVERT 315 template<
typename INP,
typename OUTP>
319 out =
static_cast<OUTP
>( in );
322 template<
class INP,
class OUTP>
329 template<
class INP,
class OUTP>
337 template<
class INP,
class OUTP>
344 sc.convert( in, out );
353 #if __cplusplus >= 201103L 365 template <typename T, bool is_min=std::numeric_limits<T>::is_integer>
375 template <
typename T>
397 return ( value == carto::min_limit<T>() );
405 template<
typename TYPE,
typename TEST>
408 return ( static_cast<TYPE>(carto::min_limit<TEST>()) <= value )
412 template<
typename TYPE>
414 return ( carto::isvalidvalue<double, TYPE>( min ) ?
415 static_cast<TYPE>( min ) :
416 carto::min_limit<TYPE>() );
419 template<
typename TYPE>
421 return ( carto::isvalidvalue<double, TYPE>( max ) ?
422 static_cast<TYPE>( max ) :
430 template<
typename INP,
typename OUTP>
437 scaledvalue = ( value - this->_defaultedvmin ) * _scale
438 + this->_defaultedomin;
440 if ( scaledvalue < static_cast<double>(carto::min_limit<OUTP>())) {
441 result = carto::min_limit<OUTP>();
445 doubleconverter.
convert( scaledvalue, result );
RescalerInfo()
Construct object requesting default rescaling.
void convert(const INP &in, OUTP &out) const
bool explicitRescale() const
Test if any explicit rescaling parameters has been specified.
This converter is a bit higher-level than RawConverter and Rescaler, it switches to the one or the ot...
virtual void convert(const INP &in, OUTP &out) const
Converts INP into an existing OUTP object.
ShallowConverter(bool rescale=false)
OUTP getScaledValue(INP value) const
ConverterSwitch(const RescalerInfo &info)
Low level rescaler info used for rescaling.
TYPE getcheckedmax(double max)
Converter(bool rescale=false)
void convert(const INP &, Void &) const
#define CARTO_SPECIALIZED_RAWCONVERTER_ROUNDED_CONVERT(INP, OUTP)
Low-level rescaling converter.
ConverterSwitch(const RescalerInfo &)
void convert(const Void &, Void &) const
void convert(const Void &, OUTP &out) const
OUTP * operator()(const INP &in) const
Converts an INP type data to an OUTP data.
static OUTP * alloc(const INP &in)
This allocator is used by the top-level Converter to allocate a new object depending on the input: it...
TYPE getcheckedmin(double min)
Converter(bool rescale, const RescalerInfo &info)
bool usevtypelimits
Use limits of the input type instead of effective input min-max.
Void does not contain anything.
bool ismax_limit(T value)
ShallowConverter(bool rescale, RescalerInfo &info)
Low-level raw converter (not rescaling)
SmartConverter(const RescalerInfo &info)
void convert(const INP &in, OUTP &out) const
High-level converter, reimplementation of aims::Converter.
bool ismin_limit(T value)
bool isvalidvalue(TYPE value)
ShallowConverter only differs from the "standard" Converter in the way that it may make shallow copie...