From 134b7accd6bdc8fbc160a42f7c52c585e73f4add Mon Sep 17 00:00:00 2001 From: eilers Date: Wed, 28 Apr 2004 09:22:02 +0000 Subject: Some modifications to alow use of generic OPimRecords without need to cast them manually to the right type --- (limited to 'libopie2/opiepim/core/opimaccesstemplate.h') 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,6 +1,7 @@ /* This file is part of the Opie Project - Copyright (C) The Main Author + Copyright (C) Holger Freyther + Copyright (C) Stefan Eilers =. Copyright (C) The Opie Team .=l. .>+-= @@ -137,6 +138,13 @@ public: */ 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 */ /** @@ -271,15 +279,29 @@ bool OPimAccessTemplate::add( const T& t ) { cache( t ); return m_backEnd->add( t ); } + template bool OPimAccessTemplate::add( const OPimRecord& rec) { /* same type */ - if ( rec.rtti() == T::rtti() ) { - const T &t = static_cast(rec); + T tempInstance; + if ( rec.rtti() == tempInstance.rtti() ) { + const T& t = static_cast(rec); return add(t); } return false; } + +template +bool OPimAccessTemplate::add( const OPimRecord* rec) { + /* same type, but pointer */ + T tempInstance; + if ( rec -> rtti() == tempInstance.rtti() ) { + const T* t = static_cast(rec); + return add( *t ); + } + return false; +} + template bool OPimAccessTemplate::remove( const T& t ) { return remove( t.uid() ); -- cgit v0.9.0.2