Generated on Sat Jun 2 2018 07:17:44 for Gecode by doxygen 1.8.13
ranges-map.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, 2008
8  *
9  * This file is part of Gecode, the generic constraint
10  * development environment:
11  * http://www.gecode.org
12  *
13  * Permission is hereby granted, free of charge, to any person obtaining
14  * a copy of this software and associated documentation files (the
15  * "Software"), to deal in the Software without restriction, including
16  * without limitation the rights to use, copy, modify, merge, publish,
17  * distribute, sublicense, and/or sell copies of the Software, and to
18  * permit persons to whom the Software is furnished to do so, subject to
19  * the following conditions:
20  *
21  * The above copyright notice and this permission notice shall be
22  * included in all copies or substantial portions of the Software.
23  *
24  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31  *
32  */
33 
34 namespace Gecode { namespace Iter { namespace Ranges {
35 
44  template<class I, class M, bool strict=true>
45  class Map {
46  public:
48 
49  Map(void);
52  Map(I& i);
54  Map(I& i, const M& m);
56  void init(I& i);
58  void init(I& i, const M& m);
60 
62 
63  bool operator ()(void) const;
66  void operator ++(void);
68 
70 
71  int min(void) const;
74  int max(void) const;
76  unsigned int width(void) const;
78  };
79 
81  template<class I, class M>
82  class Map<I,M,false> : public MinMax {
83  protected:
85  I i;
87  M m;
89  void next(void);
90  public:
92 
93  Map(void);
96  Map(I& i);
98  Map(I& i, const M& m);
100  void init(I& i);
102  void init(I& i, const M& m);
104 
106 
107  void operator ++(void);
110  };
111 
113  template<class I, class M>
114  class Map<I,M,true> {
115  protected:
117  I i;
119  M m;
120  public:
122 
123  Map(void);
126  Map(I& i);
128  Map(I& i, const M& m);
130  void init(I& i);
132  void init(I& i, const M& m);
134 
136 
137  bool operator ()(void) const;
140  void operator ++(void);
142 
144 
145  int min(void) const;
148  int max(void) const;
150  unsigned int width(void) const;
152  };
153 
154 
155  template<class I, class M>
158 
159  template<class I, class M>
160  forceinline void
162  if (i()) {
163  mi = m.min(i.min());
164  ma = m.max(i.max());
165  ++i;
166  while (i() && (ma+1 >= m.min(i.min()))) {
167  ma = m.max(i.max()); ++i;
168  }
169  } else {
170  finish();
171  }
172  }
173 
174  template<class I, class M>
175  forceinline void
177  i=i0; next();
178  }
179  template<class I, class M>
180  forceinline void
181  Map<I,M,false>::init(I& i0, const M& m0) {
182  i=i0; m=m0; next();
183  }
184 
185  template<class I, class M>
187  Map<I,M,false>::Map(I& i0) : i(i0) {
188  next();
189  }
190  template<class I, class M>
192  Map<I,M,false>::Map(I& i0, const M& m0) : i(i0), m(m0) {
193  next();
194  }
195 
196  template<class I, class M>
197  forceinline void
199  next();
200  }
201 
202 
203 
204  template<class I, class M>
207 
208  template<class I, class M>
209  forceinline void
211  i=i0;
212  }
213  template<class I, class M>
214  forceinline void
215  Map<I,M,true>::init(I& i0, const M& m0) {
216  i=i0; m=m0;
217  }
218 
219  template<class I, class M>
221  Map<I,M,true>::Map(I& i0) : i(i0) {}
222  template<class I, class M>
224  Map<I,M,true>::Map(I& i0, const M& m0) : i(i0), m(m0) {}
225 
226  template<class I, class M>
227  forceinline bool
229  return i();
230  }
231  template<class I, class M>
232  forceinline void
234  ++i;
235  }
236 
237  template<class I, class M>
238  forceinline int
239  Map<I,M,true>::min(void) const {
240  return m.min(i.min());
241  }
242  template<class I, class M>
243  forceinline int
244  Map<I,M,true>::max(void) const {
245  return m.max(i.max());
246  }
247  template<class I, class M>
248  forceinline unsigned int
249  Map<I,M,true>::width(void) const {
250  return static_cast<unsigned int>(max()-min())+1;
251  }
252 
253 }}}
254 
255 // STATISTICS: iter-any
256 
int min(void) const
Return smallest value of range.
bool operator()(void) const
Test whether iterator is still at a range or done.
void init(I &i)
Initialize with ranges from i.
Base for range iterators with explicit min and max.
#define forceinline
Definition: config.hpp:185
int max(void) const
Return largest value of range.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Gecode::IntArgs i(4, 1, 2, 3, 4)
Map(void)
Default constructor.
Range iterator for mapping ranges.
Definition: ranges-map.hpp:45
Gecode toplevel namespace
void operator++(void)
Move iterator to next range (if possible)