satellite-output-fstream-string-container.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 #include "ns3/simulator.h"
26 
27 NS_LOG_COMPONENT_DEFINE("SatOutputFileStreamStringContainer");
28 
29 namespace ns3
30 {
31 
32 TypeId
34 {
35  static TypeId tid = TypeId("ns3::SatOutputFileStreamStringContainer")
36  .SetParent<Object>()
37  .AddConstructor<SatOutputFileStreamStringContainer>();
38  return tid;
39 }
40 
42  std::ios::openmode filemode)
43  : m_outputFileStreamWrapper(),
44  m_outputFileStream(),
45  m_container(),
46  m_fileName(filename),
47  m_fileMode(filemode)
48 {
49  NS_LOG_FUNCTION(this << m_fileName << m_fileMode);
50 }
51 
53  : m_outputFileStreamWrapper(),
54  m_outputFileStream(),
55  m_container(),
56  m_fileName(),
57  m_fileMode()
58 {
59  NS_LOG_FUNCTION(this);
60  NS_FATAL_ERROR("SatOutputFileStreamStringContainer::SatOutputFileStreamStringContainer - "
61  "Constructor not in use");
62 }
63 
65 {
66  NS_LOG_FUNCTION(this);
67 
68  Reset();
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION(this);
75 
76  Reset();
77  Object::DoDispose();
78 }
79 
80 void
82 {
83  NS_LOG_FUNCTION(this);
84 
85  OpenStream();
86 
87  if (m_outputFileStream->is_open())
88  {
89  for (uint32_t i = 0; i < m_container.size(); i++)
90  {
91  *m_outputFileStream << m_container[i] << std::endl;
92  }
93  m_outputFileStream->close();
94  }
95  else
96  {
97  NS_ABORT_MSG("Output stream is not valid for writing.");
98  }
99 
100  Reset();
101 }
102 
103 void
105 {
106  NS_LOG_FUNCTION(this);
107 
108  m_container.push_back(newLine);
109 }
110 
111 void
113 {
114  NS_LOG_FUNCTION(this);
115 
118 }
119 
120 void
122 {
123  NS_LOG_FUNCTION(this);
124 
125  ResetStream();
126  ClearContainer();
127 }
128 
129 void
131 {
132  NS_LOG_FUNCTION(this);
133 
134  if (m_outputFileStreamWrapper != NULL)
135  {
138  }
139  m_outputFileStream = 0;
140 
141  m_fileName = "";
142  m_fileMode = std::ofstream::out;
143 }
144 
145 void
147 {
148  NS_LOG_FUNCTION(this);
149 
150  if (!m_container.empty())
151  {
152  m_container.clear();
153  }
154 }
155 
156 } // namespace ns3
void AddToContainer(std::string newLine)
Function for adding the line to container.
void OpenStream()
Function for opening the output file stream.
void WriteContainerToFile()
Function for writing the container contents to file.
std::ofstream * m_outputFileStream
Pointer to output file stream.
std::vector< std::string > m_container
Container for lines.
static TypeId GetTypeId(void)
NS-3 function for type id.
SatOutputFileStreamWrapper * m_outputFileStreamWrapper
Pointer to output file stream wrapper.
void ClearContainer()
Function for clearing the container.
A class encapsulating an STL output stream.
std::ofstream * GetStream(void)
Return a pointer to an ofstream previously set in the wrapper.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.