this repo has no description
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, 2007
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
34namespace Gecode { namespace Iter { namespace Values {
35
36 /**
37 * \brief %Value iterator for array of integers
38 *
39 * Allows to iterate the integers as defined by an array where the
40 * values in the array must be sorted in increasing order.
41 * The integers can be iterated several times provided the iterator
42 * is %reset by the reset member function.
43 *
44 * \ingroup FuncIterValues
45 */
46 class Array {
47 protected:
48 /// Array for values
49 int* v;
50 /// Current value
51 unsigned int c;
52 /// Number of values in array
53 unsigned int n;
54 public:
55 /// \name Constructors and initialization
56 //@{
57 /// Default constructor
58 Array(void);
59 /// Initialize with \a n values from \a v
60 Array(int* v, unsigned int n);
61 /// Initialize with \a n values from \a v
62 Array(int* v, int n);
63 /// Initialize with \a n ranges from \a v
64 void init(int* v, unsigned int n);
65 /// Initialize with \a n ranges from \a v
66 void init(int* v, int n);
67 //@}
68
69 /// \name Iteration control
70 //@{
71 /// Test whether iterator is still at a value or done
72 bool operator ()(void) const;
73 /// Move iterator to next value (if possible)
74 void operator ++(void);
75 /// Reset iterator to start from beginning
76 void reset(void);
77 //@}
78
79 /// \name %Value access
80 //@{
81 /// Return current value
82 int val(void) const;
83 //@}
84 };
85
86
87 forceinline
88 Array::Array(void) {}
89
90 forceinline
91 Array::Array(int* v0, unsigned int n0)
92 : v(v0), c(0U), n(n0) {}
93
94 forceinline
95 Array::Array(int* v0, int n0)
96 : v(v0), c(0U), n(static_cast<unsigned int>(n0)) {}
97
98 forceinline void
99 Array::init(int* v0, unsigned int n0) {
100 v=v0; c=0U; n=n0;
101 }
102
103 forceinline void
104 Array::init(int* v0, int n0) {
105 v=v0; c=0U; n=static_cast<unsigned int>(n0);
106 }
107
108 forceinline void
109 Array::operator ++(void) {
110 c++;
111 }
112 forceinline bool
113 Array::operator ()(void) const {
114 return c<n;
115 }
116 forceinline void
117 Array::reset(void) {
118 c=0;
119 }
120
121 forceinline int
122 Array::val(void) const {
123 return v[c];
124 }
125
126}}}
127
128// STATISTICS: iter-any
129