akregator/src

storagefactoryregistry.cpp

00001 /*
00002     This file is part of Akregator.
00003 
00004     Copyright (C) 2005 Frank Osterfeld <frank.osterfeld@kdemail.net>
00005 
00006     This program is free software; you can redistribute it and/or modify
00007     it under the terms of the GNU General Public License as published by
00008     the Free Software Foundation; either version 2 of the License, or
00009     (at your option) any later version.
00010 
00011     This program is distributed in the hope that it will be useful,
00012     but WITHOUT ANY WARRANTY; without even the implied warranty of
00013     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00014     GNU General Public License for more details.
00015 
00016     You should have received a copy of the GNU General Public License
00017     along with this program; if not, write to the Free Software
00018     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00019 
00020     As a special exception, permission is given to link this program
00021     with any edition of Qt, and distribute the resulting executable,
00022     without including the source code for Qt in the source distribution.
00023 */
00024 
00025 #include "storagefactory.h"
00026 #include "storagefactoryregistry.h"
00027 
00028 #include <kstaticdeleter.h>
00029 
00030 #include <qmap.h>
00031 #include <qstring.h>
00032 #include <qstringlist.h>
00033 
00034 namespace Akregator {
00035 namespace Backend {
00036 
00037 class StorageFactoryRegistry::StorageFactoryRegistryPrivate
00038 {
00039     public:
00040         QMap<QString, StorageFactory*> map;
00041 };
00042 
00043 StorageFactoryRegistry* StorageFactoryRegistry::m_instance = 0;
00044 static KStaticDeleter<StorageFactoryRegistry> storagefactoryregistrysd;
00045 
00046 StorageFactoryRegistry* StorageFactoryRegistry::self()
00047 {
00048     if (!m_instance)
00049         m_instance = storagefactoryregistrysd.setObject(m_instance, new StorageFactoryRegistry);
00050     return m_instance;
00051 }
00052     
00053 bool StorageFactoryRegistry::registerFactory(StorageFactory* factory, const QString& typestr)
00054 {
00055     if (containsFactory(typestr))
00056         return false;
00057     d->map[typestr] = factory;
00058     return true; 
00059 }
00060 
00061 void StorageFactoryRegistry::unregisterFactory(const QString& typestr)
00062 {
00063     d->map.remove(typestr);
00064 }
00065 
00066 StorageFactory* StorageFactoryRegistry::getFactory(const QString& typestr)
00067 {
00068     return d->map[typestr];
00069 }
00070 
00071 bool StorageFactoryRegistry::containsFactory(const QString& typestr) const
00072 {
00073     return d->map.contains(typestr);
00074 }
00075 
00076 QStringList StorageFactoryRegistry::list() const
00077 {
00078     return d->map.keys();
00079 }
00080 
00081 StorageFactoryRegistry::StorageFactoryRegistry() : d(new StorageFactoryRegistryPrivate)
00082 {
00083 }
00084 
00085 StorageFactoryRegistry::~StorageFactoryRegistry()
00086 {
00087     delete d; 
00088     d = 0;
00089 }
00090 
00091 }
00092 }
KDE Home | KDE Accessibility Home | Description of Access Keys