File indexing completed on 2024-12-22 04:17:19
0001 /*************************************************************************** 0002 * * 0003 * copyright : (C) 2007 The University of Toronto * 0004 * netterfield@astro.utoronto.ca * 0005 * * 0006 * This program is free software; you can redistribute it and/or modify * 0007 * it under the terms of the GNU General Public License as published by * 0008 * the Free Software Foundation; either version 2 of the License, or * 0009 * (at your option) any later version. * 0010 * * 0011 ***************************************************************************/ 0012 0013 #include "datasourcefactory.h" 0014 0015 #include <QCoreApplication> 0016 #include <QMap> 0017 0018 namespace Kst { 0019 0020 static QMap<QString, DataSourceFactory*> *factories = 0; 0021 0022 void cleanupDataSources() { 0023 foreach (DataSourceFactory *f, *factories) { 0024 delete f; 0025 } 0026 delete factories; 0027 factories = 0; 0028 } 0029 0030 0031 DataSourceFactory::DataSourceFactory() { 0032 } 0033 0034 0035 DataSourceFactory::~DataSourceFactory() { 0036 } 0037 0038 0039 void DataSourceFactory::registerFactory(const QString& node, DataSourceFactory *factory) { 0040 if (!factories) { 0041 factories = new QMap<QString,DataSourceFactory*>; 0042 qAddPostRoutine(cleanupDataSources); 0043 } 0044 factories->insert(node, factory); 0045 } 0046 0047 0048 void DataSourceFactory::registerFactory(const QStringList& nodes, DataSourceFactory *factory) { 0049 foreach (const QString &n, nodes) { 0050 registerFactory(n, factory); 0051 } 0052 } 0053 0054 0055 DataSourcePtr DataSourceFactory::parse(ObjectStore *store, QXmlStreamReader& stream) { 0056 if (!factories) { 0057 return 0; 0058 } 0059 DataSourceFactory *f = factories->value(stream.name().toString()); 0060 if (!f) { 0061 return 0; 0062 } 0063 0064 return f->generateDataSource(store, stream); 0065 } 0066 0067 0068 } 0069 0070 // vim: ts=2 sw=2 et