Generated on Mon May 30 2016 09:03:36 for Gecode by doxygen 1.8.11
ranges-array.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Christian Schulte <schulte@gecode.org>
5  *
6  * Copyright:
7  * Christian Schulte, 2006
8  *
9  * Last modified:
10  * $Date: 2009-01-26 15:15:18 +0100 (Mon, 26 Jan 2009) $ by $Author: schulte $
11  * $Revision: 8109 $
12  *
13  * This file is part of Gecode, the generic constraint
14  * development environment:
15  * http://www.gecode.org
16  *
17  * Permission is hereby granted, free of charge, to any person obtaining
18  * a copy of this software and associated documentation files (the
19  * "Software"), to deal in the Software without restriction, including
20  * without limitation the rights to use, copy, modify, merge, publish,
21  * distribute, sublicense, and/or sell copies of the Software, and to
22  * permit persons to whom the Software is furnished to do so, subject to
23  * the following conditions:
24  *
25  * The above copyright notice and this permission notice shall be
26  * included in all copies or substantial portions of the Software.
27  *
28  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35  *
36  */
37 
38 namespace Gecode { namespace Iter { namespace Ranges {
39 
50  class Array {
51  public:
53  class Range {
54  public:
55  int min; int max;
56  };
57  protected:
59  Range* r;
61  int c;
63  int n;
64  public:
66 
67  Array(void);
70  Array(Range* r, int n);
72  void init(Range* r, int n);
74 
76 
77  bool operator ()(void) const;
80  void operator ++(void);
82  void reset(void);
84 
86 
87  int min(void) const;
90  int max(void) const;
92  unsigned int width(void) const;
94  };
95 
96 
98  Array::Array(void) {}
99 
101  Array::Array(Range* r0, int n0)
102  : r(r0), c(0), n(n0) {}
103 
104  forceinline void
105  Array::init(Range* r0, int n0) {
106  r=r0; c=0; n=n0;
107  }
108 
109  forceinline void
111  c++;
112  }
113  forceinline bool
114  Array::operator ()(void) const {
115  return c < n;
116  }
117 
118  forceinline void
119  Array::reset(void) {
120  c=0;
121  }
122 
123  forceinline int
124  Array::min(void) const {
125  return r[c].min;
126  }
127  forceinline int
128  Array::max(void) const {
129  return r[c].max;
130  }
131  forceinline unsigned int
132  Array::width(void) const {
133  return static_cast<unsigned int>(r[c].max-r[c].min)+1;
134  }
135 
136 }}}
137 
138 // STATISTICS: iter-any
139 
void init(Range *r, int n)
Initialize with n ranges from r.
bool operator()(void) const
Test whether iterator is still at a range or done.
int n
Number of ranges in array.
int max(void) const
Return largest value of range.
Array(void)
Default constructor.
Range iterator for array of ranges
int min(void) const
Return smallest value of range.
Range * r
Array for ranges.
void reset(void)
Reset iterator to start from beginning.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
#define forceinline
Definition: config.hpp:170
Gecode toplevel namespace
void operator++(void)
Move iterator to next range (if possible)