Kaydet (Commit) f51f03a4 authored tarafından Stephan Bergmann's avatar Stephan Bergmann

Do not needlessly truncate MinMax argument before comparison with bounds

Change-Id: I218e70d6a19901107fd037af255ad29692c850d4
Reviewed-on: https://gerrit.libreoffice.org/8461Reviewed-by: 's avatarStephan Bergmann <sbergman@redhat.com>
Tested-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 0e78ce14
......@@ -9,9 +9,39 @@
#ifndef INCLUDED_TOOLS_HELPERS_HXX
#define INCLUDED_TOOLS_HELPERS_HXX
inline long MinMax( long nVal, long nMin, long nMax )
#include <sal/config.h>
#include <cassert>
#include <boost/mpl/or.hpp>
#include <boost/type_traits/is_floating_point.hpp>
#include <boost/type_traits/is_signed.hpp>
#include <boost/type_traits/is_unsigned.hpp>
#include <boost/utility/enable_if.hpp>
template<typename T>
inline
typename boost::enable_if<
boost::mpl::or_< boost::is_signed<T>, boost::is_floating_point<T> >, long>
::type
MinMax(T nVal, long nMin, long nMax)
{
assert(nMin <= nMax);
return nVal >= nMin
? (nVal <= nMax ? static_cast<long>(nVal) : nMax) : nMin;
}
template<typename T>
inline typename boost::enable_if<boost::is_unsigned<T>, long>::type MinMax(
T nVal, long nMin, long nMax)
{
return nVal >= nMin ? ( nVal <= nMax ? nVal : nMax ) : nMin;
assert(nMin <= nMax);
return nMax < 0
? nMax
: ((nMin < 0 || nVal >= static_cast<unsigned long>(nMin))
? (nVal <= static_cast<unsigned long>(nMax)
? static_cast<long>(nVal) : nMax)
: nMin);
}
inline long AlignedWidth4Bytes( long nWidthBits )
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment