Factory.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   (c) Jürgen Riegel (juergen.riegel@web.de) 2002                        *   
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of the GNU Library General Public License (LGPL)   *
00008  *   as published by the Free Software Foundation; either version 2 of     *
00009  *   the License, or (at your option) any later version.                   *
00010  *   for detail see the LICENCE text file.                                 *
00011  *                                                                         *
00012  *   FreeCAD is distributed in the hope that it will be useful,            *
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        * 
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00015  *   GNU Library General Public License for more details.                  *
00016  *                                                                         *
00017  *   You should have received a copy of the GNU Library General Public     *
00018  *   License along with FreeCAD; if not, write to the Free Software        * 
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  *
00020  *   USA                                                                   *
00021  *                                                                         *
00022  *   Juergen Riegel 2002                                                   *
00023  ***************************************************************************/
00024 
00025 
00026 #include "PreCompiled.h"
00027 
00028 #ifndef _PreComp_
00029 #       include <list>
00030 #endif
00031 
00032 
00033 #include "Factory.h"
00034 #include "Console.h"
00035 
00036 using namespace Base;
00037 
00038 
00039 Factory::~Factory ()
00040 {
00041   for (std::map<const std::string, AbstractProducer*>::iterator pI = _mpcProducers.begin(); pI != _mpcProducers.end(); pI++)
00042     delete pI->second;
00043 }
00044 
00045 void* Factory::Produce (const char *sClassName) const
00046 {
00047   std::map<const std::string, AbstractProducer*>::const_iterator pProd;
00048 
00049   pProd = _mpcProducers.find(sClassName);
00050   if (pProd != _mpcProducers.end())
00051     return pProd->second->Produce();
00052   else
00053     return NULL;
00054 }
00055 
00056 void Factory::AddProducer (const char *sClassName, AbstractProducer *pcProducer)
00057 {
00058   _mpcProducers[sClassName] = pcProducer;
00059 }
00060 
00061 bool Factory::CanProduce(const char* sClassName) const
00062 {
00063   return (_mpcProducers.find(sClassName) != _mpcProducers.end());
00064 }
00065 
00066 std::list<std::string> Factory::CanProduce() const
00067 {
00068   std::list<std::string> lObjects;
00069 
00070   for (std::map<const std::string, AbstractProducer*>::const_iterator pI = _mpcProducers.begin(); pI != _mpcProducers.end(); pI++)
00071   {
00072     lObjects.push_back(pI->first);
00073   }
00074 
00075   return lObjects;
00076 }
00077 
00078 // ----------------------------------------------------
00079 
00080 ScriptFactorySingleton* ScriptFactorySingleton::_pcSingleton = NULL;
00081 
00082 
00083 
00084 ScriptFactorySingleton& ScriptFactorySingleton::Instance(void)
00085 {
00086   if (_pcSingleton == NULL)
00087     _pcSingleton = new ScriptFactorySingleton;
00088   return *_pcSingleton;
00089 }
00090 
00091 void ScriptFactorySingleton::Destruct (void)
00092 {
00093   if (_pcSingleton != 0)
00094     delete _pcSingleton;
00095   _pcSingleton = 0;
00096 }
00097 
00098 const char* ScriptFactorySingleton::ProduceScript (const char* sScriptName) const
00099 {
00100   const char* script = (const char*)Produce(sScriptName);
00101 
00102   if ( !script )
00103   {
00104 #ifdef FC_DEBUG
00105     Console().Warning("\"%s\" is not registered\n", sScriptName);
00106 #endif
00107     return ""; // no data
00108   }
00109 
00110   return script;
00111 }

Generated on Wed Nov 23 19:00:11 2011 for FreeCAD by  doxygen 1.6.1