SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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>
34 #include <cstring>
35 #include <cerrno>
37 #include "OutputDevice_File.h"
38 
39 #ifdef CHECK_MEMORY_LEAKS
40 #include <foreign/nvwa/debug_new.h>
41 #endif // CHECK_MEMORY_LEAKS
42 
43 
44 // ===========================================================================
45 // method definitions
46 // ===========================================================================
47 OutputDevice_File::OutputDevice_File(const std::string& fullName, const bool binary)
48  : OutputDevice(binary), myFileStream(0) {
49 #ifdef WIN32
50  if (fullName == "/dev/null") {
51  myFileStream = new std::ofstream("NUL");
52 #else
53  if (fullName == "nul" || fullName == "NUL") {
54  myFileStream = new std::ofstream("/dev/null");
55 #endif
56  } else {
57  myFileStream = new std::ofstream(fullName.c_str(), binary ? std::ios::binary : std::ios_base::out);
58  }
59  if (!myFileStream->good()) {
60  delete myFileStream;
61  throw IOError("Could not build output file '" + fullName + "' (" + std::strerror(errno) + ").");
62  }
63 }
64 
65 
67  myFileStream->close();
68  delete myFileStream;
69 }
70 
71 
72 std::ostream&
74  return *myFileStream;
75 }
76 
77 
78 /****************************************************************************/
79 
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