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

values-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, 2007
00008  *
00009  *  Last modified:
00010  *     $Date: 2008-07-11 09:47:36 +0200 (Fri, 11 Jul 2008) $ by $Author: tack $
00011  *     $Revision: 7308 $
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 Values {
00039 
00052   template <class I>
00053   class Minus  {
00054   private:
00056     SharedArray<int> v;
00058     int c;
00059   public:
00061 
00062 
00063     Minus(void);
00065     Minus(I& i);
00067     void init(I& i);
00069 
00071 
00072 
00073     bool operator()(void) const;
00075     void operator++(void);
00077 
00079 
00080 
00081     int val(void) const;
00083   };
00084 
00085 
00086   template <class I>
00087   forceinline
00088   Minus<I>::Minus(void) {}
00089 
00090   template <class I>
00091   inline void
00092   Minus<I>::init(I& i) {
00093     Support::DynamicArray<int> d;
00094     int n=0;
00095     while (i()) {
00096       d[n] = -i.val();
00097       ++n; ++i;
00098     }
00099     v.init(n);
00100     for (int j=n; j--; )
00101       v[j]=d[j];
00102     c = n-1;
00103   }
00104 
00105   template <class I>
00106   forceinline
00107   Minus<I>::Minus(I& i) {
00108     init(i);
00109   }
00110 
00111   template <class I>
00112   forceinline void
00113   Minus<I>::operator++(void) {
00114     c--;
00115   }
00116   template <class I>
00117   forceinline bool
00118   Minus<I>::operator()(void) const {
00119     return c >= 0;
00120   }
00121 
00122   template <class I>
00123   forceinline int
00124   Minus<I>::val(void) const {
00125     return v[c];
00126   }
00127 
00128 }}}
00129 
00130 // STATISTICS: iter-any