Generated on Fri Oct 19 11:25:10 2018 for Gecode by doxygen 1.6.3

ranges-map.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  *
00006  *  Copyright:
00007  *     Christian Schulte, 2008
00008  *
00009  *  This file is part of Gecode, the generic constraint
00010  *  development environment:
00011  *     http://www.gecode.org
00012  *
00013  *  Permission is hereby granted, free of charge, to any person obtaining
00014  *  a copy of this software and associated documentation files (the
00015  *  "Software"), to deal in the Software without restriction, including
00016  *  without limitation the rights to use, copy, modify, merge, publish,
00017  *  distribute, sublicense, and/or sell copies of the Software, and to
00018  *  permit persons to whom the Software is furnished to do so, subject to
00019  *  the following conditions:
00020  *
00021  *  The above copyright notice and this permission notice shall be
00022  *  included in all copies or substantial portions of the Software.
00023  *
00024  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00025  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00026  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00027  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00028  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00029  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00030  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00031  *
00032  */
00033 
00034 namespace Gecode { namespace Iter { namespace Ranges {
00035 
00044   template<class I, class M, bool strict=true>
00045   class Map {
00046   public:
00048 
00049 
00050     Map(void);
00052     Map(I& i);
00054     Map(I& i, const M& m);
00056     void init(I& i);
00058     void init(I& i, const M& m);
00060 
00062 
00063 
00064     bool operator ()(void) const;
00066     void operator ++(void);
00068 
00070 
00071 
00072     int min(void) const;
00074     int max(void) const;
00076     unsigned int width(void) const;
00078   };
00079 
00081   template<class I, class M>
00082   class Map<I,M,false> : public MinMax {
00083   protected:
00085     I i;
00087     M m;
00089     void next(void);
00090   public:
00092 
00093 
00094     Map(void);
00096     Map(I& i);
00098     Map(I& i, const M& m);
00100     void init(I& i);
00102     void init(I& i, const M& m);
00104 
00106 
00107 
00108     void operator ++(void);
00110   };
00111 
00113   template<class I, class M>
00114   class Map<I,M,true> {
00115   protected:
00117     I i;
00119     M m;
00120   public:
00122 
00123 
00124     Map(void);
00126     Map(I& i);
00128     Map(I& i, const M& m);
00130     void init(I& i);
00132     void init(I& i, const M& m);
00134 
00136 
00137 
00138     bool operator ()(void) const;
00140     void operator ++(void);
00142 
00144 
00145 
00146     int min(void) const;
00148     int max(void) const;
00150     unsigned int width(void) const;
00152   };
00153 
00154 
00155   template<class I, class M>
00156   forceinline
00157   Map<I,M,false>::Map(void) {}
00158 
00159   template<class I, class M>
00160   forceinline void
00161   Map<I,M,false>::next(void) {
00162     if (i()) {
00163       mi = m.min(i.min());
00164       ma = m.max(i.max());
00165       ++i;
00166       while (i() && (ma+1 >= m.min(i.min()))) {
00167         ma = m.max(i.max()); ++i;
00168       }
00169     } else {
00170       finish();
00171     }
00172   }
00173 
00174   template<class I, class M>
00175   forceinline void
00176   Map<I,M,false>::init(I& i0) {
00177     i=i0; next();
00178   }
00179   template<class I, class M>
00180   forceinline void
00181   Map<I,M,false>::init(I& i0, const M& m0) {
00182     i=i0; m=m0; next();
00183   }
00184 
00185   template<class I, class M>
00186   forceinline
00187   Map<I,M,false>::Map(I& i0) : i(i0) {
00188     next();
00189   }
00190   template<class I, class M>
00191   forceinline
00192   Map<I,M,false>::Map(I& i0, const M& m0) : i(i0), m(m0) {
00193     next();
00194   }
00195 
00196   template<class I, class M>
00197   forceinline void
00198   Map<I,M,false>::operator ++(void) {
00199     next();
00200   }
00201 
00202 
00203 
00204   template<class I, class M>
00205   forceinline
00206   Map<I,M,true>::Map(void) {}
00207 
00208   template<class I, class M>
00209   forceinline void
00210   Map<I,M,true>::init(I& i0) {
00211     i=i0;
00212   }
00213   template<class I, class M>
00214   forceinline void
00215   Map<I,M,true>::init(I& i0, const M& m0) {
00216     i=i0; m=m0;
00217   }
00218 
00219   template<class I, class M>
00220   forceinline
00221   Map<I,M,true>::Map(I& i0) : i(i0) {}
00222   template<class I, class M>
00223   forceinline
00224   Map<I,M,true>::Map(I& i0, const M& m0) : i(i0), m(m0) {}
00225 
00226   template<class I, class M>
00227   forceinline bool
00228   Map<I,M,true>::operator ()(void) const {
00229     return i();
00230   }
00231   template<class I, class M>
00232   forceinline void
00233   Map<I,M,true>::operator ++(void) {
00234     ++i;
00235   }
00236 
00237   template<class I, class M>
00238   forceinline int
00239   Map<I,M,true>::min(void) const {
00240     return m.min(i.min());
00241   }
00242   template<class I, class M>
00243   forceinline int
00244   Map<I,M,true>::max(void) const {
00245     return m.max(i.max());
00246   }
00247   template<class I, class M>
00248   forceinline unsigned int
00249   Map<I,M,true>::width(void) const {
00250     return static_cast<unsigned int>(max()-min())+1;
00251   }
00252 
00253 }}}
00254 
00255 // STATISTICS: iter-any
00256