A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
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
7
#include "
output-stream-wrapper.h
"
8
9
#include "ns3/abort.h"
10
#include "ns3/fatal-impl.h"
11
#include "ns3/log.h"
12
13
#include <fstream>
14
15
namespace
ns3
16
{
17
18
NS_LOG_COMPONENT_DEFINE
(
"OutputStreamWrapper"
);
19
20
OutputStreamWrapper::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;
27
FatalImpl::RegisterStream
(
m_ostream
);
28
NS_ABORT_MSG_UNLESS
(os->is_open(),
29
"AsciiTraceHelper::CreateFileStream(): "
30
<<
"Unable to Open "
<< filename <<
" for mode "
<< filemode);
31
}
32
33
OutputStreamWrapper::OutputStreamWrapper
(std::ostream* os)
34
: m_ostream(os),
35
m_destroyable(false)
36
{
37
NS_LOG_FUNCTION
(
this
<< os);
38
FatalImpl::RegisterStream
(
m_ostream
);
39
NS_ABORT_MSG_UNLESS
(
m_ostream
->good(),
"Output stream is not valid for writing."
);
40
}
41
42
OutputStreamWrapper::~OutputStreamWrapper
()
43
{
44
NS_LOG_FUNCTION
(
this
);
45
FatalImpl::UnregisterStream
(
m_ostream
);
46
if
(
m_destroyable
)
47
{
48
delete
m_ostream
;
49
}
50
m_ostream
=
nullptr
;
51
}
52
53
std::ostream*
54
OutputStreamWrapper::GetStream
()
55
{
56
NS_LOG_FUNCTION
(
this
);
57
return
m_ostream
;
58
}
59
60
}
// namespace ns3
ns3::OutputStreamWrapper::~OutputStreamWrapper
~OutputStreamWrapper()
Definition
output-stream-wrapper.cc:42
ns3::OutputStreamWrapper::OutputStreamWrapper
OutputStreamWrapper(std::string filename, std::ios::openmode filemode)
Constructor.
Definition
output-stream-wrapper.cc:20
ns3::OutputStreamWrapper::GetStream
std::ostream * GetStream()
Return a pointer to an ostream previously set in the wrapper.
Definition
output-stream-wrapper.cc:54
ns3::OutputStreamWrapper::m_destroyable
bool m_destroyable
Can be destroyed.
Definition
output-stream-wrapper.h:87
ns3::OutputStreamWrapper::m_ostream
std::ostream * m_ostream
The output stream.
Definition
output-stream-wrapper.h:86
NS_ABORT_MSG_UNLESS
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if a condition is false, with a message.
Definition
abort.h:133
ns3::FatalImpl::UnregisterStream
void UnregisterStream(std::ostream *stream)
Unregister a stream for flushing on abnormal exit.
Definition
fatal-impl.cc:132
ns3::FatalImpl::RegisterStream
void RegisterStream(std::ostream *stream)
Register a stream to be flushed on abnormal exit.
Definition
fatal-impl.cc:125
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition
log.h:191
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition
log-macros-enabled.h:229
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
output-stream-wrapper.h
src
network
utils
output-stream-wrapper.cc
Generated on Fri Nov 8 2024 13:59:05 for ns-3 by
1.11.0