File indexing completed on 2024-12-22 04:18:00

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 "relationfactory.h"
0014 
0015 #include <QCoreApplication>
0016 #include <QMap>
0017 
0018 namespace Kst {
0019 
0020 static QMap<QString, RelationFactory*> *relation_factories = 0;
0021 
0022 void cleanupRelations() {
0023   foreach (RelationFactory *f, *relation_factories) {
0024     delete f;
0025   }
0026   delete relation_factories;
0027   relation_factories = 0;
0028 }
0029 
0030 
0031 RelationFactory::RelationFactory() {
0032 }
0033 
0034 
0035 RelationFactory::~RelationFactory() {
0036 }
0037 
0038 
0039 void RelationFactory::registerFactory(const QString& node, RelationFactory *factory) {
0040   if (!relation_factories) {
0041     relation_factories = new QMap<QString,RelationFactory*>;
0042     qAddPostRoutine(cleanupRelations);
0043   }
0044   relation_factories->insert(node, factory);
0045 }
0046 
0047 
0048 void RelationFactory::registerFactory(const QStringList& nodes, RelationFactory *factory) {
0049   foreach (const QString &n, nodes) {
0050     registerFactory(n, factory);
0051   }
0052 }
0053 
0054 
0055 RelationPtr RelationFactory::parse(ObjectStore *store, QXmlStreamReader& stream) {
0056   if (!relation_factories) {
0057     return 0;
0058   }
0059 
0060   RelationFactory *f = relation_factories->value(stream.name().toString());
0061   if (!f) {
0062     return 0;
0063   }
0064 
0065   return f->generateRelation(store, stream);
0066 }
0067 
0068 
0069 }
0070 
0071 // vim: ts=2 sw=2 et