Generated on Tue Apr 18 10:22:14 2017 for Gecode by doxygen 1.6.3

bitset-offset.hpp

Go to the documentation of this file.
00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */
00002 /*
00003  *  Main authors:
00004  *     Christopher Mears <chris.mears@monash.edu>
00005  *
00006  *  Contributing authors:
00007  *     Mikael Lagerkvist <lagerkvist@gecode.org>
00008  *     Christian Schulte <schulte@gecode.org>
00009  *
00010  *  Copyright:
00011  *     Mikael Lagerkvist, 2007
00012  *     Christopher Mears, 2012
00013  *     Christian Schulte, 2007
00014  *
00015  *  Last modified:
00016  *     $Date: 2013-03-07 17:39:13 +0100 (Thu, 07 Mar 2013) $ by $Author: schulte $
00017  *     $Revision: 13458 $
00018  *
00019  *  This file is part of Gecode, the generic constraint
00020  *  development environment:
00021  *     http://www.gecode.org
00022  *
00023  *  Permission is hereby granted, free of charge, to any person obtaining
00024  *  a copy of this software and associated documentation files (the
00025  *  "Software"), to deal in the Software without restriction, including
00026  *  without limitation the rights to use, copy, modify, merge, publish,
00027  *  distribute, sublicense, and/or sell copies of the Software, and to
00028  *  permit persons to whom the Software is furnished to do so, subject to
00029  *  the following conditions:
00030  *
00031  *  The above copyright notice and this permission notice shall be
00032  *  included in all copies or substantial portions of the Software.
00033  *
00034  *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
00035  *  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00036  *  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00037  *  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
00038  *  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
00039  *  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
00040  *  WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00041  *
00042  */
00043 
00044 #include <climits>
00045 #include <cmath>
00046 #include <iostream>
00047 
00048 namespace Gecode { namespace Support {
00049 
00054   template<class A>
00055   class BitSetOffset : public BitSetBase {
00056   protected:
00058     A& a;
00060     int _offset;
00061   public:
00063     BitSetOffset(A& a, unsigned int s, int o);
00065     BitSetOffset(A& a, const BitSetOffset& bs);
00067     ~BitSetOffset(void);
00068 
00069     // As for the ordinary bitset, most operations can be inherited
00070     // directly from BitSetBase.  We only modify the operations that
00071     // involve indices or the offset itself.
00072 
00074     bool get(int i) const;
00076     void set(int i);
00078     void clear(int i);
00080     int next(int i) const;
00082     void resize(A& a, unsigned int n, int offset, bool set=false);
00083 
00085     int offset(void) const;
00087     int max_bit(void) const;
00089     bool valid(int i) const;
00090   };
00091 
00092   template<class A>
00093   forceinline
00094   BitSetOffset<A>::BitSetOffset(A& a0, unsigned int s, int o)
00095     : BitSetBase(a0,s), a(a0), _offset(o) {}
00096 
00097   template<class A>
00098   forceinline
00099   BitSetOffset<A>::BitSetOffset(A& a0, const BitSetOffset<A>& bs)
00100     : BitSetBase(a0,bs), a(a0), _offset(bs._offset) {}
00101 
00102   template<class A>
00103   forceinline
00104   BitSetOffset<A>::~BitSetOffset(void) {
00105     dispose(a);
00106   }
00107 
00108   template<class A>
00109   forceinline bool
00110   BitSetOffset<A>::get(int i) const { return BitSetBase::get(i-_offset); }
00111 
00112   template<class A>
00113   forceinline void
00114   BitSetOffset<A>::set(int i) { BitSetBase::set(i-_offset); }
00115 
00116   template<class A>
00117   forceinline void
00118   BitSetOffset<A>::clear(int i) { BitSetBase::clear(i-_offset); }
00119 
00120   template<class A>
00121   forceinline int
00122   BitSetOffset<A>::next(int i) const { return _offset + BitSetBase::next(i-_offset); }
00123 
00124   template<class A>
00125   void
00126   BitSetOffset<A>::resize(A& a, unsigned int n, int offset, bool set) {
00127     BitSetBase::resize(a, n, set);
00128     _offset = offset;
00129   }
00130 
00131   template<class A>
00132   forceinline int
00133   BitSetOffset<A>::offset(void) const { return _offset; }
00134 
00135   template<class A>
00136   forceinline int
00137   BitSetOffset<A>::max_bit(void) const { return _offset + size() - 1; }
00138 
00139   template<class A>
00140   forceinline bool
00141   BitSetOffset<A>::valid(int i) const { return _offset <= i && i <= _offset + (int)size() - 1; }
00142 
00143   template <class A, class Char, class Traits>
00144   std::basic_ostream<Char,Traits>&
00145   operator <<(std::basic_ostream<Char,Traits>& os, const BitSetOffset<A>& bs) {
00146     for (int i = bs.offset() ; i < bs.offset()+static_cast<int>(bs.size()) ; i++)
00147       if (bs.get(i))
00148         os << i << " ";
00149     return os;
00150   }
00151 
00152 }}
00153 
00154 // STATISTICS: support-any
00155