1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 #ifndef INCLUDED_TOOLS_HELPERS_HXX
10 #define INCLUDED_TOOLS_HELPERS_HXX
12 #include <sal/config.h>
16 #include <boost/mpl/or.hpp>
17 #include <boost/type_traits/is_floating_point.hpp>
18 #include <boost/type_traits/is_signed.hpp>
19 #include <boost/type_traits/is_unsigned.hpp>
20 #include <boost/utility/enable_if.hpp>
24 typename
boost::enable_if
<
25 boost::mpl::or_
< boost::is_signed
<T
>, boost::is_floating_point
<T
> >, long>
27 MinMax(T nVal
, long nMin
, long nMax
)
31 ? (nVal
<= nMax
? static_cast<long>(nVal
) : nMax
) : nMin
;
35 inline typename
boost::enable_if
<boost::is_unsigned
<T
>, long>::type
MinMax(
36 T nVal
, long nMin
, long nMax
)
41 : ((nMin
< 0 || nVal
>= static_cast<unsigned long>(nMin
))
42 ? (nVal
<= static_cast<unsigned long>(nMax
)
43 ? static_cast<long>(nVal
) : nMax
)
47 inline long AlignedWidth4Bytes( long nWidthBits
)
49 return ( ( nWidthBits
+ 31 ) >> 5 ) << 2;
52 inline long FRound( double fVal
)
54 return fVal
> 0.0 ? static_cast<long>( fVal
+ 0.5 ) : -static_cast<long>( -fVal
+ 0.5 );
59 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */