fw4spl
NumericRoundCast.hxx
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #ifndef __FWTOOLS_NUMERICROUNDCAST_HXX__
8 #define __FWTOOLS_NUMERICROUNDCAST_HXX__
9 
10 #include <boost/numeric/conversion/converter.hpp>
11 
12 namespace fwTools
13 {
14 
25 template < typename TYPEOUT, typename TYPEIN>
26 TYPEOUT numericRoundCast (const TYPEIN &value)
27 {
28  typedef ::boost::numeric::conversion_traits<TYPEOUT, TYPEIN> TraitsType;
29  typedef ::boost::numeric::silent_overflow_handler OverflowHandlerType;
30  typedef ::boost::numeric::RoundEven<typename TraitsType::source_type> RoundEvenType;
31  typedef ::boost::numeric::raw_converter<TraitsType> ConverterType;
32  typedef ::boost::numeric::UseInternalRangeChecker RangeCheckerType;
33 
34  typedef ::boost::numeric::converter<
35  TYPEOUT,
36  TYPEIN,
37  TraitsType,
38  OverflowHandlerType,
39  RoundEvenType,
40  ConverterType,
41  RangeCheckerType
42  > RoundCastType;
43 
44  return RoundCastType::convert(value);
45 }
46 
47 } // namespace fwTools
48 
49 #endif //__FWTOOLS_NUMERICROUNDCAST_HXX__
The namespace fwTools contains several tools like UUID, factory, dispatche, stringizer, macros, helper.
TYPEOUT numericRoundCast(const TYPEIN &value)