OutputDevice.h

Go to the documentation of this file.
00001 /****************************************************************************/
00007 // Static storage of an output device and its base (abstract) implementation
00008 /****************************************************************************/
00009 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00010 // Copyright 2001-2010 DLR (http://www.dlr.de/) and contributors
00011 /****************************************************************************/
00012 //
00013 //   This program is free software; you can redistribute it and/or modify
00014 //   it under the terms of the GNU General Public License as published by
00015 //   the Free Software Foundation; either version 2 of the License, or
00016 //   (at your option) any later version.
00017 //
00018 /****************************************************************************/
00019 #ifndef OutputDevice_h
00020 #define OutputDevice_h
00021 
00022 
00023 // ===========================================================================
00024 // included modules
00025 // ===========================================================================
00026 #ifdef _MSC_VER
00027 #include <windows_config.h>
00028 #else
00029 #include <config.h>
00030 #endif
00031 
00032 #include <string>
00033 #include <vector>
00034 #include <map>
00035 #include <utils/common/UtilExceptions.h>
00036 
00037 
00038 // ===========================================================================
00039 // class definitions
00040 // ===========================================================================
00065 class OutputDevice {
00066 public:
00069 
00082     static OutputDevice& getDevice(const std::string &name,
00083                                    const std::string &base="") throw(IOError);
00084 
00085 
00102     static bool createDeviceByOption(const std::string &optionName,
00103                                      const std::string &rootElement="") throw(IOError);
00104 
00105 
00118     static OutputDevice& getDeviceByOption(const std::string &name) throw(IOError, InvalidArgument);
00119 
00120 
00123     static void closeAll() throw();
00125 
00126 
00127 
00128 public:
00131 
00133     OutputDevice() throw(IOError) { }
00134 
00135 
00137     virtual ~OutputDevice() throw() { }
00138 
00139 
00143     virtual bool ok() throw();
00144 
00145 
00148     void close() throw();
00149 
00150 
00154     void setPrecision(unsigned int precision=OUTPUT_ACCURACY) throw();
00155 
00156 
00169     bool writeXMLHeader(const std::string &rootElement,
00170                         const bool writeConfig=true,
00171                         const std::string &attrs="",
00172                         const std::string &comment="") throw();
00173 
00174 
00181     OutputDevice& indent() throw();
00182 
00183 
00193     OutputDevice& openTag(const std::string &xmlElement) throw();
00194 
00195 
00206     bool closeTag(bool abbreviated=false) throw();
00207 
00208 
00215     void inform(const std::string &msg);
00216 
00217 
00221     template <class T>
00222     OutputDevice &operator<<(const T &t) {
00223         getOStream() << t;
00224         postWriteHook();
00225         return *this;
00226     }
00227 
00228 protected:
00230     virtual std::ostream &getOStream() throw() = 0;
00231 
00232 
00237     virtual void postWriteHook() throw();
00238 
00239 
00240 private:
00243 
00245     typedef std::map<std::string, OutputDevice*> DeviceMap;
00246 
00248     static DeviceMap myOutputDevices;
00250 
00251 
00252 private:
00255 
00257     std::vector<std::string> myXMLStack;
00259 
00260 };
00261 
00262 
00263 #endif
00264 
00265 /****************************************************************************/
00266 

Generated on Wed May 5 00:06:35 2010 for Sumo - Simulation of Urban MObility by  doxygen 1.5.6