libDwm-0.9.45
DwmValueRange.hh
Go to the documentation of this file.
1//===========================================================================
2// @(#) $DwmPath$
3//===========================================================================
4// Copyright (c) Daniel W. McRobb 2007
5// All rights reserved.
6//
7// Redistribution and use in source and binary forms, with or without
8// modification, are permitted provided that the following conditions
9// are met:
10//
11// 1. Redistributions of source code must retain the above copyright
12// notice, this list of conditions and the following disclaimer.
13// 2. Redistributions in binary form must reproduce the above copyright
14// notice, this list of conditions and the following disclaimer in the
15// documentation and/or other materials provided with the distribution.
16// 3. The names of the authors and copyright holders may not be used to
17// endorse or promote products derived from this software without
18// specific prior written permission.
19//
20// IN NO EVENT SHALL DANIEL W. MCROBB BE LIABLE TO ANY PARTY FOR
21// DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
22// INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE,
23// EVEN IF DANIEL W. MCROBB HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
24// DAMAGE.
25//
26// THE SOFTWARE PROVIDED HEREIN IS ON AN "AS IS" BASIS, AND
27// DANIEL W. MCROBB HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT,
28// UPDATES, ENHANCEMENTS, OR MODIFICATIONS. DANIEL W. MCROBB MAKES NO
29// REPRESENTATIONS AND EXTENDS NO WARRANTIES OF ANY KIND, EITHER
30// IMPLIED OR EXPRESS, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
31// WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE,
32// OR THAT THE USE OF THIS SOFTWARE WILL NOT INFRINGE ANY PATENT,
33// TRADEMARK OR OTHER RIGHTS.
34//===========================================================================
35
36//---------------------------------------------------------------------------
39//---------------------------------------------------------------------------
40
41#ifndef _DWMVALUERANGE_HH_
42#define _DWMVALUERANGE_HH_
43
44#include <cassert>
45#include <utility>
46
47namespace Dwm {
48
49 //--------------------------------------------------------------------------
51 //--------------------------------------------------------------------------
52 template <typename T>
54 : public std::pair<T,T>
55 {
56 public:
57 //------------------------------------------------------------------------
59 //------------------------------------------------------------------------
61 : std::pair<T,T>()
62 { }
63
64 //------------------------------------------------------------------------
66 //------------------------------------------------------------------------
67 ValueRange(const T & low, const T & high)
68 : std::pair<T,T>(low, high)
69 {
70 assert(high >= low);
71 }
72
73 //------------------------------------------------------------------------
75 //------------------------------------------------------------------------
76 bool Contains(const T & value) const
77 {
78 return((value >= this->first) && (value <= this->second));
79 }
80
81 //------------------------------------------------------------------------
83 //------------------------------------------------------------------------
84 bool Contains(const ValueRange<T> & range) const
85 {
86 return(Contains(range.first) && Contains(range.second));
87 }
88
89 //------------------------------------------------------------------------
91 //------------------------------------------------------------------------
92 bool Overlaps(const ValueRange<T> & range) const
93 {
94 return(this->Contains(range.first)
95 || this->Contains(range.second)
96 || range.Contains(this->first)
97 || range.Contains(this->second));
98 }
99
100 };
101
102
103} // namespace Dwm
104
105#endif // _DWMVALUERANGE_HH_
106
107//---------------------------- emacs settings -----------------------------
108// Local Variables:
109// mode: C++
110// tab-width: 2
111// indent-tabs-mode: nil
112// c-basic-offset: 2
113// End:
114//-------------------------------------------------------------------------
This template encapsulates a range of values (low, high).
Definition DwmValueRange.hh:55
ValueRange()
Constructor.
Definition DwmValueRange.hh:60
bool Overlaps(const ValueRange< T > &range) const
Returns true if the range overlaps the given range.
Definition DwmValueRange.hh:92
bool Contains(const T &value) const
Returns true if the range contains value.
Definition DwmValueRange.hh:76
bool Contains(const ValueRange< T > &range) const
Returns true if the range contains the given range.
Definition DwmValueRange.hh:84
ValueRange(const T &low, const T &high)
Construct from given low and @ high values.
Definition DwmValueRange.hh:67