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

ranges-values.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, 2004
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 
00041   template<class I>
00042   class ToValues {
00043   protected:
00045     I i;
00047     int cur;
00049     int max;
00051     void start(void);
00052   public:
00054 
00055 
00056     ToValues(void);
00058     ToValues(I& i);
00060     void init(I& i);
00062 
00064 
00065 
00066     bool operator ()(void) const;
00068     void operator ++(void);
00070 
00072 
00073 
00074     int  val(void) const;
00076   };
00077 
00078 
00079 
00080   template<class I>
00081   forceinline
00082   ToValues<I>::ToValues(void) {}
00083 
00084   template<class I>
00085   forceinline void
00086   ToValues<I>::start(void) {
00087     if (i()) {
00088       cur = i.min(); max = i.max();
00089     } else {
00090       cur = 1;       max = 0;
00091     }
00092   }
00093 
00094   template<class I>
00095   forceinline
00096   ToValues<I>::ToValues(I& i0)
00097     : i(i0) {
00098     start();
00099   }
00100 
00101   template<class I>
00102   forceinline void
00103   ToValues<I>::init(I& i0) {
00104     i = i0;
00105     start();
00106   }
00107 
00108 
00109   template<class I>
00110   forceinline bool
00111   ToValues<I>::operator ()(void) const {
00112     return (cur <= max);
00113   }
00114 
00115   template<class I>
00116   forceinline void
00117   ToValues<I>::operator ++(void) {
00118     ++cur;
00119     if (cur > max) {
00120       ++i;
00121       if (i()) {
00122         cur = i.min(); max = i.max();
00123       }
00124     }
00125   }
00126 
00127   template<class I>
00128   forceinline int
00129   ToValues<I>::val(void) const {
00130     return cur;
00131   }
00132 
00133 }}}
00134 
00135 // STATISTICS: iter-any
00136