Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
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 
34 namespace 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  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  bool operator ()(void) const;
71  void operator ++(void);
73 
75 
76  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
126  Map<I,M,strict>::val(void) const {
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.
Definition: values-map.hpp:120
void operator++(void)
Move iterator to next value (if possible)
Definition: values-map.hpp:108
M m
Mapping object.
Definition: values-map.hpp:50
I i
Input iterator.
Definition: values-map.hpp:48
Value iterator for mapping values of a value iterator.
Definition: values-map.hpp:45
Map(void)
Default constructor.
Definition: values-map.hpp:84
Gecode toplevel namespace
#define forceinline
Definition: config.hpp:185
int n
Number of negative literals for node type.
Definition: bool-expr.cpp:234
void init(I &i)
Initialize with values from i.
Definition: values-map.hpp:96
Gecode::IntArgs i({1, 2, 3, 4})
int val(void) const
Return current value.
Definition: values-map.hpp:126