Generated on Thu Jan 16 2025 00:00:00 for Gecode by doxygen 1.14.0
values-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
34namespace Gecode { namespace Iter { namespace Values {
35
44 template<class I, class M, bool strict=false>
45 class Map {
46 protected:
48 I i;
50 M m;
51 public:
53
54
55 Map(void);
57 Map(I& i);
59 Map(I& i, const M& m);
61 void init(I& i);
63 void init(I& i, const M& m);
65
67
68
69 bool operator ()(void) const;
71 void operator ++(void);
73
75
76
77 int val(void) const;
79 };
80
81
82 template<class I, class M, bool strict>
85
86 template<class I, class M, bool strict>
88 Map<I,M,strict>::Map(I& i0) : i(i0) {}
89
90 template<class I, class M, bool strict>
92 Map<I,M,strict>::Map(I& i0, const M& m0) : i(i0), m(m0) {}
93
94 template<class I, class M, bool strict>
95 forceinline void
97 i=i0;
98 }
99
100 template<class I, class M, bool strict>
101 forceinline void
102 Map<I,M,strict>::init(I& i0, const M& m0) {
103 i=i0; m=m0;
104 }
105
106 template<class I, class M, bool strict>
107 forceinline void
109 if (strict) {
110 ++i;
111 } else {
112 int n=m.val(i.val());
113 do {
114 ++i;
115 } while (i() && (n == m.val(i.val())));
116 }
117 }
118 template<class I, class M, bool strict>
119 forceinline bool
121 return i();
122 }
123
124 template<class I, class M, bool strict>
125 forceinline int
127 return m.val(i.val());
128 }
129
130}}}
131
132// STATISTICS: iter-any
bool operator()(void) const
Test whether iterator is still at a value or done.
Map(void)
Default constructor.
void init(I &i)
Initialize with values from i.
int val(void) const
Return current value.
void operator++(void)
Move iterator to next value (if possible)
Value iterators.
Definition iter.hh:45
Range and value iterators.
Definition iter.hh:41
Gecode toplevel namespace
#define forceinline
Definition config.hpp:194