Generated on Mon Jul 27 2020 00:00:00 for Gecode by doxygen 1.8.18
ranges-negative.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 #include <algorithm>
35 
36 namespace Gecode { namespace Iter { namespace Ranges {
37 
46  template<class I, bool strict=false>
47  class Negative {
48  protected:
50  I i;
51  public:
53 
54  Negative(void);
57  Negative(I& i);
59  void init(I& i);
61 
63 
64  bool operator ()(void) const;
67  void operator ++(void);
69 
71 
72  int min(void) const;
75  int max(void) const;
77  unsigned int width(void) const;
79  };
80 
81 
82  template<class I, bool strict>
85 
86  template<class I, bool strict>
87  forceinline void
89  i=i0;
90  }
91 
92  template<class I, bool strict>
95 
96  template<class I, bool strict>
97  forceinline void
99  ++i;
100  }
101  template<class I, bool strict>
102  forceinline bool
104  if (strict) {
105  return i() && (i.min() < 0);
106  } else {
107  return i() && (i.min() <= 0);
108  }
109  }
110 
111  template<class I, bool strict>
112  forceinline int
114  return i.min();
115  }
116  template<class I, bool strict>
117  forceinline int
119  if (strict) {
120  return std::min(i.max(),-1);
121  } else {
122  return std::min(i.max(),0);
123  }
124  }
125  template<class I, bool strict>
126  forceinline unsigned int
128  return static_cast<unsigned int>(max()-min()+1);
129  }
130 
131 }}}
132 
133 // STATISTICS: iter-any
I i
Input iterator.
unsigned int width(void) const
Return width of range (distance between minimum and maximum)
void max(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:49
const FloatNum min
Smallest allowed float value.
Definition: float.hh:846
Gecode toplevel namespace
int min(void) const
Return smallest value of range.
int max(void) const
Return largest value of range.
Range iterator for negative part of a range iterator.
#define forceinline
Definition: config.hpp:185
void min(Home home, FloatVar x0, FloatVar x1, FloatVar x2)
Post propagator for .
Definition: arithmetic.cpp:67
Negative(void)
Default constructor.
Gecode::IntArgs i({1, 2, 3, 4})
bool operator()(void) const
Test whether iterator is still at a range or done.
void init(I &i)
Initialize with ranges from i.
void operator++(void)
Move iterator to next range (if possible)