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