Diffstat (limited to 'libopie2/opiepim/orecordlist.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 230 |
1 files changed, 148 insertions, 82 deletions
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 8f0011b..1742dcc 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h @@ -29,7 +29,6 @@ -#ifndef OPIE_RECORD_LIST_H -#define OPIE_RECORD_LIST_H - -#include <qarray.h> +#ifndef ORECORDLIST_H +#define ORECORDLIST_H +/* OPIE */ #include <opie2/otemplatebase.h> @@ -37,3 +36,7 @@ -namespace Opie { +/* QT */ +#include <qarray.h> + +namespace Opie +{ @@ -49,5 +52,7 @@ template <class T> class ORecordList; template <class T = OPimRecord> -class ORecordListIterator { +class ORecordListIterator +{ friend class ORecordList<T>; -public: + + public: typedef OTemplateBase<T> Base; @@ -67,3 +72,3 @@ public: ORecordListIterator( const ORecordListIterator& ); - ORecordListIterator &operator=(const ORecordListIterator& ); + ORecordListIterator &operator=( const ORecordListIterator& ); @@ -83,3 +88,3 @@ public: */ - uint current()const; + uint current() const; @@ -88,3 +93,3 @@ public: */ - uint count()const; + uint count() const; @@ -95,3 +100,3 @@ public: -private: + private: QArray<int> m_uids; @@ -101,3 +106,3 @@ private: T m_record; - bool m_direction :1; + bool m_direction : 1; @@ -107,2 +112,3 @@ private: + class ORecordListPrivate; @@ -113,4 +119,5 @@ class ORecordListPrivate; template <class T = OPimRecord > -class ORecordList { -public: +class ORecordList +{ + public: typedef OTemplateBase<T> Base; @@ -121,5 +128,5 @@ public: */ - ORecordList () { - } -ORecordList( const QArray<int>& ids, + ORecordList () + {} + ORecordList( const QArray<int>& ids, const Base* ); @@ -140,10 +147,10 @@ ORecordList( const QArray<int>& ids, */ - uint count()const; + uint count() const; - T operator[]( uint i ); - int uidAt(uint i ); + T operator[] ( uint i ); + int uidAt( uint i ); - /** - * Remove the contact with given uid - */ + /** + * Remove the contact with given uid + */ bool remove( int uid ); @@ -154,3 +161,3 @@ ORecordList( const QArray<int>& ids, */ -private: + private: QArray<int> m_ids; @@ -160,5 +167,7 @@ private: + /* ok now implement it */ template <class T> -ORecordListIterator<T>::ORecordListIterator() { +ORecordListIterator<T>::ORecordListIterator() +{ m_current = 0; @@ -170,10 +179,15 @@ ORecordListIterator<T>::ORecordListIterator() { } + + template <class T> -ORecordListIterator<T>::~ORecordListIterator() { -/* nothing to delete */ +ORecordListIterator<T>::~ORecordListIterator() +{ + /* nothing to delete */ } + template <class T> -ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { -// qWarning("ORecordListIterator copy c'tor"); +ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it ) +{ + // qWarning("ORecordListIterator copy c'tor"); m_uids = it.m_uids; @@ -186,4 +200,6 @@ ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { + template <class T> -ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { +ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it ) +{ m_uids = it.m_uids; @@ -197,9 +213,11 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIter + template <class T> -T ORecordListIterator<T>::operator*() { - //qWarning("operator* %d %d", m_current, m_uids[m_current] ); - if (!m_end ) - m_record = m_temp->find( m_uids[m_current], m_uids, m_current, +T ORecordListIterator<T>::operator*() +{ + //qWarning("operator* %d %d", m_current, m_uids[m_current] ); + if ( !m_end ) + m_record = m_temp->find( m_uids[ m_current ], m_uids, m_current, m_direction ? Base::Forward : - Base::Reverse ); + Base::Reverse ); else @@ -210,9 +228,13 @@ T ORecordListIterator<T>::operator*() { + template <class T> -ORecordListIterator<T> &ORecordListIterator<T>::operator++() { +ORecordListIterator<T> &ORecordListIterator<T>::operator++() +{ m_direction = true; - if (m_current < m_uids.count() ) { + if ( m_current < m_uids.count() ) + { m_end = false; ++m_current; - }else + } + else m_end = true; @@ -221,9 +243,14 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator++() { } + + template <class T> -ORecordListIterator<T> &ORecordListIterator<T>::operator--() { +ORecordListIterator<T> &ORecordListIterator<T>::operator--() +{ m_direction = false; - if ( m_current > 0 ) { + if ( m_current > 0 ) + { --m_current; m_end = false; - } else + } + else m_end = true; @@ -233,4 +260,6 @@ ORecordListIterator<T> &ORecordListIterator<T>::operator--() { + template <class T> -bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { +bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) +{ @@ -245,25 +274,37 @@ bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { } + + template <class T> -bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { - return !(*this == it ); +bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) +{ + return !( *this == it ); } + + template <class T> ORecordListIterator<T>::ORecordListIterator( const QArray<int> uids, - const Base* t ) - : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), - m_direction( false ) + const Base* t ) + : m_uids( uids ), m_current( 0 ), m_temp( t ), m_end( false ), + m_direction( false ) { /* if the list is empty we're already at the end of the list */ - if (uids.count() == 0 ) + if ( uids.count() == 0 ) m_end = true; } + + template <class T> -uint ORecordListIterator<T>::current()const { +uint ORecordListIterator<T>::current() const +{ return m_current; } + + template <class T> -void ORecordListIterator<T>::setCurrent( uint cur ) { - if( cur < m_uids.count() ) { - m_end = false; - m_current= cur; +void ORecordListIterator<T>::setCurrent( uint cur ) +{ + if ( cur < m_uids.count() ) + { + m_end = false; + m_current = cur; } @@ -271,5 +312,8 @@ void ORecordListIterator<T>::setCurrent( uint cur ) { template <class T> -uint ORecordListIterator<T>::count()const { +uint ORecordListIterator<T>::count() const +{ return m_uids.count(); } + + template <class T> @@ -277,11 +321,16 @@ ORecordList<T>::ORecordList( const QArray<int>& ids, const Base* acc ) - : m_ids( ids ), m_acc( acc ) -{ -} + : m_ids( ids ), m_acc( acc ) +{} + + template <class T> -ORecordList<T>::~ORecordList() { -/* nothing to do here */ +ORecordList<T>::~ORecordList() +{ + /* nothing to do here */ } + + template <class T> -typename ORecordList<T>::Iterator ORecordList<T>::begin() { +typename ORecordList<T>::Iterator ORecordList<T>::begin() +{ Iterator it( m_ids, m_acc ); @@ -289,4 +338,7 @@ typename ORecordList<T>::Iterator ORecordList<T>::begin() { } + + template <class T> -typename ORecordList<T>::Iterator ORecordList<T>::end() { +typename ORecordList<T>::Iterator ORecordList<T>::end() +{ Iterator it( m_ids, m_acc ); @@ -297,8 +349,14 @@ typename ORecordList<T>::Iterator ORecordList<T>::end() { } + + template <class T> -uint ORecordList<T>::count()const { -return m_ids.count(); +uint ORecordList<T>::count() const +{ + return m_ids.count(); } + + template <class T> -T ORecordList<T>::operator[]( uint i ) { +T ORecordList<T>::operator[] ( uint i ) +{ if ( i >= m_ids.count() ) @@ -306,28 +364,36 @@ T ORecordList<T>::operator[]( uint i ) { /* forward */ - return m_acc->find( m_ids[i], m_ids, i ); -} -template <class T> -int ORecordList<T>::uidAt( uint i ) { - return m_ids[i]; + return m_acc->find( m_ids[ i ], m_ids, i ); } + template <class T> -bool ORecordList<T>::remove( int uid ) { - QArray<int> copy( m_ids.count() ); - int counter = 0; - bool ret_val = false; +int ORecordList<T>::uidAt( uint i ) +{ + return m_ids[ i ]; +} - for (uint i = 0; i < m_ids.count(); i++){ - if ( m_ids[i] != uid ){ - copy[counter++] = m_ids[i]; - }else - ret_val = true; - } +template <class T> +bool ORecordList<T>::remove( int uid ) +{ + QArray<int> copy( m_ids.count() ); + int counter = 0; + bool ret_val = false; + + for ( uint i = 0; i < m_ids.count(); i++ ) + { + if ( m_ids[ i ] != uid ) + { + copy[ counter++ ] = m_ids[ i ]; + + } + else + ret_val = true; + } - copy.resize( counter ); - m_ids = copy; + copy.resize( counter ); + m_ids = copy; - return ret_val; + return ret_val; } |