Diffstat (limited to 'libopie2/opiepim/orecordlist.h') (more/less context) (show whitespace changes)
-rw-r--r-- | libopie2/opiepim/orecordlist.h | 100 |
1 files changed, 53 insertions, 47 deletions
diff --git a/libopie2/opiepim/orecordlist.h b/libopie2/opiepim/orecordlist.h index 65c2169..a3955b0 100644 --- a/libopie2/opiepim/orecordlist.h +++ b/libopie2/opiepim/orecordlist.h @@ -2,33 +2,32 @@ #ifndef OPIE_RECORD_LIST_H #define OPIE_RECORD_LIST_H -#include <opie/opimaccesstemplate.h> -#include <opie/opimrecord.h> +#include <qarray.h> + +#include "otemplatebase.h" +#include "opimrecord.h" + template <class T = OPimRecord > -class ORecordList { +class ORecordListIterator { public: - class Iterator { - friend class ORecordList; - public: - Iterator(); - ~Iterator(); - Iterator(const Iterator& ); - Iterator &operator=(const Iterator& ); + typedef OTemplateBase<T> Base; + ORecordListIterator( const QArray<int>, const Base* ); + ORecordListIterator(); + ~ORecordListIterator(); + ORecordListIterator( const ORecordListIterator& ); + ORecordListIterator &operator=(const ORecordListIterator& ); T &operator*(); - Iterator &operator++(); - Iterator &operator--(); + ORecordListIterator &operator++(); + ORecordListIterator &operator--(); - bool operator==( const Iterator& it ); - bool operator!=( const Iterator& it ); + bool operator==( const ORecordListIterator& it ); + bool operator!=( const ORecordListIterator& it ); private: - Iterator( const QArray<int>, - OPimAccessTemplate<T>* ); - QArray<int> m_uids; int m_current; - OPimAccessTemplate* m_temp; + const Base* m_temp; bool m_end : 1; T m_record; @@ -36,8 +35,14 @@ public: class IteratorPrivate; IteratorPrivate *d; }; + +template <class T = OPimRecord > +class ORecordList { +public: + typedef OTemplateBase<T> Base; + typedef ORecordListIterator<T> Iterator; ORecordList( const QArray<int>& ids, - OPimAccessTemplate<T>* acc ); + const Base* ); ~ORecordList(); Iterator begin(); Iterator end(); @@ -47,23 +52,23 @@ public: */ private: QArray<int> m_ids; - OPimAccessTemplate<T>* m_acc; + const Base* m_acc; }; /* ok now implement it */ -template <class T= OPimRecord> -ORecordList<T>::Iterator::Iterator() { +template <class T> +ORecordListIterator<T>::ORecordListIterator() { m_current = 0; m_temp = 0l; m_end = true; } -template <class T= OPimRecord> -ORecordList<T>::Iterator::~Iterator() { +template <class T> +ORecordListIterator<T>::~ORecordListIterator() { /* nothing to delete */ } -template <class T = OPimRecord> -ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) { +template <class T> +ORecordListIterator<T>::ORecordListIterator( const ORecordListIterator<T>& it) { m_uids = it.m_uids; m_current = it.m_current; m_temp = it.m_temp; @@ -71,8 +76,8 @@ ORecordList<T>::Iterator::Iterator( const ORecordList<T>::Iterator& it) { m_record = it.m_record; } -template <class T = OPimRecord> -ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T>::Iterator& it) { +template <class T> +ORecordListIterator<T> &ORecordListIterator<T>::operator=( const ORecordListIterator<T>& it) { m_uids = it.m_uids; m_current = it.m_current; m_temp = it.m_temp; @@ -82,18 +87,18 @@ ORecordList<T>::Iterator &ORecordList::Iterator::operator=( const ORecordList<T> return *this; } -template <class T = OPimRecord> -T &ORecordList<T>::Iterator::operator*() { +template <class T> +T &ORecordListIterator<T>::operator*() { if (!m_end ) m_record = m_temp->find( m_uids[m_current] ); else - m_record = T; + m_record = T(); return m_record; } -template <class T = OPimRecord> -ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() { +template <class T> +ORecordListIterator<T> &ORecordListIterator<T>::operator++() { if (m_current < m_uids.count() ) { m_end = false; ++m_current; @@ -102,8 +107,8 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator++() { return *this; } -template <class T = OPimRecord> -ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() { +template <class T> +ORecordListIterator<T> &ORecordListIterator<T>::operator--() { if ( m_current > 0 ) { --m_current; m_end = false; @@ -113,8 +118,8 @@ ORecordList<T>::Iterator &ORecordList<T>::Iterator::operator--() { return *this; } -template <class T = OPimRecord> -bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) { +template <class T> +bool ORecordListIterator<T>::operator==( const ORecordListIterator<T>& it ) { /* if both are at we're the same.... */ if ( m_end == it.m_end ) return true; @@ -125,32 +130,33 @@ bool ORecordList<T>::Iterator::operator==( const ORecordList<T>::Iterator& it ) return true; } -template <class T = ORecordList> -bool ORecordList<T>::Iterator::operator!=( const ORecordList<T>::Iterator it ) { +template <class T> +bool ORecordListIterator<T>::operator!=( const ORecordListIterator<T>& it ) { return !(*this == it ); } -template <class T = ORecordList> -ORecordList<T>::Iterator::Iterator( const QArray<int> uids, - OPimAccessTemplate<T>* t ) +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 ) { } -template <class T = ORecordList> + +template <class T> ORecordList<T>::ORecordList( const QArray<int>& ids, - OPimAccessTemplate<T>* acc ) + const Base* acc ) : m_ids( ids ), m_acc( acc ) { } -template <class T = ORecordList> +template <class T> ORecordList<T>::~ORecordList() { /* nothing to do here */ } -template <class T = ORecordList> +template <class T> ORecordList<T>::Iterator ORecordList<T>::begin() { Iterator it( m_ids, m_acc ); return it; } -template <class T = ORecordList> +template <class T> ORecordList<T>::Iterator ORecordList<T>::end() { Iterator it( m_ids, m_acc ); it.m_end = true; |