LCOV - code coverage report
Current view: top level - include/tools - helpers.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 8 0.0 %
Date: 2014-04-14 Functions: 0 7 0.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           0 : MinMax(T nVal, long nMin, long nMax)
      28             : {
      29             :     assert(nMin <= nMax);
      30             :     return nVal >= nMin
      31           0 :         ? (nVal <= nMax ? static_cast<long>(nVal) : nMax) : nMin;
      32             : }
      33             : 
      34             : template<typename T>
      35           0 : 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           0 :            : nMin);
      45             : }
      46             : 
      47           0 : inline long AlignedWidth4Bytes( long nWidthBits )
      48             : {
      49           0 :     return ( ( nWidthBits + 31 ) >> 5 ) << 2;
      50             : }
      51             : 
      52           0 : inline long FRound( double fVal )
      53             : {
      54           0 :     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