ranges-values.icc
Go to the documentation of this file.00001 /* 00002 * Main authors: 00003 * Christian Schulte <schulte@gecode.org> 00004 * 00005 * Copyright: 00006 * Christian Schulte, 2004 00007 * 00008 * Last modified: 00009 * $Date: 2006-04-11 15:58:37 +0200 (Tue, 11 Apr 2006) $ by $Author: tack $ 00010 * $Revision: 3188 $ 00011 * 00012 * This file is part of Gecode, the generic constraint 00013 * development environment: 00014 * http://www.gecode.org 00015 * 00016 * See the file "LICENSE" for information on usage and 00017 * redistribution of this file, and for a 00018 * DISCLAIMER OF ALL WARRANTIES. 00019 * 00020 */ 00021 00022 namespace Gecode { namespace Iter { namespace Ranges { 00023 00030 template <class I> 00031 class ToValues { 00032 protected: 00034 I i; 00036 int cur; 00038 int max; 00040 void start(void); 00041 public: 00043 00044 00045 ToValues(void); 00047 ToValues(I& i); 00049 void init(I& i); 00051 00053 00054 00055 bool operator()(void) const; 00057 void operator++(void); 00059 00061 00062 00063 int val(void) const; 00065 }; 00066 00067 00068 00069 template <class I> 00070 forceinline 00071 ToValues<I>::ToValues(void) {} 00072 00073 template <class I> 00074 forceinline void 00075 ToValues<I>::start(void) { 00076 if (i()) { 00077 cur = i.min(); max = i.max(); 00078 } else { 00079 cur = 1; max = 0; 00080 } 00081 } 00082 00083 template <class I> 00084 forceinline 00085 ToValues<I>::ToValues(I& i0) 00086 : i(i0) { 00087 start(); 00088 } 00089 00090 template <class I> 00091 forceinline void 00092 ToValues<I>::init(I& i0) { 00093 i = i0; 00094 start(); 00095 } 00096 00097 00098 template <class I> 00099 forceinline bool 00100 ToValues<I>::operator()(void) const { 00101 return (cur <= max); 00102 } 00103 00104 template <class I> 00105 forceinline void 00106 ToValues<I>::operator++(void) { 00107 ++cur; 00108 if (cur > max) { 00109 ++i; 00110 if (i()) { 00111 cur = i.min(); max = i.max(); 00112 } 00113 } 00114 } 00115 00116 template <class I> 00117 forceinline int 00118 ToValues<I>::val(void) const { 00119 return cur; 00120 } 00121 00122 }}} 00123 00124 // STATISTICS: iter-any 00125