Generated on Sun Aug 9 2020 05:34:08 for Gecode by doxygen 1.8.18
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  * 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 
45  template<class I>
46  class Size {
47  protected:
49  I i;
51  unsigned int _size;
52  public:
54 
55  Size(void);
58  Size(I& i);
60  void init(I& i);
62 
64 
65  bool operator ()(void);
68  void operator ++(void);
70 
72 
73  int min(void) const;
76  int max(void) const;
78  unsigned int width(void) const;
80 
82 
83  unsigned int size(void) const;
86  };
87 
88 
89  template<class I>
92  : _size(0) {}
93 
94  template<class I>
95  inline void
96  Size<I>::init(I& i0) {
97  i.init(i0);
98  _size = 0;
99  }
100 
101  template<class I>
102  inline
103  Size<I>::Size(I& i0) : i(i0), _size(0) {}
104 
105  template<class I>
106  forceinline void
108  _size += i.width();
109  ++i;
110  }
111  template<class I>
112  forceinline bool
114  return i();
115  }
116 
117  template<class I>
118  forceinline int
119  Size<I>::min(void) const {
120  return i.min();
121  }
122  template<class I>
123  forceinline int
124  Size<I>::max(void) const {
125  return i.max();
126  }
127  template<class I>
128  forceinline unsigned int
129  Size<I>::width(void) const {
130  return i.width();
131  }
132 
133  template<class I>
134  forceinline unsigned int
135  Size<I>::size(void) const {
136  return _size;
137  }
138 
139 }}}
140 
141 // STATISTICS: iter-any
142 
int max(void) const
Return largest value of range.
void init(I &i)
Initialize with ranges from i.
Definition: ranges-size.hpp:96
Size(void)
Default constructor.
Definition: ranges-size.hpp:91
Range iterator with size counting
Definition: ranges-size.hpp:46
Gecode toplevel namespace
void operator++(void)
Move iterator to next range (if possible)
bool operator()(void)
Test whether iterator is still at a range or done.
unsigned int _size
Accumulated size.
Definition: ranges-size.hpp:51
unsigned int size(void) const
Return accumulated size.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
int min(void) const
Return smallest value of range.
I i
Iterator to compute size of.
Definition: ranges-size.hpp:49
#define forceinline
Definition: config.hpp:185
Gecode::IntArgs i({1, 2, 3, 4})