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') diff --git a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp index 401a3c1..14207be 100644 --- a/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp +++ b/libopie2/opiepim/backend/ocontactaccessbackend_sql.cpp @@ -430,6 +430,7 @@ QArray OPimContactAccessBackend_SQL::allRecords() const bool OPimContactAccessBackend_SQL::add ( const OPimContact &newcontact ) { + qDebug("add in contact SQL-Backend"); InsertQuery ins( newcontact ); OSQLResult res = m_driver->query( &ins ); diff --git a/libopie2/opiepim/core/ocontactaccess.cpp b/libopie2/opiepim/core/ocontactaccess.cpp index 4f9b504..67f267f 100644 --- a/libopie2/opiepim/core/ocontactaccess.cpp +++ b/libopie2/opiepim/core/ocontactaccess.cpp @@ -52,6 +52,7 @@ #include #include +#include namespace Opie { @@ -149,4 +150,9 @@ void OPimContactAccess::copMessage( const QCString &msg, const QByteArray & ) } } +int OPimContactAccess::rtti() const +{ + return OPimResolver::AddressBook; +} + } diff --git a/libopie2/opiepim/core/ocontactaccess.h b/libopie2/opiepim/core/ocontactaccess.h index cf5333a..4429b6f 100644 --- a/libopie2/opiepim/core/ocontactaccess.h +++ b/libopie2/opiepim/core/ocontactaccess.h @@ -127,6 +127,11 @@ class OPimContactAccess: public QObject, public OPimAccessTemplate * @return true if successful */ bool save(); + + /** + * Return identification of used records + */ + int rtti() const; signals: /* Signal is emitted if the database was changed. Therefore diff --git a/libopie2/opiepim/core/odatebookaccess.cpp b/libopie2/opiepim/core/odatebookaccess.cpp index ac310c1..29298ea 100644 --- a/libopie2/opiepim/core/odatebookaccess.cpp +++ b/libopie2/opiepim/core/odatebookaccess.cpp @@ -28,6 +28,7 @@ */ #include #include +#include namespace Opie { /** @@ -108,5 +109,9 @@ OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const Q OEffectiveEvent::ValueList ODateBookAccess::effectiveNonRepeatingEvents( const QDateTime& start ) const { return m_backEnd->effectiveNonRepeatingEvents( start ); } +int ODateBookAccess::rtti() const +{ + return OPimResolver::DateBook; +} } diff --git a/libopie2/opiepim/core/odatebookaccess.h b/libopie2/opiepim/core/odatebookaccess.h index 6c9290f..c6c3598 100644 --- a/libopie2/opiepim/core/odatebookaccess.h +++ b/libopie2/opiepim/core/odatebookaccess.h @@ -64,6 +64,12 @@ public: OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDate& from, const QDate& to ) const; OEffectiveEvent::ValueList effectiveNonRepeatingEvents( const QDateTime& start ) const; + /** + * Return identification of used records + */ + int rtti() const; + + private: ODateBookAccessBackend* m_backEnd; class Private; 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() ); diff --git a/libopie2/opiepim/core/opimtemplatebase.h b/libopie2/opiepim/core/opimtemplatebase.h index 58cbfeb..b48dfed 100644 --- a/libopie2/opiepim/core/opimtemplatebase.h +++ b/libopie2/opiepim/core/opimtemplatebase.h @@ -1,6 +1,6 @@ /* This file is part of the Opie Project - Copyright (C) The Main Author + Copyright (C) Holger Freyther =. Copyright (C) The Opie Team .=l. .>+-= @@ -49,10 +49,11 @@ struct OPimBase { /** * return the rtti */ - virtual int rtti()= 0; + virtual int rtti() const = 0; virtual OPimRecord* record()const = 0; virtual OPimRecord* record(int uid)const = 0; virtual bool add( const OPimRecord& ) = 0; + virtual bool add( const OPimRecord* ) = 0; virtual bool remove( int uid ) = 0; virtual bool remove( const OPimRecord& ) = 0; virtual void clear() = 0; @@ -90,8 +91,6 @@ public: virtual void cache( const T& )const = 0; virtual void setSaneCacheSize( int ) = 0; - /* reimplement of OPimBase */ - int rtti(); OPimRecord* record()const; OPimRecord* record(int uid )const; static T* rec(); @@ -100,14 +99,7 @@ private: OTemplateBasePrivate *d; }; -/* - * implementation - */ -template -int -OTemplateBase::rtti() { - return T::rtti(); -} + template OPimRecord* OTemplateBase::record()const { T* t = new T; diff --git a/libopie2/opiepim/core/otodoaccess.cpp b/libopie2/opiepim/core/otodoaccess.cpp index 83750d5..6fa0089 100644 --- a/libopie2/opiepim/core/otodoaccess.cpp +++ b/libopie2/opiepim/core/otodoaccess.cpp @@ -33,6 +33,7 @@ // #include "otodoaccesssql.h" #include #include +#include namespace Opie { OPimTodoAccess::OPimTodoAccess( OPimTodoAccessBackend* end, enum Access ) @@ -90,4 +91,10 @@ bool OPimTodoAccess::backendSupports( int attr, const QString& ar) const{ return backendSupport(ar).testBit( attr ); } + +int OPimTodoAccess::rtti() const +{ + return OPimResolver::TodoList; +} + } diff --git a/libopie2/opiepim/core/otodoaccess.h b/libopie2/opiepim/core/otodoaccess.h index 51f3793..3f5af30 100644 --- a/libopie2/opiepim/core/otodoaccess.h +++ b/libopie2/opiepim/core/otodoaccess.h @@ -116,6 +116,12 @@ public: * @param backend Will be used in the future when we support multiple backends */ bool backendSupports( int attr, const QString& backend = QString::null )const; + + + /** + * Return identification of used records + */ + int rtti() const; signals: /** * if the OPimTodoAccess was changed -- cgit v0.9.0.2