Generated on Mon Aug 25 11:35:39 2008 for Gecode by doxygen 1.5.6

ranges-minus.icc

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  *  Last modified:
00010  *     $Date: 2007-09-19 09:51:28 +0200 (Wed, 19 Sep 2007) $ by $Author: schulte $
00011  *     $Revision: 5048 $
00012  *
00013  *  This file is part of Gecode, the generic constraint
00014  *  development environment:
00015  *     http://www.gecode.org
00016  *
00017  *  Permission is hereby granted, free of charge, to any person obtaining
00018  *  a copy of this software and associated documentation files (the
00019  *  "Software"), to deal in the Software without restriction, including
00020  *  without limitation the rights to use, copy, modify, merge, publish,
00021  *  distribute, sublicense, and/or sell copies of the Software, and to
00022  *  permit persons to whom the Software is furnished to do so, subject to
00023  *  the following conditions:
00024  *
00025  *  The above copyright notice and this permission notice shall be
00026  *  included in all copies or substantial portions of the Software.
00027  *
00028  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00029  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00030  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00031  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00032  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00033  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00034  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00035  *
00036  */
00037 
00038 namespace Gecode { namespace Iter { namespace Ranges {
00039 
00052   template <class I>
00053   class Minus  {
00054   private:
00056     class Range {
00057     public:
00058       int min; int max;
00059     };
00061     SharedArray<Range> r;
00063     int c;
00064   public:
00066 
00067 
00068     Minus(void);
00070     Minus(I& i);
00072     void init(I& i);
00074 
00076 
00077 
00078     bool operator()(void) const;
00080     void operator++(void);
00082 
00084 
00085 
00086     int min(void) const;
00088     int max(void) const;
00090     unsigned int width(void) const;
00092   };
00093 
00094 
00095   template <class I>
00096   forceinline
00097   Minus<I>::Minus(void) {}
00098 
00099   template <class I>
00100   inline void
00101   Minus<I>::init(I& i) {
00102     Support::DynamicArray<Range> d;
00103     int n=0;
00104     while (i()) {
00105       d[n].min = -i.max(); d[n].max = -i.min();
00106       ++n; ++i;
00107     }
00108     r.init(n);
00109     for (int j=n; j--; )
00110       r[j]=d[j];
00111     c = n-1;
00112   }
00113 
00114   template <class I>
00115   inline
00116   Minus<I>::Minus(I& i) {
00117     init(i);
00118   }
00119 
00120   template <class I>
00121   forceinline void
00122   Minus<I>::operator++(void) {
00123     c--;
00124   }
00125   template <class I>
00126   forceinline bool
00127   Minus<I>::operator()(void) const {
00128     return c >= 0;
00129   }
00130 
00131   template <class I>
00132   forceinline int
00133   Minus<I>::min(void) const {
00134     return r[c].min;
00135   }
00136   template <class I>
00137   forceinline int
00138   Minus<I>::max(void) const {
00139     return r[c].max;
00140   }
00141   template <class I>
00142   forceinline unsigned int
00143   Minus<I>::width(void) const {
00144     return static_cast<unsigned int>(r[c].max-r[c].min+1);
00145   }
00146 
00147 }}}
00148 
00149 // STATISTICS: iter-any
00150