SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
OutputDevice_File.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // An output device that encapsulates an ofstream
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2004-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <iostream>
35 #include "OutputDevice_File.h"
36 
37 #ifdef CHECK_MEMORY_LEAKS
38 #include <foreign/nvwa/debug_new.h>
39 #endif // CHECK_MEMORY_LEAKS
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 OutputDevice_File::OutputDevice_File(const std::string& fullName, const bool binary)
46  : OutputDevice(binary), myFileStream(0) {
47 #ifdef WIN32
48  if (fullName == "/dev/null") {
49  myFileStream = new std::ofstream("NUL");
50 #else
51  if (fullName == "nul" || fullName == "NUL") {
52  myFileStream = new std::ofstream("/dev/null");
53 #endif
54  } else {
55  myFileStream = new std::ofstream(fullName.c_str(), binary ? std::ios::binary : std::ios_base::out);
56  }
57  if (!myFileStream->good()) {
58  delete myFileStream;
59  throw IOError("Could not build output file '" + fullName + "'.");
60  }
61 }
62 
63 
65  myFileStream->close();
66  delete myFileStream;
67 }
68 
69 
70 std::ostream&
72  return *myFileStream;
73 }
74 
75 
76 /****************************************************************************/
77 
std::ostream & getOStream()
Returns the associated ostream.
std::ofstream * myFileStream
The wrapped ofstream.
~OutputDevice_File()
Destructor.
OutputDevice_File(const std::string &fullName, const bool binary)
Constructor.
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:71