ranges-size.hpp
Go to the documentation of this file.00001 /* -*- mode: C++; c-basic-offset: 2; indent-tabs-mode: nil -*- */ 00002 /* 00003 * Main authors: 00004 * Guido Tack <tack@gecode.org> 00005 * 00006 * Copyright: 00007 * Guido Tack, 2006 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 Ranges { 00035 00045 template<class I> 00046 class Size { 00047 protected: 00049 I i; 00051 unsigned int _size; 00052 public: 00054 00055 00056 Size(void); 00058 Size(I& i); 00060 void init(I& i); 00062 00064 00065 00066 bool operator ()(void); 00068 void operator ++(void); 00070 00072 00073 00074 int min(void) const; 00076 int max(void) const; 00078 unsigned int width(void) const; 00080 00082 00083 00084 unsigned int size(void) const; 00086 }; 00087 00088 00089 template<class I> 00090 forceinline 00091 Size<I>::Size(void) 00092 : _size(0) {} 00093 00094 template<class I> 00095 inline void 00096 Size<I>::init(I& i0) { 00097 i.init(i0); 00098 _size = 0; 00099 } 00100 00101 template<class I> 00102 inline 00103 Size<I>::Size(I& i0) : i(i0), _size(0) {} 00104 00105 template<class I> 00106 forceinline void 00107 Size<I>::operator ++(void) { 00108 _size += i.width(); 00109 ++i; 00110 } 00111 template<class I> 00112 forceinline bool 00113 Size<I>::operator ()(void) { 00114 return i(); 00115 } 00116 00117 template<class I> 00118 forceinline int 00119 Size<I>::min(void) const { 00120 return i.min(); 00121 } 00122 template<class I> 00123 forceinline int 00124 Size<I>::max(void) const { 00125 return i.max(); 00126 } 00127 template<class I> 00128 forceinline unsigned int 00129 Size<I>::width(void) const { 00130 return i.width(); 00131 } 00132 00133 template<class I> 00134 forceinline unsigned int 00135 Size<I>::size(void) const { 00136 return _size; 00137 } 00138 00139 }}} 00140 00141 // STATISTICS: iter-any 00142