LCOV - code coverage report
Current view: top level - eq/fabric - range.h (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 16 23 69.6 %
Date: 2014-06-18 Functions: 7 10 70.0 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2006-2014, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *
       4             :  * This library is free software; you can redistribute it and/or modify it under
       5             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       6             :  * by the Free Software Foundation.
       7             :  *
       8             :  * This library is distributed in the hope that it will be useful, but WITHOUT
       9             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      10             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      11             :  * details.
      12             :  *
      13             :  * You should have received a copy of the GNU Lesser General Public License
      14             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      15             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      16             :  */
      17             : 
      18             : #ifndef EQFABRIC_RANGE_H
      19             : #define EQFABRIC_RANGE_H
      20             : 
      21             : #include <eq/fabric/api.h>
      22             : #include <lunchbox/bitOperation.h>
      23             : #include <iostream>
      24             : 
      25             : namespace eq
      26             : {
      27             : namespace fabric
      28             : {
      29             :     /** A fractional database range with methods for manipulation. */
      30             :     class Range
      31             :     {
      32             :     public:
      33             :         /** @name Constructors */
      34             :         //@{
      35             :         /** Construct a new range covering all data. @version 1.0 */
      36       11621 :         Range() : start(0.f), end(1.f)  {}
      37             : 
      38             :         /** Construct a new range with default values. @version 1.0 */
      39         410 :         Range( const float start_, const float end_ )
      40         410 :                 : start(start_), end(end_) {}
      41             :         //@}
      42             : 
      43             :         /** @name Data Access */
      44             :         //@{
      45             :         /** @return true if the two ranges are identical. @version 1.0 */
      46           0 :         bool operator == ( const Range& rhs ) const
      47           0 :             { return start==rhs.start && end==rhs.end; }
      48             : 
      49             :         /** @return true if the two ranges are not identical. @version 1.0 */
      50        1876 :         bool operator != ( const Range& rhs ) const
      51        1876 :             { return start!=rhs.start || end!=rhs.end; }
      52             : 
      53             :         /** @return the interval spanned by this range. @version 1.3 */
      54           0 :         float getSize() const { return end - start; }
      55             : 
      56             :         /** @internal Invalidate the database range. */
      57             :         void invalidate() { start=0.f; end=0.f; }
      58             : 
      59             :         /** @internal @return true if the database range is valid. */
      60        1876 :         bool isValid() const
      61        1876 :             { return ( start>=0.f && end <=1.f && (end - start) >= 0.f ); }
      62             : 
      63             :         /** @internal @return true if the database range covers some data. */
      64        1163 :         bool hasData() const { return  (end - start) > 0.f; }
      65             : 
      66             :         /** @internal Apply (accumulate) another database range. */
      67        1164 :         void apply( const Range& rhs )
      68             :             {
      69        1164 :                 const float w = end-start;
      70        1164 :                 end    = start + rhs.end * w;
      71        1164 :                 start += rhs.start * w;
      72        1164 :             }
      73             : 
      74             : 
      75             :         float start; //!< The start position
      76             :         float end;   //!< The end position
      77             : 
      78             :         EQFABRIC_API static const Range ALL; //!< A full database range
      79             :     };
      80             : 
      81         181 :     inline std::ostream& operator << ( std::ostream& os, const Range& range )
      82             :     {
      83         181 :         os << "range    [ " << range.start << " " << range.end << " ]";
      84         181 :         return os;
      85             :     }
      86             : }
      87             : }
      88             : 
      89             : namespace lunchbox
      90             : {
      91           0 : template<> inline void byteswap( eq::fabric::Range& value )
      92             : {
      93           0 :     byteswap( value.start );
      94           0 :     byteswap( value.end );
      95           0 : }
      96             : }
      97             : #endif // EQFABRIC_RANGE_H

Generated by: LCOV version 1.10