FreeCAD

Форк
0
/
Factory.cpp 
109 строк · 3.4 Кб
1
/***************************************************************************
2
 *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>              *
3
 *                                                                         *
4
 *   This file is part of the FreeCAD CAx development system.              *
5
 *                                                                         *
6
 *   This program is free software; you can redistribute it and/or modify  *
7
 *   it under the terms of the GNU Library General Public License (LGPL)   *
8
 *   as published by the Free Software Foundation; either version 2 of     *
9
 *   the License, or (at your option) any later version.                   *
10
 *   for detail see the LICENCE text file.                                 *
11
 *                                                                         *
12
 *   FreeCAD 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 Library General Public License for more details.                  *
16
 *                                                                         *
17
 *   You should have received a copy of the GNU Library General Public     *
18
 *   License along with FreeCAD; if not, write to the Free Software        *
19
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
20
 *   USA                                                                   *
21
 *                                                                         *
22
 ***************************************************************************/
23

24

25
#include "PreCompiled.h"
26

27
#ifndef _PreComp_
28
#include <list>
29
#endif
30

31
#include "Factory.h"
32
#include "Console.h"
33

34

35
using namespace Base;
36

37

38
Factory::~Factory()
39
{
40
    for (auto& it : _mpcProducers) {
41
        delete it.second;
42
    }
43
}
44

45
void* Factory::Produce(const char* sClassName) const
46
{
47
    std::map<const std::string, AbstractProducer*>::const_iterator pProd;
48

49
    pProd = _mpcProducers.find(sClassName);
50
    if (pProd != _mpcProducers.end()) {
51
        return pProd->second->Produce();
52
    }
53

54
    return nullptr;
55
}
56

57
void Factory::AddProducer(const char* sClassName, AbstractProducer* pcProducer)
58
{
59
    _mpcProducers[sClassName] = pcProducer;
60
}
61

62
bool Factory::CanProduce(const char* sClassName) const
63
{
64
    return (_mpcProducers.find(sClassName) != _mpcProducers.end());
65
}
66

67
std::list<std::string> Factory::CanProduce() const
68
{
69
    std::list<std::string> lObjects;
70

71
    for (const auto& it : _mpcProducers) {
72
        lObjects.push_back(it.first);
73
    }
74

75
    return lObjects;
76
}
77

78
// ----------------------------------------------------
79

80
ScriptFactorySingleton* ScriptFactorySingleton::_pcSingleton = nullptr;  // NOLINT
81

82

83
ScriptFactorySingleton& ScriptFactorySingleton::Instance()
84
{
85
    if (!_pcSingleton) {
86
        _pcSingleton = new ScriptFactorySingleton;
87
    }
88
    return *_pcSingleton;
89
}
90

91
void ScriptFactorySingleton::Destruct()
92
{
93
    delete _pcSingleton;
94
    _pcSingleton = nullptr;
95
}
96

97
const char* ScriptFactorySingleton::ProduceScript(const char* sScriptName) const
98
{
99
    const char* script = static_cast<const char*>(Produce(sScriptName));
100

101
    if (!script) {
102
#ifdef FC_DEBUG
103
        Console().Warning("\"%s\" is not registered\n", sScriptName);
104
#endif
105
        return "";  // no data
106
    }
107

108
    return script;
109
}
110

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.