Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : */
9 : #ifndef INCLUDED_TOOLS_HELPERS_HXX
10 : #define INCLUDED_TOOLS_HELPERS_HXX
11 :
12 : #include <sal/config.h>
13 :
14 : #include <cassert>
15 :
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>
21 :
22 : template<typename T>
23 : inline
24 : typename boost::enable_if<
25 : boost::mpl::or_< boost::is_signed<T>, boost::is_floating_point<T> >, long>
26 : ::type
27 118359396 : MinMax(T nVal, long nMin, long nMax)
28 : {
29 : assert(nMin <= nMax);
30 : return nVal >= nMin
31 118359396 : ? (nVal <= nMax ? static_cast<long>(nVal) : nMax) : nMin;
32 : }
33 :
34 : template<typename T>
35 8785 : inline typename boost::enable_if<boost::is_unsigned<T>, long>::type MinMax(
36 : T nVal, long nMin, long nMax)
37 : {
38 : assert(nMin <= nMax);
39 : return nMax < 0
40 : ? nMax
41 : : ((nMin < 0 || nVal >= static_cast<unsigned long>(nMin))
42 : ? (nVal <= static_cast<unsigned long>(nMax)
43 : ? static_cast<long>(nVal) : nMax)
44 8785 : : nMin);
45 : }
46 :
47 2779 : inline long AlignedWidth4Bytes( long nWidthBits )
48 : {
49 2779 : return ( ( nWidthBits + 31 ) >> 5 ) << 2;
50 : }
51 :
52 8330392 : inline long FRound( double fVal )
53 : {
54 8330392 : return fVal > 0.0 ? static_cast<long>( fVal + 0.5 ) : -static_cast<long>( -fVal + 0.5 );
55 : }
56 :
57 : #endif
58 :
59 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|