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

values-bitsetoffset.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, 2008
00008  *
00009  *  Converted into offset version:
00010  *     Christopher Mears <chris.mears@monash.edu>
00011  *
00012  *  This file is part of Gecode, the generic constraint
00013  *  development environment:
00014  *     http://www.gecode.org
00015  *
00016  *  Permission is hereby granted, free of charge, to any person obtaining
00017  *  a copy of this software and associated documentation files (the
00018  *  "Software"), to deal in the Software without restriction, including
00019  *  without limitation the rights to use, copy, modify, merge, publish,
00020  *  distribute, sublicense, and/or sell copies of the Software, and to
00021  *  permit persons to whom the Software is furnished to do so, subject to
00022  *  the following conditions:
00023  *
00024  *  The above copyright notice and this permission notice shall be
00025  *  included in all copies or substantial portions of the Software.
00026  *
00027  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00028  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00029  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00030  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00031  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00032  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00033  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00034  *
00035  */
00036 
00037 namespace Gecode { namespace Iter { namespace Values {
00038 
00044   template<class BS>
00045   class BitSetOffset {
00046   protected:
00048     const BS& bs;
00050     int cur;
00052     int limit;
00054     void move(void);
00055   public:
00057 
00058 
00059     BitSetOffset(const BS& bs);
00061     BitSetOffset(const BS& bs, int n, int m);
00063 
00065 
00066 
00067     bool operator ()(void) const;
00069     void operator ++(void);
00071 
00073 
00074 
00075     int val(void) const;
00077   };
00078 
00079 
00080   template<class BS>
00081   forceinline
00082   BitSetOffset<BS>::BitSetOffset(const BS& bs0)
00083     : bs(bs0), cur(bs.next(bs0.offset())), limit(bs.offset()+bs.size()) {
00084   }
00085 
00086   template<class BS>
00087   forceinline
00088   BitSetOffset<BS>::BitSetOffset(const BS& bs0, int n, int m)
00089     : bs(bs0),
00090       cur(bs.next(n)),
00091       limit(std::min(bs.offset()+bs.size(),m+1)) {
00092   }
00093 
00094   template<class BS>
00095   forceinline void
00096   BitSetOffset<BS>::operator ++(void) {
00097     cur=bs.next(cur+1);
00098   }
00099   template<class BS>
00100   forceinline bool
00101   BitSetOffset<BS>::operator ()(void) const {
00102     return cur < limit;
00103   }
00104 
00105   template<class BS>
00106   forceinline int
00107   BitSetOffset<BS>::val(void) const {
00108     return static_cast<int>(cur);
00109   }
00110 
00111 }}}
00112 
00113 // STATISTICS: iter-any