Generated on Thu Apr 11 13:59:13 2019 for Gecode by doxygen 1.6.3

ranges-add.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, 2005
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 AddRange : public MinMax {
00043   protected:
00045     I i;
00047     int r_min;
00049     int r_max;
00050   public:
00052 
00053 
00054     AddRange(void);
00056     AddRange(I& i, int min, int max);
00058     void init(I& i, int min, int max);
00060 
00062 
00063 
00064     void operator ++(void);
00066   };
00067 
00068 
00074   template<class I>
00075   class SubRange : public AddRange<I> {
00076   public:
00078 
00079 
00080     SubRange(void);
00082     SubRange(I& i, int min, int max);
00084     void init(I& i, int min, int max);
00086   };
00087 
00088   template<class I>
00089   forceinline
00090   AddRange<I>::AddRange(void) {}
00091 
00092   template<class I>
00093   forceinline void
00094   AddRange<I>::operator ++(void) {
00095     if (i()) {
00096       mi = r_min + i.min();
00097       ma = r_max + i.max();
00098       ++i;
00099       while (i() && (ma+1 >= r_min+i.min())) {
00100         ma = r_max + i.max(); ++i;
00101       }
00102     } else {
00103       finish();
00104     }
00105   }
00106 
00107   template<class I>
00108   forceinline
00109   AddRange<I>::AddRange(I& i0, int r_min0, int r_max0)
00110     : i(i0), r_min(r_min0), r_max(r_max0) {
00111     operator ++();
00112   }
00113 
00114   template<class I>
00115   forceinline void
00116   AddRange<I>::init(I& i0, int r_min0, int r_max0) {
00117     i = i0; r_min = r_min0; r_max = r_max0;
00118     operator ++();
00119   }
00120 
00121 
00122   template<class I>
00123   forceinline
00124   SubRange<I>::SubRange(void) {}
00125 
00126   template<class I>
00127   forceinline
00128   SubRange<I>::SubRange(I& i, int r_min, int r_max)
00129     : AddRange<I>(i,-r_max,-r_min) {}
00130 
00131   template<class I>
00132   forceinline void
00133   SubRange<I>::init(I& i, int r_min, int r_max) {
00134     AddRange<I>::init(i,-r_max,-r_min);
00135   }
00136 
00137 }}}
00138 
00139 // STATISTICS: iter-any
00140