satellite-output-fstream-wrapper.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Frans Laakso <frans.laakso@magister.fi>
19  */
20 
22 
23 #include "ns3/abort.h"
24 #include "ns3/fatal-impl.h"
25 #include "ns3/log.h"
26 
27 #include <fstream>
28 
29 NS_LOG_COMPONENT_DEFINE("SatOutputFileStreamWrapper");
30 
31 namespace ns3
32 {
33 
35  std::ios::openmode filemode)
36  : m_destroyable(true)
37 {
38  NS_LOG_FUNCTION(this << filename << filemode);
39 
40  m_ofstream = new std::ofstream(filename.c_str(), filemode);
41 
42  NS_ABORT_MSG_UNLESS(m_ofstream->is_open(),
43  "SatOutputFileStreamWrapper::SatOutputFileStreamWrapper(): "
44  << "Unable to Open " << filename << " for mode " << filemode);
45 
46  FatalImpl::RegisterStream(m_ofstream);
47 }
48 
50 {
51  NS_LOG_FUNCTION(this);
52 
53  FatalImpl::UnregisterStream(m_ofstream);
54 
55  if (m_destroyable)
56  {
57  delete m_ofstream;
58  m_ofstream = 0;
59  }
60  m_destroyable = false;
61 }
62 
63 std::ofstream*
65 {
66  NS_LOG_FUNCTION(this);
67 
68  return m_ofstream;
69 }
70 
71 } // namespace ns3
SatOutputFileStreamWrapper(std::string filename, std::ios::openmode filemode)
Constructor.
std::ofstream * GetStream(void)
Return a pointer to an ofstream previously set in the wrapper.
bool m_destroyable
Is the stream destroyable.
std::ofstream * m_ofstream
Output file stream.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.