Nemiver  0.3
nmv-range.h
Go to the documentation of this file.
1 // Author: Dodji Seketeli
2 /*
3  *This file is part of the Nemiver project
4  *
5  *Nemiver is free software; you can redistribute
6  *it and/or modify it under the terms of
7  *the GNU General Public License as published by the
8  *Free Software Foundation; either version 2,
9  *or (at your option) any later version.
10  *
11  *Nemiver is distributed in the hope that it will
12  *be useful, but WITHOUT ANY WARRANTY;
13  *without even the implied warranty of
14  *MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
15  *See the GNU General Public License for more details.
16  *
17  *You should have received a copy of the
18  *GNU General Public License along with Nemiver;
19  *see the file COPYING.
20  *If not, write to the Free Software Foundation,
21  *Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22  *
23  *See COPYRIGHT file copyright information.
24  */
25 #ifndef __NMV_RANGE_H__
26 #define __NMV_RANGE_H__
27 
28 #include "nmv-namespace.h"
29 #include "nmv-api-macros.h"
30 
31 NEMIVER_BEGIN_NAMESPACE (nemiver)
32 NEMIVER_BEGIN_NAMESPACE (common)
33 
34 class Range {
36  size_t m_min;
37  size_t m_max;
38 
39 public:
40 
60  VALUE_SEARCH_RESULT_EXACT = 0,
64  VALUE_SEARCH_RESULT_NONE // <-- must always be last.
65  };
66 
67  Range (size_t a_min = 0, size_t a_max = 0) :
68  m_min (a_min),
69  m_max (a_max)
70  {
71  }
72 
74  size_t min () const {return m_min;}
75  void min (size_t a) {m_min = a;}
76 
78  size_t max () const {return m_max;}
79  void max (size_t a) {m_max = a;}
80 
82  bool contains (size_t a_value) const
83  {
84  return (a_value >= m_min && a_value <= m_max);
85  }
86 
92  void extend (size_t a_value)
93  {
94  if (!contains (a_value)) {
95  if (a_value < m_min)
96  m_min = a_value;
97  else
98  m_max = a_value;
99  }
100  }
101 };
102 
103 NEMIVER_END_NAMESPACE (common)
104 NEMIVER_END_NAMESPACE (nemiver)
105 
106 #endif // __NMV_RANGE_H__
107 
nemiver::common::Range::VALUE_SEARCH_RESULT_WITHIN
@ VALUE_SEARCH_RESULT_WITHIN
Definition: nmv-range.h:61
nemiver::common::Range::max
void max(size_t a)
Definition: nmv-range.h:79
nemiver
Definition: nmv-address.h:31
nmv-api-macros.h
nemiver::common::Range::max
size_t max() const
Accessors of the upper bound of the range.
Definition: nmv-range.h:78
nemiver::common::Range::min
void min(size_t a)
Definition: nmv-range.h:75
nemiver::common::Range::contains
bool contains(size_t a_value) const
Returns true if a_value is within the range.
Definition: nmv-range.h:82
nemiver::common::Range::VALUE_SEARCH_RESULT_BEFORE
@ VALUE_SEARCH_RESULT_BEFORE
Definition: nmv-range.h:62
nemiver::common::Range::extend
void extend(size_t a_value)
Definition: nmv-range.h:92
nemiver::common::Range::VALUE_SEARCH_RESULT_AFTER
@ VALUE_SEARCH_RESULT_AFTER
Definition: nmv-range.h:63
nemiver::common::Range::min
size_t min() const
Accessors of the lower bound of the range.
Definition: nmv-range.h:74
nmv-namespace.h
nemiver::common::Range::ValueSearchResult
ValueSearchResult
Definition: nmv-range.h:59
nemiver::common::Range::Range
Range(size_t a_min=0, size_t a_max=0)
Definition: nmv-range.h:67
common
Definition: nmv-proc-list-dialog.h:32