akregator/src

storagefactoryregistry.cpp
1/*
2 This file is part of Akregator.
3
4 Copyright (C) 2005 Frank Osterfeld <frank.osterfeld@kdemail.net>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 As a special exception, permission is given to link this program
21 with any edition of TQt, and distribute the resulting executable,
22 without including the source code for TQt in the source distribution.
23*/
24
25#include "storagefactory.h"
26#include "storagefactoryregistry.h"
27
28#include <kstaticdeleter.h>
29
30#include <tqmap.h>
31#include <tqstring.h>
32#include <tqstringlist.h>
33
34namespace Akregator {
35namespace Backend {
36
37class StorageFactoryRegistry::StorageFactoryRegistryPrivate
38{
39 public:
40 TQMap<TQString, StorageFactory*> map;
41};
42
43StorageFactoryRegistry* StorageFactoryRegistry::m_instance = 0;
44static KStaticDeleter<StorageFactoryRegistry> storagefactoryregistrysd;
45
46StorageFactoryRegistry* StorageFactoryRegistry::self()
47{
48 if (!m_instance)
49 m_instance = storagefactoryregistrysd.setObject(m_instance, new StorageFactoryRegistry);
50 return m_instance;
51}
52
53bool StorageFactoryRegistry::registerFactory(StorageFactory* factory, const TQString& typestr)
54{
55 if (containsFactory(typestr))
56 return false;
57 d->map[typestr] = factory;
58 return true;
59}
60
61void StorageFactoryRegistry::unregisterFactory(const TQString& typestr)
62{
63 d->map.remove(typestr);
64}
65
66StorageFactory* StorageFactoryRegistry::getFactory(const TQString& typestr)
67{
68 return d->map[typestr];
69}
70
71bool StorageFactoryRegistry::containsFactory(const TQString& typestr) const
72{
73 return d->map.contains(typestr);
74}
75
76TQStringList StorageFactoryRegistry::list() const
77{
78 return d->map.keys();
79}
80
81StorageFactoryRegistry::StorageFactoryRegistry() : d(new StorageFactoryRegistryPrivate)
82{
83}
84
85StorageFactoryRegistry::~StorageFactoryRegistry()
86{
87 delete d;
88 d = 0;
89}
90
91}
92}