SUMO - Simulation of Urban MObility
|
00001 /****************************************************************************/ 00008 // An output device that encapsulates an ofstream 00009 /****************************************************************************/ 00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/ 00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors 00012 /****************************************************************************/ 00013 // 00014 // This file is part of SUMO. 00015 // SUMO is free software: you can redistribute it and/or modify 00016 // it under the terms of the GNU General Public License as published by 00017 // the Free Software Foundation, either version 3 of the License, or 00018 // (at your option) any later version. 00019 // 00020 /****************************************************************************/ 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 <iostream> 00033 #include "OutputDevice_File.h" 00034 00035 #ifdef CHECK_MEMORY_LEAKS 00036 #include <foreign/nvwa/debug_new.h> 00037 #endif // CHECK_MEMORY_LEAKS 00038 00039 00040 // =========================================================================== 00041 // method definitions 00042 // =========================================================================== 00043 OutputDevice_File::OutputDevice_File(const std::string& fullName, const bool binary) 00044 : OutputDevice(binary), myFileStream(0) { 00045 #ifdef WIN32 00046 if (fullName == "/dev/null") { 00047 myFileStream = new std::ofstream("NUL"); 00048 #else 00049 if (fullName == "nul" || fullName == "NUL") { 00050 myFileStream = new std::ofstream("/dev/null"); 00051 #endif 00052 } else { 00053 myFileStream = new std::ofstream(fullName.c_str()); 00054 } 00055 if (!myFileStream->good()) { 00056 delete myFileStream; 00057 throw IOError("Could not build output file '" + fullName + "'."); 00058 } 00059 } 00060 00061 00062 OutputDevice_File::~OutputDevice_File() { 00063 myFileStream->close(); 00064 delete myFileStream; 00065 } 00066 00067 00068 std::ostream& 00069 OutputDevice_File::getOStream() { 00070 return *myFileStream; 00071 } 00072 00073 00074 /****************************************************************************/ 00075