[KLF Backend][KLF Tools][KLF Home]
KLatexFormula Project
klffactory.cpp
Go to the documentation of this file.
1/***************************************************************************
2 * file klffactory.cpp
3 * This file is part of the KLatexFormula Project.
4 * Copyright (C) 2011 by Philippe Faist
5 * philippe.faist at bluewin.ch
6 * *
7 * This program is free software; you can redistribute it and/or modify *
8 * it under the terms of the GNU General Public License as published by *
9 * the Free Software Foundation; either version 2 of the License, or *
10 * (at your option) any later version. *
11 * *
12 * This program is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU General Public License *
18 * along with this program; if not, write to the *
19 * Free Software Foundation, Inc., *
20 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 ***************************************************************************/
22/* $Id$ */
23
24#include <QStringList>
25
26#include <klfdefs.h>
27
28#include "klffactory.h"
29
30
32 : pFactoryManager(factoryManager)
33{
34 KLF_ASSERT_NOT_NULL(pFactoryManager, "NULL factory manager given!", return; ) ;
35 pFactoryManager->registerFactory(this);
36}
38{
39 KLF_ASSERT_NOT_NULL(pFactoryManager, "NULL factory manager!", return; ) ;
40 pFactoryManager->unRegisterFactory(this);
41}
42
43// --
44
51
53{
54 int k;
55 for (k = 0; k < pRegisteredFactories.size(); ++k) {
56 KLFFactoryBase * factory = pRegisteredFactories[k];
57 if (factory->supportedTypes().contains(objType)) {
58 return factory;
59 }
60 }
61 qWarning()
62 <<"KLFFactoryManager::findFactoryFor(object type="<<objType<<"): No factory found!";
63
64 return NULL;
65}
66
68{
69 QStringList objtypes;
70 int k;
71 for (k = 0; k < pRegisteredFactories.size(); ++k) {
72 objtypes << pRegisteredFactories[k]->supportedTypes();
73 }
74 return objtypes;
75}
76
77void KLFFactoryManager::registerFactory(KLFFactoryBase *factory)
78{
79 if (pRegisteredFactories.indexOf(factory) != -1) {
80 qWarning()<<"KLFFactory<>::registerFactory(): Factory " << factory << " is already registered!";
81 return;
82 }
83 pRegisteredFactories.prepend(factory);
84}
85
86void KLFFactoryManager::unRegisterFactory(KLFFactoryBase *factory)
87{
88 if (pRegisteredFactories.indexOf(factory) == -1) {
89 qWarning()<<"KLFFactory<>::unRegisterFactory(): Factory "<<factory<<" is not registered!";
90 return;
91 }
92 pRegisteredFactories.removeAll(factory);
93}
94
95
Base class for factories.
Definition klffactory.h:41
virtual QStringList supportedTypes() const =0
A list of object types that this factory supports instantiating.
KLFFactoryBase(KLFFactoryManager *factoryManager)
virtual ~KLFFactoryBase()
A base abstract factory manager class.
Definition klffactory.h:92
QStringList allSupportedTypes()
friend class KLFFactoryBase
Definition klffactory.h:118
virtual ~KLFFactoryManager()
KLFFactoryBase * findFactoryFor(const QString &objType)
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
Asserting Non-NULL pointers (NON-FATAL)
Definition klfdebug.h:210
Base declarations for klatexformula and some utilities.
int indexOf(const T &value, int from) const
void prepend(const T &value)
bool contains(const QString &str, Qt::CaseSensitivity cs) const

Generated by doxygen 1.13.2