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 namespace simth
00059 {
00060 
00108 class StreamDrivenSystem : public FreeConnectionSystem
00109 {
00110   private:
00111     //std::string loopControlFileName;
00112     //std::string connectionFileName;
00113     //std::string deviceFileName;
00114     std::string parameterOutputFileName;
00115 
00116     // std::queue<Device*> refreshQueue;
00117     std::queue<Device*> processQueue;
00118 
00119     typedef simth::checkedVector<std::string> StringList;
00120     StringList libPaths;
00121     StringList preLoadLibs;
00122     int startDeviceNumber;
00123     bool verbose;
00124 
00125     simth::checkedVector<LoopControl*> controls;
00126     typedef std::map<int, Device*> DeviceMap;
00127     DeviceMap devices;
00128     simth::checkedVector<Connection> connections;
00129 
00130     static const std::string const_blockQualifier;
00131 
00132     /* If set to true, the current iteration is stopped */
00133     bool _isIterationStopped;
00134     /* If set to true, the complete simulation will be stopped and
00135     not just the current iteration.
00136     */
00137     bool _isStoppedPremature;
00138     /* Is set to true if the simulation finally
00139        reached its end.
00140     */
00141     bool _reachedEnd;
00142 
00147     virtual LoopControl* loopControl(const std::string& varName);
00151     virtual Device* device(int deviceNr);
00152 
00154 
00155 
00158 
00165     void nextIteration();
00166 
00170     bool reachedEnd();
00172 
00173 
00181     DeviceFactory *createDeviceFactory(const std::string& libName) const;
00182 
00186     DeviceFactory *getDeviceFactory(const std::string &filename) const;
00187 
00190     virtual void connectDevices();
00191     
00195     DeviceFactory::FactoryMap getAllFactoryMaps() const;
00196 
00198 
00199 
00202     // Total wrapper for the version-1 process of loading a device.
00203     Device *createDeviceByFactoryV1(const std::string& datasetFileName,
00204                     int deviceNr);
00205 
00207     virtual void initLoopControls(const std::string&);
00208 
00219     virtual void readConnectionTable(const std::string&);
00221     void readConnectionTablev1(std::ifstream*is);
00222 
00224 
00225 
00228     // Total wrapper for the version-2 process of loading a device
00229     // from a FactoryFunc.
00230     Device *createDeviceByFactoryFunc(const std::string& deviceFileName, 
00231                       int deviceNr, 
00232                       const DeviceDescription& dd, 
00233                       const DeviceFactory::FactoryFunc& factoryfunc, 
00234                       const std::string& cppname);
00235 
00236     // Retrieves the C++ type name of this device number from the
00237     // parameter file at filename.
00238     static std::string getTypeName(const std::string& filename, int deviceNr);
00239 
00241     virtual void initDevices(const std::string& deviceFileName,
00242                  const DeviceManager::DDMap& ddmap);
00243 
00250     void readConnectionTablev2(std::ifstream* is);
00251 
00253 
00254 
00257     // Total wrapper for the version-3 process of loading a device
00258     // from a FactoryFunc with ParameterDescription.
00259     Device *createDeviceByFactoryFunc(const ParameterDescription& pdescr,
00260                       int deviceNr, 
00261                       const DeviceDescription& dd, 
00262                       const DeviceFactory::FactoryFunc& factoryfunc, 
00263                       const std::string& cppname);
00264 
00266     void initDevicesV3(const ParameterDescription& pardescr,
00267                const DeviceManager::DDMap& ddmap);
00268 
00270     void readConnectionTablev3(
00271     const std::vector<ParameterDescription::Connection>& clist);
00272 
00274     void initLoopControls(const ParameterDescription& pardescr);
00275 
00276     // Retrieves the C++ type name of this device number from the
00277     // ParameterDescription
00278     static std::string getTypeName(const ParameterDescription& pdescr, 
00279                    int deviceNr);
00280 
00284     static const ParameterDescription::Devicevalues& 
00285     getDevice(const ParameterDescription& pdescr, unsigned deviceNr);
00286 
00290     static const ParameterDescription::Loopvariable& 
00291     getLoopvar(const ParameterDescription& pdescr, unsigned nr);
00292 
00294 
00295 
00296 
00297   public:
00298 
00302     StreamDrivenSystem(const std::string& fileName);
00303 
00304     virtual ~StreamDrivenSystem();
00305 
00311     virtual void connectInterface(ControlInterface* interface, const std::string& varName);
00312 
00315     virtual const Device* device(int deviceNr) const;
00316 
00326     virtual double mainSimulationLoop(int mode = 0);
00327 
00345     virtual void queueForProcess(Device *dev);
00346 
00357     virtual void stopIteration();
00358 
00363     virtual void stopSimulationPremature();
00365 
00372     virtual void print(std::ostream &os) const;
00373 };
00374 
00375 
00376 }
00377 
00378 
00379 #endif

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