Generated on Mon May 10 06:46:41 2010 for Gecode by doxygen 1.6.3

ranges-minus.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  *  Last modified:
00010  *     $Date: 2009-09-08 21:10:29 +0200 (Tue, 08 Sep 2009) $ by $Author: schulte $
00011  *     $Revision: 9692 $
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     IsRangeIter<I> _checkI;
00057   private:
00059     class Range {
00060     public:
00061       int min; int max;
00062     };
00064     SharedArray<Range> r;
00066     int c;
00067   public:
00069 
00070 
00071     Minus(void);
00073     Minus(I& i);
00075     void init(I& i);
00077 
00079 
00080 
00081     bool operator ()(void) const;
00083     void operator ++(void);
00085 
00087 
00088 
00089     int min(void) const;
00091     int max(void) const;
00093     unsigned int width(void) const;
00095   };
00096 
00097 
00098   template<class I>
00099   forceinline
00100   Minus<I>::Minus(void) {}
00101 
00102   template<class I>
00103   inline void
00104   Minus<I>::init(I& i) {
00105     Support::DynamicArray<Range,Heap> d(heap);
00106     int n=0;
00107     while (i()) {
00108       d[n].min = -i.max(); d[n].max = -i.min();
00109       ++n; ++i;
00110     }
00111     r.init(n);
00112     for (int j=n; j--; )
00113       r[j]=d[j];
00114     c = n-1;
00115   }
00116 
00117   template<class I>
00118   inline
00119   Minus<I>::Minus(I& i) {
00120     init(i);
00121   }
00122 
00123   template<class I>
00124   forceinline void
00125   Minus<I>::operator ++(void) {
00126     c--;
00127   }
00128   template<class I>
00129   forceinline bool
00130   Minus<I>::operator ()(void) const {
00131     return c >= 0;
00132   }
00133 
00134   template<class I>
00135   forceinline int
00136   Minus<I>::min(void) const {
00137     return r[c].min;
00138   }
00139   template<class I>
00140   forceinline int
00141   Minus<I>::max(void) const {
00142     return r[c].max;
00143   }
00144   template<class I>
00145   forceinline unsigned int
00146   Minus<I>::width(void) const {
00147     return static_cast<unsigned int>(r[c].max-r[c].min+1);
00148   }
00149 
00150 }}}
00151 
00152 // STATISTICS: iter-any
00153