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

values-bitset.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  *  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 Values {
00035 
00041   template<class BS>
00042   class BitSet {
00043   protected:
00045     const BS& bs;
00047     unsigned int cur;
00049     unsigned int limit;
00051     void move(void);
00052   public:
00054 
00055 
00056     BitSet(const BS& bs);
00058     BitSet(const BS& bs, int n, int m);
00060 
00062 
00063 
00064     bool operator ()(void) const;
00066     void operator ++(void);
00068 
00070 
00071 
00072     int val(void) const;
00074   };
00075 
00076 
00077   template<class BS>
00078   forceinline
00079   BitSet<BS>::BitSet(const BS& bs0)
00080     : bs(bs0), cur(bs.next(0)), limit(bs.size()) {
00081   }
00082 
00083   template<class BS>
00084   forceinline
00085   BitSet<BS>::BitSet(const BS& bs0, int n, int m)
00086     : bs(bs0),
00087       cur(bs.next(static_cast<unsigned int>(n))),
00088       limit(std::min(bs.size(),static_cast<unsigned int>(m)+1)) {
00089   }
00090 
00091   template<class BS>
00092   forceinline void
00093   BitSet<BS>::operator ++(void) {
00094     cur=bs.next(cur+1);
00095   }
00096   template<class BS>
00097   forceinline bool
00098   BitSet<BS>::operator ()(void) const {
00099     return cur < limit;
00100   }
00101 
00102   template<class BS>
00103   forceinline int
00104   BitSet<BS>::val(void) const {
00105     return static_cast<int>(cur);
00106   }
00107 
00108 }}}
00109 
00110 // STATISTICS: iter-any