yat
0.8.3pre
|
00001 #ifndef _theplu_yat_utility_data_iterator_ 00002 #define _theplu_yat_utility_data_iterator_ 00003 00004 // $Id: DataIterator.h 2282 2010-06-26 01:38:17Z peter $ 00005 00006 /* 00007 Copyright (C) 2008 Jari Häkkinen, Peter Johansson 00008 Copyright (C) 2009, 2010 Peter Johansson 00009 00010 This file is part of the yat library, http://dev.thep.lu.se/yat 00011 00012 The yat library is free software; you can redistribute it and/or 00013 modify it under the terms of the GNU General Public License as 00014 published by the Free Software Foundation; either version 3 of the 00015 License, or (at your option) any later version. 00016 00017 The yat library is distributed in the hope that it will be useful, 00018 but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 General Public License for more details. 00021 00022 You should have received a copy of the GNU General Public License 00023 along with yat. If not, see <http://www.gnu.org/licenses/>. 00024 */ 00025 00026 #include "iterator_traits.h" 00027 00028 #include <boost/concept_check.hpp> 00029 #include <boost/iterator/iterator_adaptor.hpp> 00030 #include <boost/type_traits/remove_reference.hpp> 00031 00032 namespace theplu { 00033 namespace yat { 00034 namespace utility { 00035 00060 template<typename Base> 00061 class DataIterator 00062 : public boost::iterator_adaptor< 00063 DataIterator<Base> // Derived 00064 , Base // Base 00065 , typename boost::remove_reference<typename iterator_traits<Base>::data_reference>::type 00066 , boost::use_default // CategoryOrTraversal 00067 , typename iterator_traits<Base>::data_reference // Reference 00068 > 00069 00070 { 00071 public: 00075 explicit DataIterator(Base b) 00076 : DataIterator::iterator_adaptor_(b) 00077 { 00078 BOOST_CONCEPT_ASSERT((boost::InputIterator<Base>)); 00079 } 00080 00086 DataIterator(void) 00087 : DataIterator::iterator_adaptor_() 00088 { 00089 BOOST_CONCEPT_ASSERT((boost::InputIterator<Base>)); 00090 } 00091 00099 template<typename B2> 00100 DataIterator(DataIterator<B2> other, 00101 typename boost::enable_if_convertible<B2, Base>::type* = 0 ) 00102 : DataIterator::iterator_adaptor_(other.base()) {} 00103 00109 typename iterator_traits<Base>::data_reference operator*(void) const 00110 { return iterator_traits<Base>().data(this->base()); } 00111 00112 private: 00113 }; 00114 00122 template<typename Base> 00123 DataIterator<Base> data_iterator(Base base) 00124 { 00125 return DataIterator<Base>(base); 00126 } 00127 00128 00129 00130 }}} // of namespace utility, yat, and theplu 00131 00132 #endif