#ifndef OPIE_PIM_ACCESS_TEMPLATE_H #define OPIE_PIM_ACCESS_TEMPLATE_H #include #include #include #include #include "otemplatebase.h" /** * Thats the frontend to our OPIE PIM * Library. Either you want to use it's * interface or you want to implement * your own Access lib * Just create a OPimRecord and inherit from * the plugins */ template class OPimAccessTemplate : public OTemplateBase { public: typedef ORecordList List; typedef OPimAccessBackend BackEnd; /** * our sort order * should be safe explaining */ enum SortOrder { WildCards = 0, IgnoreCase = 1, RegExp = 2, ExactMatch = 4 }; /** * c'tor BackEnd */ OPimAccessTemplate( BackEnd* end); virtual ~OPimAccessTemplate(); /** * load from the backend */ virtual bool load(); /** * reload from the backend */ virtual bool reload(); /** * save to the backend */ virtual bool save(); /** * if the resource was changed externally */ bool wasChangedExternally()const; /** * return a List of records * you can iterate over them */ virtual List allRecords()const; /** * queryByExample */ virtual List queryByExample( const T& t, int sortOrder ); /** * find the OPimRecord uid */ virtual T find( int uid )const; /* invalidate cache here */ /** * clears the backend and invalidates the backend */ virtual void clear() ; /** * add T to the backend */ virtual bool add( const T& t ) ; /* only the uid matters */ /** * remove T from the backend */ virtual bool remove( const T& t ); /** * remove the OPimRecord with uid */ virtual bool remove( int uid ); /** * replace T from backend */ virtual bool replace( const T& t) ; protected: /** * invalidate the cache */ void invalidateCache(); void setBackEnd( BackEnd* end ); /** * returns the backend */ BackEnd* backEnd(); BackEnd* m_backEnd; }; template OPimAccessTemplate::OPimAccessTemplate( BackEnd* end ) : OTemplateBase(), m_backEnd( end ) { } template OPimAccessTemplate::~OPimAccessTemplate() { qWarning("~OPimAccessTemplate"); delete m_backEnd; } template bool OPimAccessTemplate::load() { return m_backEnd->load(); } template bool OPimAccessTemplate::reload() { return m_backEnd->reload(); } template bool OPimAccessTemplate::save() { return m_backEnd->save(); } template OPimAccessTemplate::List OPimAccessTemplate::allRecords()const { QArray ints = m_backEnd->allRecords(); List lis(ints, this ); return lis; } template OPimAccessTemplate::List OPimAccessTemplate::queryByExample( const T& t, int sortOrder ) { QArray ints = m_backEnd->queryByExample( t, sortOrder ); List lis(ints, this ); return lis; } template T OPimAccessTemplate::find( int uid ) const{ T t = m_backEnd->find( uid ); return t; } template void OPimAccessTemplate::clear() { invalidateCache(); m_backEnd->clear(); } template bool OPimAccessTemplate::add( const T& t ) { return m_backEnd->add( t ); } template bool OPimAccessTemplate::remove( const T& t ) { return m_backEnd->remove( t.uid() ); } template bool OPimAccessTemplate::remove( int uid ) { return m_backEnd->remove( uid ); } template bool OPimAccessTemplate::replace( const T& t ) { return m_backEnd->replace( t ); } template void OPimAccessTemplate::invalidateCache() { } template OPimAccessTemplate::BackEnd* OPimAccessTemplate::backEnd() { return m_backEnd; } template bool OPimAccessTemplate::wasChangedExternally()const { return false; } template void OPimAccessTemplate::setBackEnd( BackEnd* end ) { m_backEnd = end; } #endif