A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
output-stream-wrapper.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2010 University of Washington
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
8
9#include "ns3/abort.h"
10#include "ns3/fatal-impl.h"
11#include "ns3/log.h"
12
13#include <fstream>
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("OutputStreamWrapper");
19
20OutputStreamWrapper::OutputStreamWrapper(std::string filename, std::ios::openmode filemode)
21 : m_destroyable(true)
22{
23 NS_LOG_FUNCTION(this << filename << filemode);
24 auto os = new std::ofstream();
25 os->open(filename, filemode);
26 m_ostream = os;
28 NS_ABORT_MSG_UNLESS(os->is_open(),
29 "AsciiTraceHelper::CreateFileStream(): "
30 << "Unable to Open " << filename << " for mode " << filemode);
31}
32
34 : m_ostream(os),
35 m_destroyable(false)
36{
37 NS_LOG_FUNCTION(this << os);
39 NS_ABORT_MSG_UNLESS(m_ostream->good(), "Output stream is not valid for writing.");
40}
41
52
53std::ostream*
59
60} // namespace ns3
OutputStreamWrapper(std::string filename, std::ios::openmode filemode)
Constructor.
std::ostream * GetStream()
Return a pointer to an ostream previously set in the wrapper.
bool m_destroyable
Can be destroyed.
std::ostream * m_ostream
The output stream.
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition abort.h:133
void UnregisterStream(std::ostream *stream)
Unregister a stream for flushing on abnormal exit.
void RegisterStream(std::ostream *stream)
Register a stream to be flushed on abnormal exit.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.