satellite-input-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/log.h"
25 
26 #include <fstream>
27 
28 NS_LOG_COMPONENT_DEFINE("SatInputFileStreamWrapper");
29 
30 namespace ns3
31 {
32 
34  std::ios::openmode filemode)
35  : m_destroyable(true)
36 {
37  NS_LOG_FUNCTION(this << filename << filemode);
38 
39  std::ifstream* ifs = new std::ifstream(filename.c_str(), filemode);
40 
41  NS_ABORT_MSG_UNLESS(ifs->is_open(),
42  "SatInputFileStreamWrapper::SatInputFileStreamWrapper(): "
43  << "Unable to Open " << filename << " for mode " << filemode);
44 
45  m_ifstream = ifs;
46 }
47 
49 {
50  NS_LOG_FUNCTION(this);
51 
52  if (m_destroyable)
53  {
54  delete m_ifstream;
55  m_ifstream = 0;
56  }
57  m_destroyable = false;
58 }
59 
60 std::ifstream*
62 {
63  NS_LOG_FUNCTION(this);
64 
65  return m_ifstream;
66 }
67 
68 } // namespace ns3
std::ifstream * GetStream(void)
Return a pointer to an ifstream previously set in the wrapper.
SatInputFileStreamWrapper(std::string filename, std::ios::openmode filemode)
Constructor.
std::ifstream * m_ifstream
Input file stream.
bool m_destroyable
Is the stream destroyable.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.