QElectroTech 0.100.0-dev
Loading...
Searching...
No Matches
elementfactory.h
Go to the documentation of this file.
1/*
2 Copyright 2006-2024 The QElectroTech Team
3 This file is part of QElectroTech.
4
5 QElectroTech is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 2 of the License, or
8 (at your option) any later version.
9
10 QElectroTech is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with QElectroTech. If not, see <http://www.gnu.org/licenses/>.
17*/
18#ifndef ELEMENTFACTORY_H
19#define ELEMENTFACTORY_H
20
21#include <QMutex>
22
23class Element;
25class QGraphicsItem;
26
34{
35 //methods for singleton pattern
36 public:
37 // return instance of factory
39 static QMutex mutex;
40 if (!factory_) {
41 mutex.lock();
42 if (!factory_) factory_ = new ElementFactory();
43 mutex.unlock();
44 }
45 return factory_;
46 }
47
48 // delete the instance of factory
49 static void dropInstance () {
50 static QMutex mutex;
51 if (factory_) {
52 mutex.lock();
53 delete factory_;
54 factory_ = nullptr;
55 mutex.unlock();
56 }
57 }
58
59 //attributes
60 private:
62
63 //methods for the class factory himself
64 private:
69
70 public:
71 Element *createElement (const ElementsLocation &, QGraphicsItem * = nullptr, int * = nullptr);
72};
73//ElementFactory ElementFactory::factory_ = 0;
74#endif // ELEMENTFACTORY_H
The ElementFactory class this class is a pattern factory and also a singleton factory....
Definition elementfactory.h:34
static ElementFactory * factory_
Definition elementfactory.h:61
Element * createElement(const ElementsLocation &, QGraphicsItem *=nullptr, int *=nullptr)
ElementFactory::createElement.
Definition elementfactory.cpp:36
ElementFactory(const ElementFactory &)
static void dropInstance()
Definition elementfactory.h:49
ElementFactory operator=(const ElementFactory &)
~ElementFactory()
Definition elementfactory.h:68
static ElementFactory * Instance()
Definition elementfactory.h:38
ElementFactory()
Definition elementfactory.h:65
Definition element.h:43
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition elementslocation.h:47