author | eilers <eilers> | 2004-04-28 09:22:02 (UTC) |
---|---|---|
committer | eilers <eilers> | 2004-04-28 09:22:02 (UTC) |
commit | 134b7accd6bdc8fbc160a42f7c52c585e73f4add (patch) (side-by-side diff) | |
tree | 5e221e990d0c94e38d816e147762f205733b0e72 /libopie2/opiepim/core/opimaccesstemplate.h | |
parent | 8ce67859c54234dabd88e17a0bc72369ea8301a3 (diff) | |
download | opie-134b7accd6bdc8fbc160a42f7c52c585e73f4add.zip opie-134b7accd6bdc8fbc160a42f7c52c585e73f4add.tar.gz opie-134b7accd6bdc8fbc160a42f7c52c585e73f4add.tar.bz2 |
Some modifications to alow use of generic OPimRecords without need to
cast them manually to the right type
Diffstat (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opiepim/core/opimaccesstemplate.h | 28 |
1 files changed, 25 insertions, 3 deletions
diff --git a/libopie2/opiepim/core/opimaccesstemplate.h b/libopie2/opiepim/core/opimaccesstemplate.h index f1bcc44..d4c5fbb 100644 --- a/libopie2/opiepim/core/opimaccesstemplate.h +++ b/libopie2/opiepim/core/opimaccesstemplate.h @@ -1,15 +1,16 @@ /* This file is part of the Opie Project - Copyright (C) The Main Author <main-author@whereever.org> + Copyright (C) Holger Freyther <zecke@handhelds.org> + Copyright (C) Stefan Eilers <eilers.stefan@epost.de> =. Copyright (C) The Opie Team <opie-devel@handhelds.org> .=l. .>+-= _;:, .> :=|. This program is free software; you can .> <`_, > . <= redistribute it and/or modify it under :`=1 )Y*s>-.-- : the terms of the GNU Library General Public .="- .-=="i, .._ License as published by the Free Software - . .-<_> .<> Foundation; either version 2 of the License, ._= =} : or (at your option) any later version. .%`+i> _;_. .i_,=:_. -<s. This program is distributed in the hope that + . -:. = it will be useful, but WITHOUT ANY WARRANTY; @@ -128,24 +129,31 @@ public: /** * clears the backend and invalidates the backend */ void clear() ; /** * add T to the backend * @param t The item to add. * @return <i>true</i> if added successfully. */ virtual bool add( const T& t ) ; bool add( const OPimRecord& ); + // Needed for real generic access (eilers) + // Info: Take this if you are working with OPimRecord, which is a generic base class, and + // you need to add it into any database, you cannot generate a reference to + // it and casting may be not approriate, too. + // But take care that the accessing database is compatible to the real type of OPimRecord !! + bool add( const OPimRecord* ); + /* only the uid matters */ /** * remove T from the backend * @param t The item to remove * @return <i>true</i> if successful. */ virtual bool remove( const T& t ); /** * remove the OPimRecord with uid * @param uid The ID of the item to remove @@ -262,33 +270,47 @@ T OPimAccessTemplate<T>::find( int uid, const QArray<int>& ar, return t; } template <class T> void OPimAccessTemplate<T>::clear() { invalidateCache(); m_backEnd->clear(); } template <class T> bool OPimAccessTemplate<T>::add( const T& t ) { cache( t ); return m_backEnd->add( t ); } + template <class T> bool OPimAccessTemplate<T>::add( const OPimRecord& rec) { /* same type */ - if ( rec.rtti() == T::rtti() ) { - const T &t = static_cast<const T&>(rec); + T tempInstance; + if ( rec.rtti() == tempInstance.rtti() ) { + const T& t = static_cast<const T&>(rec); return add(t); } return false; } + +template <class T> +bool OPimAccessTemplate<T>::add( const OPimRecord* rec) { + /* same type, but pointer */ + T tempInstance; + if ( rec -> rtti() == tempInstance.rtti() ) { + const T* t = static_cast<const T*>(rec); + return add( *t ); + } + return false; +} + template <class T> bool OPimAccessTemplate<T>::remove( const T& t ) { return remove( t.uid() ); } template <class T> bool OPimAccessTemplate<T>::remove( int uid ) { m_cache.remove( uid ); return m_backEnd->remove( uid ); } template <class T> bool OPimAccessTemplate<T>::remove( const OPimRecord& rec) { return remove( rec.uid() ); |