Equalizer  1.6.1
range.h
1 
2 /* Copyright (c) 2006-2012, 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 
23 #include <iostream>
24 
25 namespace eq
26 {
27 namespace fabric
28 {
30  class Range
31  {
32  public:
36  Range() : start(0.f), end(1.f) {}
37 
39  Range( const float start_, const float end_ )
40  : start(start_), end(end_) {}
42 
46  bool operator == ( const Range& rhs ) const
47  { return start==rhs.start && end==rhs.end; }
48 
50  bool operator != ( const Range& rhs ) const
51  { return start!=rhs.start || end!=rhs.end; }
52 
54  float getSize() const { return end - start; }
55 
57  void invalidate() { start=0.f; end=0.f; }
58 
60  bool isValid() const
61  { return ( start>=0.f && end <=1.f && (end - start) >= 0.f ); }
62 
64  bool hasData() const { return (end - start) > 0.f; }
65 
67  void apply( const Range& rhs )
68  {
69  const float w = end-start;
70  end = start + rhs.end * w;
71  start += rhs.start * w;
72  }
73 
74 
75  float start;
76  float end;
77 
78  EQFABRIC_API static const Range ALL;
79  };
80 
81  inline std::ostream& operator << ( std::ostream& os, const Range& range )
82  {
83  os << "range [ " << range.start << " " << range.end << " ]";
84  return os;
85  }
86 }
87 }
88 
89 namespace lunchbox
90 {
91 template<> inline void byteswap( eq::fabric::Range& value )
92 {
93  byteswap( value.start );
94  byteswap( value.end );
95 }
96 }
97 #endif // EQFABRIC_RANGE_H
A fractional database range with methods for manipulation.
Definition: range.h:30
float getSize() const
Definition: range.h:54
Range()
Construct a new range covering all data.
Definition: range.h:36
static const Range ALL
A full database range.
Definition: range.h:78
Range(const float start_, const float end_)
Construct a new range with default values.
Definition: range.h:39
bool operator!=(const Range &rhs) const
Definition: range.h:50
float end
The end position.
Definition: range.h:76
bool operator==(const Range &rhs) const
Definition: range.h:46
float start
The start position.
Definition: range.h:75