m_desktoptmpl.h

Go to the documentation of this file.
00001 ///
00002 /// \file       m_desktoptmpl.h
00003 ///             Ease of use templates for the Desktop mode class
00004 ///
00005 
00006 /*
00007     Copyright (C) 2005-2009, Net Direct Inc. (http://www.netdirect.ca/)
00008 
00009     This program is free software; you can redistribute it and/or modify
00010     it under the terms of the GNU General Public License as published by
00011     the Free Software Foundation; either version 2 of the License, or
00012     (at your option) any later version.
00013 
00014     This program is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00017 
00018     See the GNU General Public License in the COPYING file at the
00019     root directory of this project for more details.
00020 */
00021 
00022 #ifndef __BARRY_M_DESKTOPTMPL_H__
00023 #define __BARRY_M_DESKTOPTMPL_H__
00024 
00025 #include "dll.h"
00026 #include "m_desktop.h"
00027 #include "parser.h"
00028 #include "builder.h"
00029 
00030 namespace Barry { namespace Mode {
00031 
00032 BXEXPORT void LoadDatabase(unsigned int dbId, Parser &parser);
00033 BXEXPORT void SaveDatabase(unsigned int dbId, Builder &builder);
00034 
00035 template <class RecordT, class StorageT>
00036 void Desktop::LoadDatabaseByType(StorageT &store)
00037 {
00038         unsigned int dbId = this->GetDBID( RecordT::GetDBName() );
00039         Barry::RecordParser<RecordT, StorageT> parser(store);
00040         this->LoadDatabase(dbId, parser);
00041 }
00042 
00043 template <class RecordT, class StorageT>
00044 void Desktop::SaveDatabaseByType(StorageT &store)
00045 {
00046         unsigned int dbId = this->GetDBID( RecordT::GetDBName() );
00047         Barry::RecordBuilder<RecordT, StorageT> build(store);
00048         SaveDatabase(dbId, build);
00049 }
00050 
00051 template <class StorageT>
00052 void Desktop::LoadDatabaseByName(const std::string &name, StorageT &store)
00053 {
00054         if( name == Contact::GetDBName() )
00055                 LoadDatabaseByType<Contact>(store);
00056         else if( name == Message::GetDBName() )
00057                 LoadDatabaseByType<Message>(store);
00058         else if( name == Calendar::GetDBName() )
00059                 LoadDatabaseByType<Calendar>(store);
00060         else
00061                 throw Error("Unknown database name in LoadDatabaseByName: " + name);
00062 }
00063 
00064 template <class StorageT>
00065 void Desktop::SaveDatabaseByName(const std::string &name, StorageT &store)
00066 {
00067         if( name == Contact::GetDBName() )
00068                 SaveDatabaseByType<Contact>(store);
00069         else if( name == Message::GetDBName() )
00070                 SaveDatabaseByType<Message>(store);
00071         else if( name == Calendar::GetDBName() )
00072                 SaveDatabaseByType<Calendar>(store);
00073         else
00074                 throw Error("Unknown database name in SaveDatabaseByName: " + name);
00075 }
00076 
00077 template <class RecordT>
00078 void Desktop::AddRecordByType(uint32_t recordId, const RecordT &rec)
00079 {
00080         unsigned int dbId = this->GetDBID( RecordT::GetDBName() );
00081         // FIXME - I know this is a convenience template, but it still
00082         // hurts making a temporary copy just to set the record ID...
00083         // create a better API for this.
00084         RecordT r = rec;
00085         r.SetIds(RecordT::GetDefaultRecType(), recordId);
00086         Barry::RecordFetch<RecordT> fetch(r);
00087         Barry::RecordBuilder<RecordT, Barry::RecordFetch<RecordT> > build(fetch);
00088         this->AddRecord(dbId, build);
00089 }
00090 
00091 
00092 }} // namespace Barry::Mode
00093 
00094 #endif
00095 

Generated on Mon Jan 12 10:51:13 2009 for Barry by  doxygen 1.5.7.1