ranges-compl.hpp
Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Christian Schulte <schulte@gecode.org> 00005 * Guido Tack <tack@gecode.org> 00006 * 00007 * Copyright: 00008 * Guido Tack, 2004 00009 * Christian Schulte, 2005 00010 * 00011 * Last modified: 00012 * $Date: 2009-09-08 21:10:29 +0200 (Tue, 08 Sep 2009) $ by $Author: schulte $ 00013 * $Revision: 9692 $ 00014 * 00015 * This file is part of Gecode, the generic constraint 00016 * development environment: 00017 * http://www.gecode.org 00018 * 00019 * Permission is hereby granted, free of charge, to any person obtaining 00020 * a copy of this software and associated documentation files (the 00021 * "Software"), to deal in the Software without restriction, including 00022 * without limitation the rights to use, copy, modify, merge, publish, 00023 * distribute, sublicense, and/or sell copies of the Software, and to 00024 * permit persons to whom the Software is furnished to do so, subject to 00025 * the following conditions: 00026 * 00027 * The above copyright notice and this permission notice shall be 00028 * included in all copies or substantial portions of the Software. 00029 * 00030 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 00031 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00032 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 00033 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 00034 * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 00035 * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 00036 * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00037 * 00038 */ 00039 00040 namespace Gecode { namespace Iter { namespace Ranges { 00041 00052 template<int UMIN, int UMAX, class I> 00053 class Compl : public MinMax { 00054 private: 00056 IsRangeIter<I> _checkI; 00057 protected: 00059 I i; 00061 void start(void); 00062 public: 00064 00065 00066 Compl(void); 00068 Compl(I& i); 00070 void init(I& i); 00072 00074 00075 00076 void operator ++(void); 00078 }; 00079 00080 00091 template<class I> 00092 class ComplVal : public MinMax { 00093 private: 00095 IsRangeIter<I> _checkI; 00096 protected: 00098 int UMIN, UMAX; 00100 I i; 00102 void start(void); 00103 public: 00105 00106 00107 ComplVal(void); 00109 ComplVal(int umin, int umax, I& i); 00111 void init(int umin, int umax, I& i); 00113 00115 00116 00117 void operator ++(void); 00119 }; 00120 00121 00122 template<int UMIN, int UMAX, class I> 00123 forceinline void 00124 Compl<UMIN,UMAX,I>::start(void) { 00125 if (i()) { 00126 assert((i.min() >= UMIN) && (i.max() <= UMAX)); 00127 if (i.min() > UMIN) { 00128 mi = UMIN; 00129 ma = i.min()-1; 00130 } else if (i.max() < UMAX) { 00131 mi = i.max()+1; 00132 ++i; 00133 ma = i() ? (i.min()-1) : UMAX; 00134 } else { 00135 finish(); 00136 } 00137 } else { 00138 mi = UMIN; 00139 ma = UMAX; 00140 } 00141 } 00142 00143 template<int UMIN, int UMAX, class I> 00144 forceinline 00145 Compl<UMIN,UMAX,I>::Compl(void) {} 00146 00147 template<int UMIN, int UMAX, class I> 00148 forceinline 00149 Compl<UMIN,UMAX,I>::Compl(I& i0) : i(i0) { 00150 start(); 00151 } 00152 00153 template<int UMIN, int UMAX, class I> 00154 forceinline void 00155 Compl<UMIN,UMAX,I>::init(I& i0) { 00156 i=i0; start(); 00157 } 00158 00159 template<int UMIN, int UMAX, class I> 00160 forceinline void 00161 Compl<UMIN,UMAX,I>::operator ++(void) { 00162 assert(!i() || (i.max() <= UMAX)); 00163 if (i() && (i.max() < UMAX)) { 00164 mi = i.max()+1; 00165 ++i; 00166 ma = i() ? (i.min()-1) : UMAX; 00167 } else { 00168 finish(); 00169 } 00170 } 00171 00172 template<class I> 00173 forceinline void 00174 ComplVal<I>::start(void) { 00175 if (i()) { 00176 assert((i.min() >= UMIN) && (i.max() <= UMAX)); 00177 if (i.min() > UMIN) { 00178 mi = UMIN; 00179 ma = i.min()-1; 00180 } else if (i.max() < UMAX) { 00181 mi = i.max()+1; 00182 ++i; 00183 ma = i() ? (i.min()-1) : UMAX; 00184 } else { 00185 finish(); 00186 } 00187 } else { 00188 mi = UMIN; 00189 ma = UMAX; 00190 } 00191 } 00192 00193 template<class I> 00194 forceinline 00195 ComplVal<I>::ComplVal(void) {} 00196 00197 template<class I> 00198 forceinline 00199 ComplVal<I>::ComplVal(int umin, int umax, I& i0) 00200 : UMIN(umin), UMAX(umax), i(i0) { 00201 start(); 00202 } 00203 00204 template<class I> 00205 forceinline void 00206 ComplVal<I>::init(int umin, int umax, I& i0) { 00207 UMIN=umin; UMAX=umax; i=i0; start(); 00208 } 00209 00210 template<class I> 00211 forceinline void 00212 ComplVal<I>::operator ++(void) { 00213 assert(!i() || (i.max() <= UMAX)); 00214 if (i() && (i.max() < UMAX)) { 00215 mi = i.max()+1; 00216 ++i; 00217 ma = i() ? (i.min()-1) : UMAX; 00218 } else { 00219 finish(); 00220 } 00221 } 00222 00223 }}} 00224 00225 // STATISTICS: iter-any 00226