Generated on Sat Feb 7 2015 02:01:26 for Gecode by doxygen 1.8.9.1
ranges-size.hpp
Go to the documentation of this file.
1 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2 /*
3  * Main authors:
4  * Guido Tack <tack@gecode.org>
5  *
6  * Copyright:
7  * Guido Tack, 2006
8  *
9  * Last modified:
10  * $Date: 2010-07-28 17:35:33 +0200 (Wed, 28 Jul 2010) $ by $Author: schulte $
11  * $Revision: 11294 $
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 
49  template<class I>
50  class Size {
51  protected:
53  I i;
55  unsigned int _size;
56  public:
58 
59  Size(void);
62  Size(I& i);
64  void init(I& i);
66 
68 
69  bool operator ()(void);
72  void operator ++(void);
74 
76 
77  int min(void) const;
80  int max(void) const;
82  unsigned int width(void) const;
84 
86 
87  unsigned int size(void) const;
90  };
91 
92 
93  template<class I>
96  : _size(0) {}
97 
98  template<class I>
99  inline void
100  Size<I>::init(I& i0) {
101  i.init(i0);
102  _size = 0;
103  }
104 
105  template<class I>
106  inline
107  Size<I>::Size(I& i0) : i(i0), _size(0) {}
108 
109  template<class I>
110  forceinline void
112  _size += i.width();
113  ++i;
114  }
115  template<class I>
116  forceinline bool
118  return i();
119  }
120 
121  template<class I>
122  forceinline int
123  Size<I>::min(void) const {
124  return i.min();
125  }
126  template<class I>
127  forceinline int
128  Size<I>::max(void) const {
129  return i.max();
130  }
131  template<class I>
132  forceinline unsigned int
133  Size<I>::width(void) const {
134  return i.width();
135  }
136 
137  template<class I>
138  forceinline unsigned int
139  Size<I>::size(void) const {
140  return _size;
141  }
142 
143 }}}
144 
145 // STATISTICS: iter-any
146 
bool operator()(void)
Test whether iterator is still at a range or done.
void operator++(void)
Move iterator to next range (if possible)
int max(void) const
Return largest value of range.
int min(void) const
Return smallest value of range.
unsigned int size(void) const
Return accumulated size.
Gecode::IntArgs i(4, 1, 2, 3, 4)
unsigned int _size
Accumulated size.
Definition: ranges-size.hpp:55
void init(I &i)
Initialize with ranges from i.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
Range iterator with size counting
Definition: ranges-size.hpp:50
#define forceinline
Definition: config.hpp:132
Gecode toplevel namespace
Size(void)
Default constructor.
Definition: ranges-size.hpp:95
I i
Iterator to compute size of.
Definition: ranges-size.hpp:53