Debian Codegraph @

src/Gui/WorkbenchFactory.h

raw
1 /***************************************************************************
2 * Copyright (c) 2004 Werner Mayer <wmayer[at]users.sourceforge.net> *
3 * *
4 * This file is part of the FreeCAD CAx development system. *
5 * *
6 * This library is free software; you can redistribute it and/or *
7 * modify it under the terms of the GNU Library General Public *
8 * License as published by the Free Software Foundation; either *
9 * version 2 of the License, or (at your option) any later version. *
10 * *
11 * This library is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU Library General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU Library General Public *
17 * License along with this library; see the file COPYING.LIB. If not, *
18 * write to the Free Software Foundation, Inc., 59 Temple Place, *
19 * Suite 330, Boston, MA 02111-1307, USA *
20 * *
21 ***************************************************************************/
22
23
24 #ifndef GUI_WORKBENCHFACTORY_H
25 #define GUI_WORKBENCHFACTORY_H
26
27 #include <list>
28 #include <string>
29 #include <Base/Factory.h>
30
31 namespace Gui
32 {
33 class Workbench;
34
35 /**
36 * The workbench factory provides methods for the dynamic creation of
37 * special workbenches for each module. To create these workbenches once
38 * they must be registered through a subclass of WorkbenchProducer.
39 * @note To create workbenches you should use the API of WorkbenchManager.
40 * @author Werner Mayer
41 */
42 class GuiExport WorkbenchFactoryInst: public Base::Factory
43 {
44 public:
45 /// The one and only instance.
46 static WorkbenchFactoryInst& instance();
47 /// Destructs the sole instance.
48 static void destruct();
49
50 /** Creates the workbench with \a name. If no such workbench is registered
51 * 0 is returned.
52 */
53 Workbench* createWorkbench(const char* sName) const;
54 /** Returns a list of all registered workbench classes. */
55 std::list<std::string> workbenches() const;
56
57 private:
58 static WorkbenchFactoryInst* _pcSingleton;
59
60 WorkbenchFactoryInst() = default;
61 ~WorkbenchFactoryInst() override = default;
62 };
63
64 inline GuiExport WorkbenchFactoryInst& WorkbenchFactory()
65 {
66 return WorkbenchFactoryInst::instance();
67 }
68
69 // --------------------------------------------------------------------
70
71 /**
72 * The WorkbenchProducer template class allows the registration and the creation of workbench
73 * classes.
74 * @author Werner Mayer
75 */
76 template<class CLASS>
77 class WorkbenchProducer: public Base::AbstractProducer
78 {
79 public:
80 WorkbenchProducer() = default;
81
82 ~WorkbenchProducer() override = default;
83
84 void* Produce() const override
85 {
86 return (new CLASS);
87 }
88 };
89
90 } // namespace Gui
91
92 #endif // GUI_WORKBENCHFACTORY_H