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, 2005 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 Ranges { 35 36 /** 37 * \brief Range iterator for adding a single range to a range iterator 38 * 39 * \ingroup FuncIterRanges 40 */ 41 template<class I> 42 class AddRange : public MinMax { 43 protected: 44 /// Iterator to which the range is to be added 45 I i; 46 /// Minimum of range to be added 47 int r_min; 48 /// Maximum of range to be added 49 int r_max; 50 public: 51 /// \name Constructors and initialization 52 //@{ 53 /// Default constructor 54 AddRange(void); 55 /// Initialize with ranges \a i and range \a min to \a max 56 AddRange(I& i, int min, int max); 57 /// Initialize with ranges \a i and range \a min to \a max 58 void init(I& i, int min, int max); 59 //@} 60 61 /// \name Iteration control 62 //@{ 63 /// Move iterator to next range (if possible) 64 void operator ++(void); 65 //@} 66 }; 67 68 69 /** 70 * \brief Range iterator for subtracting a single range from a range iterator 71 * 72 * \ingroup FuncIterRanges 73 */ 74 template<class I> 75 class SubRange : public AddRange<I> { 76 public: 77 /// \name Constructors and initialization 78 //@{ 79 /// Default constructor 80 SubRange(void); 81 /// Initialize with ranges \a i and range \a min to \a max 82 SubRange(I& i, int min, int max); 83 /// Initialize with ranges \a i and range \a min to \a max 84 void init(I& i, int min, int max); 85 //@} 86 }; 87 88 template<class I> 89 forceinline 90 AddRange<I>::AddRange(void) {} 91 92 template<class I> 93 forceinline void 94 AddRange<I>::operator ++(void) { 95 if (i()) { 96 mi = r_min + i.min(); 97 ma = r_max + i.max(); 98 ++i; 99 while (i() && (ma+1 >= r_min+i.min())) { 100 ma = r_max + i.max(); ++i; 101 } 102 } else { 103 finish(); 104 } 105 } 106 107 template<class I> 108 forceinline 109 AddRange<I>::AddRange(I& i0, int r_min0, int r_max0) 110 : i(i0), r_min(r_min0), r_max(r_max0) { 111 operator ++(); 112 } 113 114 template<class I> 115 forceinline void 116 AddRange<I>::init(I& i0, int r_min0, int r_max0) { 117 i = i0; r_min = r_min0; r_max = r_max0; 118 operator ++(); 119 } 120 121 122 template<class I> 123 forceinline 124 SubRange<I>::SubRange(void) {} 125 126 template<class I> 127 forceinline 128 SubRange<I>::SubRange(I& i, int r_min, int r_max) 129 : AddRange<I>(i,-r_max,-r_min) {} 130 131 template<class I> 132 forceinline void 133 SubRange<I>::init(I& i, int r_min, int r_max) { 134 AddRange<I>::init(i,-r_max,-r_min); 135 } 136 137}}} 138 139// STATISTICS: iter-any 140