range.h

00001 
00002 /* Copyright (c) 2006-2009, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * This library is free software; you can redistribute it and/or modify it under
00005  * the terms of the GNU Lesser General Public License version 2.1 as published
00006  * by the Free Software Foundation.
00007  *  
00008  * This library is distributed in the hope that it will be useful, but WITHOUT
00009  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
00010  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00011  * details.
00012  * 
00013  * You should have received a copy of the GNU Lesser General Public License
00014  * along with this library; if not, write to the Free Software Foundation, Inc.,
00015  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
00016  */
00017 
00018 #ifndef EQ_RANGE_H
00019 #define EQ_RANGE_H
00020 
00021 #include <eq/base/base.h>
00022 
00023 #include <iostream>
00024 
00025 namespace eq
00026 {
00030     class Range 
00031     {
00032     public:
00037         Range() : start(0.f), end(1.f)  {}
00038 
00039         Range( const float start_, const float end_ )
00040                 : start(start_), end(end_) {}
00042 
00043         void apply( const Range& rhs )
00044             {
00045                 const float w = end-start;
00046                 end    = start + rhs.end * w;
00047                 start += rhs.start * w;
00048             }
00049         
00050         bool operator == ( const Range& rhs ) const
00051         {
00052             return start==rhs.start && end==rhs.end;
00053         }
00054         
00055         bool operator != ( const Range& rhs ) const
00056         {
00057             return start!=rhs.start || end!=rhs.end;
00058         }
00059         
00060         void invalidate() { start=0.f; end=0.f; }
00061 
00062         bool isValid() const 
00063             { return ( start>=0.f && end <=1.f && (end - start) >= 0.f ); }
00064 
00065         bool hasData() const { return  (end - start) > 0.f; }
00066 
00067         float start;
00068         float end;
00069 
00070         EQ_EXPORT static const Range ALL;
00071     };
00072 
00073     inline std::ostream& operator << ( std::ostream& os, const Range& range )
00074     {
00075         os << "range    [ " << range.start << " " << range.end << " ]";
00076         return os;
00077     }
00078 }
00079 
00080 #endif // EQ_RANGE_H
Generated on Mon Aug 10 18:58:40 2009 for Equalizer 0.9 by  doxygen 1.5.8