[KLF Application][KLF Tools][KLF Backend][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: klffactory.cpp 603 2011-02-26 23:14:55Z phfaist $ */
23 
24 #include <QDebug>
25 #include <QStringList>
26 
27 #include "klffactory.h"
28 
29 
31  : pFactoryManager(factoryManager)
32 {
33  pFactoryManager->registerFactory(this);
34 }
36 {
37  pFactoryManager->unRegisterFactory(this);
38 }
39 
41 {
42 }
44 {
45 }
46 
48 {
49  int k;
50  for (k = 0; k < pRegisteredFactories.size(); ++k) {
51  KLFFactoryBase * factory = pRegisteredFactories[k];
52  if (factory->supportedTypes().contains(objType)) {
53  return factory;
54  }
55  }
56  qWarning()
57  <<"KLFFactoryManager::findFactoryFor(object type="<<objType<<"): No factory found!";
58 
59  return NULL;
60 }
61 
63 {
64  QStringList objtypes;
65  int k;
66  for (k = 0; k < pRegisteredFactories.size(); ++k) {
67  objtypes << pRegisteredFactories[k]->supportedTypes();
68  }
69  return objtypes;
70 }
71 
72 void KLFFactoryManager::registerFactory(KLFFactoryBase *factory)
73 {
74  if (pRegisteredFactories.indexOf(factory) != -1) {
75  qWarning()<<"KLFFactory<>::registerFactory(): Factory " << factory << " is already registered!";
76  return;
77  }
78  pRegisteredFactories.prepend(factory);
79 }
80 
81 void KLFFactoryManager::unRegisterFactory(KLFFactoryBase *factory)
82 {
83  if (pRegisteredFactories.indexOf(factory) == -1) {
84  qWarning()<<"KLFFactory<>::unRegisterFactory(): Factory "<<factory<<" is not registered!";
85  return;
86  }
87  pRegisteredFactories.removeAll(factory);
88 }
89 
90 
KLFFactoryBase(KLFFactoryManager *factoryManager)
Definition: klffactory.cpp:30
contains(const QString &str, Qt::CaseSensitivity cs=Qt::CaseSensitive)
indexOf(const T &value, int from=0)
KLFFactoryBase * findFactoryFor(const QString &objType)
Definition: klffactory.cpp:47
removeAll(const T &value)
virtual ~KLFFactoryBase()
Definition: klffactory.cpp:35
virtual ~KLFFactoryManager()
Definition: klffactory.cpp:43
QStringList allSupportedTypes()
Definition: klffactory.cpp:62
prepend(const T &value)
Base class for factories.
Definition: klffactory.h:40
virtual QStringList supportedTypes() const =0
A list of object types that this factory supports instantiating.
A base abstract factory manager class.
Definition: klffactory.h:90

Generated by doxygen 1.8.8