LCOV - code coverage report
Current view: top level - include/tools - helpers.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 8 8 100.0 %
Date: 2014-11-03 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          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   114776680 : MinMax(T nVal, long nMin, long nMax)
      28             : {
      29             :     assert(nMin <= nMax);
      30             :     return nVal >= nMin
      31   114776680 :         ? (nVal <= nMax ? static_cast<long>(nVal) : nMax) : nMin;
      32             : }
      33             : 
      34             : template<typename T>
      35        5348 : 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        5348 :            : nMin);
      45             : }
      46             : 
      47        4949 : inline long AlignedWidth4Bytes( long nWidthBits )
      48             : {
      49        4949 :     return ( ( nWidthBits + 31 ) >> 5 ) << 2;
      50             : }
      51             : 
      52    13536945 : inline long FRound( double fVal )
      53             : {
      54    13536945 :     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: */

Generated by: LCOV version 1.10