Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

basicdevicefactory.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           basicdevicefactory.h  -  description
00003                              -------------------
00004     begin                : Tue May 14 2002
00005     copyright            : (C) 2002 by Peter Haase
00006     email                : mail@p-haase.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This library is free software; you can redistribute it and/or         *
00012  *   modify it under the terms of the GNU Lesser General Public            *
00013  *   License as published by the Free Software Foundation; either          *
00014  *   version 2.1 of the License, or (at your option) any later version.    *
00015  *                                                                         *
00016  *   This library is distributed in the hope that it will be useful,       *
00017  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00018  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
00019  *   Lesser General Public License for more details.                       *
00020  *                                                                         *
00021  *   You should have received a copy of the GNU Lesser General Public      *
00022  *   License along with this library; if not, write to the Free Software   *
00023  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston,                 *
00024  *   MA  02111-1307  USA                                                   *
00025  *                                                                         *
00026  ***************************************************************************/
00027 
00028 #ifndef BASIC_DEVICE_FACTORY_HEADER
00029 #define BASIC_DEVICE_FACTORY_HEADER
00030 
00031 #include <string>
00032 #include <iosfwd>
00033 #include <map>
00034 #include <simthetic/propertylist.h>
00035 
00036 namespace simth
00037 {
00038 
00056 class Device;
00057 class DeviceSystemIntf;
00058 
00063 class DeviceFactory
00064 {
00065   public:
00067     DeviceFactory();
00069     virtual ~DeviceFactory() = 0;
00070 
00093     virtual Device* createDevice(const std::string& fileName, 
00094                  DeviceSystemIntf* sysPtr,
00095                                  int ID, 
00096                  const std::string blockQualifier = "") = 0;
00098 
00099     // The following are all quite new (Feb 2004)
00100 
00117     typedef simth::Device *(*FactoryFunc)(int id, 
00118                       simth::DeviceSystemIntf* sysPtr,
00119                       const simth::PropertyList& pl, 
00120                       const std::string& cpptype);
00121 
00124     typedef std::map<std::string, FactoryFunc> FactoryMap;
00125 
00155     virtual FactoryMap allDevices();
00156 
00171     void addFunction(const std::string& cppname, FactoryFunc func);
00173 
00174   private:
00175     // Data store for ethe support mechanism for easy registering of
00176     // factory functions.
00177     FactoryMap _fm;
00178 };
00179 
00184 template<class T>
00185 static simth::Device* factory_function(int ID, 
00186                        simth::DeviceSystemIntf* sysPtr,
00187                        const simth::PropertyList& pl, 
00188                        const std::string& /*cpptype*/)
00189 {
00190    return new T(ID, sysPtr, pl);
00191 }
00192 
00194  std::ostream& operator<<(std::ostream&os, 
00195               const DeviceFactory::FactoryMap& fm);
00196 
00197 } // namespace
00198 
00199 #endif // BASIC_DEVICE_FACTORY_HEADER

Generated on Mon Apr 24 21:19:19 2006 for simthetic by  doxygen 1.4.1