A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Documentation ▼
Installation
Manual
Models
Contributing
Wiki
Development ▼
API Docs
Issue Tracker
Merge Requests
API
output-stream-wrapper.cc
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2010 University of Washington
3
*
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License version 2 as
6
* published by the Free Software Foundation;
7
*
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
12
*
13
* You should have received a copy of the GNU General Public License
14
* along with this program; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16
*/
17
18
#include "
output-stream-wrapper.h
"
19
20
#include "ns3/abort.h"
21
#include "ns3/fatal-impl.h"
22
#include "ns3/log.h"
23
24
#include <fstream>
25
26
namespace
ns3
27
{
28
29
NS_LOG_COMPONENT_DEFINE
(
"OutputStreamWrapper"
);
30
31
OutputStreamWrapper::OutputStreamWrapper
(std::string filename, std::ios::openmode filemode)
32
: m_destroyable(true)
33
{
34
NS_LOG_FUNCTION
(
this
<< filename << filemode);
35
auto
os =
new
std::ofstream();
36
os->open(filename, filemode);
37
m_ostream
= os;
38
FatalImpl::RegisterStream
(
m_ostream
);
39
NS_ABORT_MSG_UNLESS
(os->is_open(),
40
"AsciiTraceHelper::CreateFileStream(): "
41
<<
"Unable to Open "
<< filename <<
" for mode "
<< filemode);
42
}
43
44
OutputStreamWrapper::OutputStreamWrapper
(std::ostream* os)
45
: m_ostream(os),
46
m_destroyable(false)
47
{
48
NS_LOG_FUNCTION
(
this
<< os);
49
FatalImpl::RegisterStream
(
m_ostream
);
50
NS_ABORT_MSG_UNLESS
(
m_ostream
->good(),
"Output stream is not valid for writing."
);
51
}
52
53
OutputStreamWrapper::~OutputStreamWrapper
()
54
{
55
NS_LOG_FUNCTION
(
this
);
56
FatalImpl::UnregisterStream
(
m_ostream
);
57
if
(
m_destroyable
)
58
{
59
delete
m_ostream
;
60
}
61
m_ostream
=
nullptr
;
62
}
63
64
std::ostream*
65
OutputStreamWrapper::GetStream
()
66
{
67
NS_LOG_FUNCTION
(
this
);
68
return
m_ostream
;
69
}
70
71
}
// namespace ns3
ns3::OutputStreamWrapper::~OutputStreamWrapper
~OutputStreamWrapper()
Definition:
output-stream-wrapper.cc:53
ns3::OutputStreamWrapper::OutputStreamWrapper
OutputStreamWrapper(std::string filename, std::ios::openmode filemode)
Constructor.
Definition:
output-stream-wrapper.cc:31
ns3::OutputStreamWrapper::GetStream
std::ostream * GetStream()
Return a pointer to an ostream previously set in the wrapper.
Definition:
output-stream-wrapper.cc:65
ns3::OutputStreamWrapper::m_destroyable
bool m_destroyable
Can be destroyed.
Definition:
output-stream-wrapper.h:98
ns3::OutputStreamWrapper::m_ostream
std::ostream * m_ostream
The output stream.
Definition:
output-stream-wrapper.h:97
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:144
ns3::FatalImpl::UnregisterStream
void UnregisterStream(std::ostream *stream)
Unregister a stream for flushing on abnormal exit.
Definition:
fatal-impl.cc:143
ns3::FatalImpl::RegisterStream
void RegisterStream(std::ostream *stream)
Register a stream to be flushed on abnormal exit.
Definition:
fatal-impl.cc:136
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
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:240
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 Sun Mar 3 2024 17:11:06 for ns-3 by
1.9.1