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

streamdrivensystem.h

Go to the documentation of this file.
00001 /*-*-c++-*-*****************************************************************
00002                           streamdrivensystem.cpp  -  description
00003                              -------------------
00004     begin                : Mon Nov 17 2003
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 
00037 #ifndef STEAM_DRIVEN_SYSTEM_HEADER
00038 #define STEAM_DRIVEN_SYSTEM_HEADER
00039 
00040 
00041 
00042 #include <queue>
00043 #include <map>
00044 #include <iosfwd>
00045 #include <iostream>
00046 #include <string>
00047 
00048 #include <simthetic/freeconnectionsystem.h>
00049 #include <simthetic/phbib.h>
00050 #include <simthetic/exceptions.h>
00051 #include <simthetic/basicsimulationsystem.h>
00052 #include <simthetic/devicesystemintf.h>
00053 #include <simthetic/connection.h>
00054 #include <simthetic/basicdevicefactory.h>
00055 #include <simthetic/devicemanager.h>
00056 #include <simthetic/parameterdescription.h>
00057 
00058 // Forward declaration; Implementation in <gwenhywfar/libloader.h>
00059 typedef struct GWEN_LIBLOADERSTRUCT GWEN_LIBLOADER;
00060 
00061 namespace simth
00062 {
00063 
00110 class StreamDrivenSystem : public FreeConnectionSystem
00111 {
00112   private:
00113     //std::string loopControlFileName;
00114     //std::string connectionFileName;
00115     //std::string deviceFileName;
00116     std::string parameterOutputFileName;
00117 
00118     // std::queue<Device*> refreshQueue;
00119     std::queue<Device*> processQueue;
00120 
00121     typedef simth::checkedVector<std::string> StringList;
00122     StringList libPaths;
00123     StringList preLoadLibs;
00124     int startDeviceNumber;
00125     bool verbose;
00126 
00127     simth::checkedVector<LoopControl*> controls;
00128     typedef std::map<int, Device*> DeviceMap;
00129     DeviceMap devices;
00130     simth::checkedVector<Connection> connections;
00131 
00132     static const std::string const_blockQualifier;
00133 
00134     /* If set to true, the current iteration is stopped */
00135     bool _isIterationStopped;
00136     /* If set to true, the complete simulation will be stopped and
00137     not just the current iteration.
00138     */
00139     bool _isStoppedPremature;
00140     /* Is set to true if the simulation finally
00141        reached its end.
00142     */
00143     bool _reachedEnd;
00144 
00149     virtual LoopControl* loopControl(const std::string& varName);
00153     virtual Device* device(int deviceNr);
00154 
00156 
00157 
00160 
00167     void nextIteration();
00168 
00172     bool reachedEnd();
00173 
00184     virtual void stopIteration();
00185 
00190     virtual void stopSimulationPremature();
00192 
00193 
00196     /* Help function to wrapp the mechanism of loading a library.
00197        Returns a handle as dlopen() does. */
00198     GWEN_LIBLOADER *loadLibrary(const std::string& path,
00199                                 const std::string& fileName) const
00200       throw (simth::file_not_found, std::runtime_error,
00201              simth::library_dependencies);
00202 
00208     DeviceFactory *createDeviceFactory(const std::string& libName) const;
00209 
00213     DeviceFactory *getDeviceFactory(const std::string &filename) const;
00214 
00217     virtual void connectDevices();
00218     
00222     DeviceFactory::FactoryMap getAllFactoryMaps() const;
00223 
00225 
00226 
00229     // Total wrapper for the version-1 process of loading a device.
00230     Device *createDeviceByFactoryV1(const std::string& datasetFileName,
00231                     int deviceNr);
00232 
00234     virtual void initLoopControls(const std::string&);
00235 
00246     virtual void readConnectionTable(const std::string&);
00248     void readConnectionTablev1(std::ifstream*is);
00249 
00251 
00252 
00255     // Total wrapper for the version-2 process of loading a device
00256     // from a FactoryFunc.
00257     Device *createDeviceByFactoryFunc(const std::string& deviceFileName, 
00258                       int deviceNr, 
00259                       const DeviceDescription& dd, 
00260                       const DeviceFactory::FactoryFunc& factoryfunc, 
00261                       const std::string& cppname);
00262 
00263     // Retrieves the C++ type name of this device number from the
00264     // parameter file at filename.
00265     static std::string getTypeName(const std::string& filename, int deviceNr);
00266 
00268     virtual void initDevices(const std::string& deviceFileName,
00269                  const DeviceManager::DDMap& ddmap);
00270 
00277     void readConnectionTablev2(std::ifstream* is);
00278 
00280 
00281 
00284     // Total wrapper for the version-3 process of loading a device
00285     // from a FactoryFunc with ParameterDescription.
00286     Device *createDeviceByFactoryFunc(const ParameterDescription& pdescr,
00287                       int deviceNr, 
00288                       const DeviceDescription& dd, 
00289                       const DeviceFactory::FactoryFunc& factoryfunc, 
00290                       const std::string& cppname);
00291 
00293     void initDevicesV3(const ParameterDescription& pardescr,
00294                const DeviceManager::DDMap& ddmap);
00295 
00297     void readConnectionTablev3(
00298     const std::vector<ParameterDescription::Connection>& clist);
00299 
00301     void initLoopControls(const ParameterDescription& pardescr);
00302 
00303     // Retrieves the C++ type name of this device number from the
00304     // ParameterDescription
00305     static std::string getTypeName(const ParameterDescription& pdescr, 
00306                    int deviceNr);
00307 
00311     static const ParameterDescription::Devicevalues& 
00312     getDevice(const ParameterDescription& pdescr, unsigned deviceNr);
00313 
00317     static const ParameterDescription::Loopvariable& 
00318     getLoopvar(const ParameterDescription& pdescr, unsigned nr);
00319 
00321 
00322 
00323 
00324   public:
00325 
00329     StreamDrivenSystem(const std::string& fileName);
00330 
00331     virtual ~StreamDrivenSystem();
00332 
00338     virtual void connectInterface(ControlInterface* interface, const std::string& varName);
00339 
00342     virtual const Device* device(int deviceNr) const;
00343 
00356     virtual void acceptSignal(Device* dev, process_signal sig);
00357 
00364     virtual double startSimulation(int mode = 0);
00365 
00372     virtual void print(std::ostream &os) const;
00373 };
00374 
00375 
00376 }
00377 
00378 
00379 #endif

Generated on Mon Aug 15 13:54:27 2005 for simthetic by  doxygen 1.4.1