00001 /* 00002 * Copyright (c) [2004-2009] Novell, Inc. 00003 * 00004 * All Rights Reserved. 00005 * 00006 * This program is free software; you can redistribute it and/or modify it 00007 * under the terms of version 2 of the GNU General Public License as published 00008 * by the Free Software Foundation. 00009 * 00010 * This program is distributed in the hope that it will be useful, but WITHOUT 00011 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 00013 * more details. 00014 * 00015 * You should have received a copy of the GNU General Public License along 00016 * with this program; if not, contact Novell, Inc. 00017 * 00018 * To contact Novell about this file by physical or electronic mail, you may 00019 * find current contact information at www.novell.com. 00020 */ 00021 00022 00023 #ifndef ITER_PAIR_H 00024 #define ITER_PAIR_H 00025 00026 #include <iterator> 00027 00028 namespace storage 00029 { 00030 00031 template< class Iter > 00032 class IterPair 00033 { 00034 public: 00035 typedef Iter itype; 00036 IterPair(const Iter& b, const Iter& e) : m_begin(b), m_end(e) {} 00037 IterPair( const IterPair& x ) 00038 { 00039 *this = x; 00040 } 00041 00042 template <class Ip> 00043 IterPair(const Ip& x) : m_begin(x.begin()), m_end(x.end()) {} 00044 00045 template< class Ip > 00046 IterPair& operator=(const Ip& x) 00047 { 00048 m_begin=x.begin(); 00049 m_end=x.end(); 00050 return( *this ); 00051 } 00052 template< class Ip > 00053 bool operator==(const Ip& x) const 00054 { 00055 return( m_begin==x.begin() && m_end==x.end() ); 00056 } 00057 bool empty() const { return( m_begin==m_end ); } 00058 unsigned length() const { return( std::distance( m_begin, m_end )); } 00059 Iter begin() const { return( m_begin ); } 00060 Iter end() const { return( m_end ); } 00061 protected: 00062 Iter m_begin; 00063 Iter m_end; 00064 }; 00065 00066 template< class Container, class Iter > 00067 IterPair<Iter> MakeIterPair( Container& c ) 00068 { 00069 return( IterPair<Iter>( c.begin(), c.end() )); 00070 } 00071 00072 template< class Pred, class Iter > 00073 class MakeCondIterPair : public IterPair<Iter> 00074 { 00075 typedef IterPair<Iter> _bclass; 00076 public: 00077 MakeCondIterPair( const Iter& b, const Iter& e ) : 00078 _bclass( b, e ) {} 00079 }; 00080 00081 } 00082 00083 #endif
1.5.6