QElectroTech  0.8-dev
elementfactory.h
Go to the documentation of this file.
1 /*
2  Copyright 2006-2020 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 
23 class Element;
24 class ElementsLocation;
25 class 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
ElementsLocation::exist
bool exist() const
ElementsLocation::exist.
Definition: elementslocation.cpp:472
reportelement.h
ElementFactory::operator=
ElementFactory operator=(const ElementFactory &)
ElementFactory
The ElementFactory class this class is a pattern factory and also a singleton factory....
Definition: elementfactory.h:34
terminalelement.h
ElementFactory::ElementFactory
ElementFactory(const ElementFactory &)
ReportElement
Definition: reportelement.h:29
simpleelement.h
SlaveElement
Definition: slaveelement.h:25
ElementFactory::factory_
static ElementFactory * factory_
Definition: elementfactory.h:61
ElementsLocation::isElement
bool isElement() const
ElementsLocation::isElement.
Definition: elementslocation.cpp:412
TerminalElement
The TerminalElement class.
Definition: terminalelement.h:29
ElementFactory::createElement
Element * createElement(const ElementsLocation &, QGraphicsItem *=nullptr, int *=nullptr)
ElementFactory::createElement.
Definition: elementfactory.cpp:34
ElementsLocation::pugiXml
pugi::xml_document pugiXml() const
ElementsLocation::pugiXml.
Definition: elementslocation.cpp:610
ElementFactory::dropInstance
static void dropInstance()
Definition: elementfactory.h:49
Element
Definition: element.h:41
MasterElement
The MasterElement class This class is a custom element, with extended behavior to be a master element...
Definition: masterelement.h:32
ElementFactory::Instance
static ElementFactory * Instance()
Definition: elementfactory.h:38
SimpleElement
The SimpleElement class this class represente a simple element with no specific attribute.
Definition: simpleelement.h:29
ElementsLocation
The ElementsLocation class This class represents the location, the location of an element or of a cat...
Definition: elementslocation.h:46
ElementFactory::~ElementFactory
~ElementFactory()
Definition: elementfactory.h:68
ElementFactory::ElementFactory
ElementFactory()
Definition: elementfactory.h:65
masterelement.h
elementfactory.h
slaveelement.h