[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: klffactory.cpp 673 2011-07-27 13:45:42Z phfaist $ */
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 
46 {
47 }
49 {
50 }
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 
77 void 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 
86 void 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 declarations for klatexformula and some utilities.
bool contains(const QString &str, Qt::CaseSensitivity cs) const
Base class for factories.
Definition: klffactory.h:40
#define KLF_ASSERT_NOT_NULL(ptr, msg, failaction)
Asserting Non-NULL pointers (NON-FATAL)
A base abstract factory manager class.
Definition: klffactory.h:91
virtual ~KLFFactoryManager()
Definition: klffactory.cpp:48
QStringList allSupportedTypes()
Definition: klffactory.cpp:67
KLFFactoryBase * findFactoryFor(const QString &objType)
Definition: klffactory.cpp:52
virtual QStringList supportedTypes() const =0
A list of object types that this factory supports instantiating.
virtual ~KLFFactoryBase()
Definition: klffactory.cpp:37
KLFFactoryBase(KLFFactoryManager *factoryManager)
Definition: klffactory.cpp:31

Generated by doxygen 1.8.13