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 IterPair& operator=(const IterPair& x) 00042 { 00043 m_begin=x.m_begin; 00044 m_end=x.m_end; 00045 return( *this ); 00046 } 00047 bool operator==(const IterPair& x) const 00048 { 00049 return( m_begin==x.m_begin && m_end==x.m_end ); 00050 } 00051 bool empty() const { return( m_begin==m_end ); } 00052 unsigned length() const { return( std::distance( m_begin, m_end )); } 00053 Iter begin() const { return( m_begin ); } 00054 Iter end() const { return( m_end ); } 00055 protected: 00056 Iter m_begin; 00057 Iter m_end; 00058 }; 00059 00060 template< class Container, class Iter > 00061 IterPair<Iter> MakeIterPair( Container& c ) 00062 { 00063 return( IterPair<Iter>( c.begin(), c.end() )); 00064 } 00065 00066 template< class Pred, class Iter > 00067 class MakeCondIterPair : public IterPair<Iter> 00068 { 00069 typedef IterPair<Iter> _bclass; 00070 public: 00071 MakeCondIterPair( const Iter& b, const Iter& e ) : 00072 _bclass( b, e ) {} 00073 }; 00074 00075 } 00076 00077 #endif
1.5.6