A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
file-aggregator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2011 Bucknell University
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 * Author: L. Felipe Perrone (perrone@bucknell.edu)
18 *
19 * Modified by: Mitch Watrous (watrous@u.washington.edu)
20 *
21 */
22
23#ifndef FILE_AGGREGATOR_H
24#define FILE_AGGREGATOR_H
25
27
28#include <fstream>
29#include <map>
30#include <string>
31
32namespace ns3
33{
34
35/**
36 * \ingroup aggregator
37 *
38 * This aggregator sends values it receives to a file.
39 **/
41{
42 public:
43 /// The type of file written by the aggregator.
45 {
50 };
51
52 /**
53 * \brief Get the type ID.
54 * \return the object TypeId
55 */
56 static TypeId GetTypeId();
57
58 /**
59 * \param outputFileName name of the file to write.
60 * \param fileType type of file to write.
61 *
62 * Constructs a file aggregator that will create a file named
63 * outputFileName with values printed as specified by fileType. The
64 * default file type is space-separated.
65 */
66 FileAggregator(const std::string& outputFileName, FileType fileType = SPACE_SEPARATED);
67
68 ~FileAggregator() override;
69
70 /**
71 * \param fileType file type specifies the separator to use in
72 * printing the file.
73 *
74 * \brief Set the file type to create, which determines the
75 * separator to use when printing values to the file.
76 */
77 void SetFileType(FileType fileType);
78
79 /**
80 * \param heading the heading string.
81 *
82 * \brief Sets the heading string that will be printed on the first
83 * line of the file.
84 *
85 * Note that the heading string will only be printed if it has been
86 * set by calling this function.
87 */
88 void SetHeading(const std::string& heading);
89
90 /**
91 * \param format the 1D format string.
92 *
93 * \brief Sets the 1D format string for the C-style sprintf()
94 * function.
95 */
96 void Set1dFormat(const std::string& format);
97
98 /**
99 * \param format the 2D format string.
100 *
101 * \brief Sets the 2D format string for the C-style sprintf()
102 * function.
103 */
104 void Set2dFormat(const std::string& format);
105
106 /**
107 * \param format the 3D format string.
108 *
109 * \brief Sets the 3D format string for the C-style sprintf()
110 * function.
111 */
112 void Set3dFormat(const std::string& format);
113
114 /**
115 * \param format the 4D format string.
116 *
117 * \brief Sets the 4D format string for the C-style sprintf()
118 * function.
119 */
120 void Set4dFormat(const std::string& format);
121
122 /**
123 * \param format the 5D format string.
124 *
125 * \brief Sets the 5D format string for the C-style sprintf()
126 * function.
127 */
128 void Set5dFormat(const std::string& format);
129
130 /**
131 * \param format the 6D format string.
132 *
133 * \brief Sets the 6D format string for the C-style sprintf()
134 * function.
135 */
136 void Set6dFormat(const std::string& format);
137
138 /**
139 * \param format the 7D format string.
140 *
141 * \brief Sets the 7D format string for the C-style sprintf()
142 * function.
143 */
144 void Set7dFormat(const std::string& format);
145
146 /**
147 * \param format the 8D format string.
148 *
149 * \brief Sets the 8D format string for the C-style sprintf()
150 * function.
151 */
152 void Set8dFormat(const std::string& format);
153
154 /**
155 * \param format the 9D format string.
156 *
157 * \brief Sets the 9D format string for the C-style sprintf()
158 * function.
159 */
160 void Set9dFormat(const std::string& format);
161
162 /**
163 * \param format the 10D format string.
164 *
165 * \brief Sets the 10D format string for the C-style sprintf()
166 * function.
167 */
168 void Set10dFormat(const std::string& format);
169
170 // Below are hooked to connectors exporting data
171 // They are not overloaded since it confuses the compiler when made
172 // into callbacks
173
174 /**
175 * \param context specifies the 1D dataset these values came from.
176 * \param v1 value for the new data point.
177 *
178 * \brief Writes 1 value to the file.
179 */
180 void Write1d(std::string context, double v1);
181
182 /**
183 * \param context specifies the 2D dataset these values came from.
184 * \param v1 first value for the new data point.
185 * \param v2 second value for the new data point.
186 *
187 * \brief Writes 2 values to the file.
188 */
189 void Write2d(std::string context, double v1, double v2);
190
191 /**
192 * \param context specifies the 3D dataset these values came from.
193 * \param v1 first value for the new data point.
194 * \param v2 second value for the new data point.
195 * \param v3 third value for the new data point.
196 *
197 * \brief Writes 3 values to the file.
198 */
199 void Write3d(std::string context, double v1, double v2, double v3);
200
201 /**
202 * \param context specifies the 4D dataset these values came from.
203 * \param v1 first value for the new data point.
204 * \param v2 second value for the new data point.
205 * \param v3 third value for the new data point.
206 * \param v4 fourth value for the new data point.
207 *
208 * \brief Writes 4 values to the file.
209 */
210 void Write4d(std::string context, double v1, double v2, double v3, double v4);
211
212 /**
213 * \param context specifies the 5D dataset these values came from.
214 * \param v1 first value for the new data point.
215 * \param v2 second value for the new data point.
216 * \param v3 third value for the new data point.
217 * \param v4 fourth value for the new data point.
218 * \param v5 fifth value for the new data point.
219 *
220 * \brief Writes 5 values to the file.
221 */
222 void Write5d(std::string context, double v1, double v2, double v3, double v4, double v5);
223
224 /**
225 * \param context specifies the 6D dataset these values came from.
226 * \param v1 first value for the new data point.
227 * \param v2 second value for the new data point.
228 * \param v3 third value for the new data point.
229 * \param v4 fourth value for the new data point.
230 * \param v5 fifth value for the new data point.
231 * \param v6 sixth value for the new data point.
232 *
233 * \brief Writes 6 values to the file.
234 */
235 void Write6d(std::string context,
236 double v1,
237 double v2,
238 double v3,
239 double v4,
240 double v5,
241 double v6);
242
243 /**
244 * \param context specifies the 7D dataset these values came from.
245 * \param v1 first value for the new data point.
246 * \param v2 second value for the new data point.
247 * \param v3 third value for the new data point.
248 * \param v4 fourth value for the new data point.
249 * \param v5 fifth value for the new data point.
250 * \param v6 sixth value for the new data point.
251 * \param v7 seventh value for the new data point.
252 *
253 * \brief Writes 7 values to the file.
254 */
255 void Write7d(std::string context,
256 double v1,
257 double v2,
258 double v3,
259 double v4,
260 double v5,
261 double v6,
262 double v7);
263
264 /**
265 * \param context specifies the 8D dataset these values came from.
266 * \param v1 first value for the new data point.
267 * \param v2 second value for the new data point.
268 * \param v3 third value for the new data point.
269 * \param v4 fourth value for the new data point.
270 * \param v5 fifth value for the new data point.
271 * \param v6 sixth value for the new data point.
272 * \param v7 seventh value for the new data point.
273 * \param v8 eighth value for the new data point.
274 *
275 * \brief Writes 8 values to the file.
276 */
277 void Write8d(std::string context,
278 double v1,
279 double v2,
280 double v3,
281 double v4,
282 double v5,
283 double v6,
284 double v7,
285 double v8);
286
287 /**
288 * \param context specifies the 9D dataset these values came from.
289 * \param v1 first value for the new data point.
290 * \param v2 second value for the new data point.
291 * \param v3 third value for the new data point.
292 * \param v4 fourth value for the new data point.
293 * \param v5 fifth value for the new data point.
294 * \param v6 sixth value for the new data point.
295 * \param v7 seventh value for the new data point.
296 * \param v8 eighth value for the new data point.
297 * \param v9 ninth value for the new data point.
298 *
299 * \brief Writes 9 values to the file.
300 */
301 void Write9d(std::string context,
302 double v1,
303 double v2,
304 double v3,
305 double v4,
306 double v5,
307 double v6,
308 double v7,
309 double v8,
310 double v9);
311
312 /**
313 * \param context specifies the 10D dataset these values came from.
314 * \param v1 first value for the new data point.
315 * \param v2 second value for the new data point.
316 * \param v3 third value for the new data point.
317 * \param v4 fourth value for the new data point.
318 * \param v5 fifth value for the new data point.
319 * \param v6 sixth value for the new data point.
320 * \param v7 seventh value for the new data point.
321 * \param v8 eighth value for the new data point.
322 * \param v9 ninth value for the new data point.
323 * \param v10 tenth value for the new data point.
324 *
325 * \brief Writes 10 values to the file.
326 */
327 void Write10d(std::string context,
328 double v1,
329 double v2,
330 double v3,
331 double v4,
332 double v5,
333 double v6,
334 double v7,
335 double v8,
336 double v9,
337 double v10);
338
339 private:
340 /// The file name.
341 std::string m_outputFileName;
342
343 /// Used to write values to the file.
344 std::ofstream m_file;
345
346 /// Determines the kind of file written by the aggregator.
348
349 /// Printed between values in the file.
350 std::string m_separator;
351
352 /// Indicates if the heading line for the file has been set.
354
355 /// Heading line for the outputfile.
356 std::string m_heading;
357
358 std::string m_1dFormat; //!< Format string for 1D C-style sprintf() function.
359 std::string m_2dFormat; //!< Format string for 2D C-style sprintf() function.
360 std::string m_3dFormat; //!< Format string for 3D C-style sprintf() function.
361 std::string m_4dFormat; //!< Format string for 4D C-style sprintf() function.
362 std::string m_5dFormat; //!< Format string for 5D C-style sprintf() function.
363 std::string m_6dFormat; //!< Format string for 6D C-style sprintf() function.
364 std::string m_7dFormat; //!< Format string for 7D C-style sprintf() function.
365 std::string m_8dFormat; //!< Format string for 8D C-style sprintf() function.
366 std::string m_9dFormat; //!< Format string for 9D C-style sprintf() function.
367 std::string m_10dFormat; //!< Format string for 10D C-style sprintf() function.
368
369}; // class FileAggregator
370
371} // namespace ns3
372
373#endif // FILE_AGGREGATOR_H
Base class for data collection framework objects.
This aggregator sends values it receives to a file.
~FileAggregator() override
void Set4dFormat(const std::string &format)
Sets the 4D format string for the C-style sprintf() function.
void Write7d(std::string context, double v1, double v2, double v3, double v4, double v5, double v6, double v7)
Writes 7 values to the file.
void Write3d(std::string context, double v1, double v2, double v3)
Writes 3 values to the file.
std::string m_separator
Printed between values in the file.
void Set6dFormat(const std::string &format)
Sets the 6D format string for the C-style sprintf() function.
std::string m_5dFormat
Format string for 5D C-style sprintf() function.
FileType m_fileType
Determines the kind of file written by the aggregator.
std::string m_4dFormat
Format string for 4D C-style sprintf() function.
void Set8dFormat(const std::string &format)
Sets the 8D format string for the C-style sprintf() function.
void Write1d(std::string context, double v1)
Writes 1 value to the file.
void Set7dFormat(const std::string &format)
Sets the 7D format string for the C-style sprintf() function.
void Write9d(std::string context, double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8, double v9)
Writes 9 values to the file.
void Write4d(std::string context, double v1, double v2, double v3, double v4)
Writes 4 values to the file.
void Set2dFormat(const std::string &format)
Sets the 2D format string for the C-style sprintf() function.
void SetFileType(FileType fileType)
Set the file type to create, which determines the separator to use when printing values to the file.
void Set9dFormat(const std::string &format)
Sets the 9D format string for the C-style sprintf() function.
std::string m_10dFormat
Format string for 10D C-style sprintf() function.
std::ofstream m_file
Used to write values to the file.
void Write2d(std::string context, double v1, double v2)
Writes 2 values to the file.
std::string m_9dFormat
Format string for 9D C-style sprintf() function.
void Write5d(std::string context, double v1, double v2, double v3, double v4, double v5)
Writes 5 values to the file.
void Set3dFormat(const std::string &format)
Sets the 3D format string for the C-style sprintf() function.
void Set1dFormat(const std::string &format)
Sets the 1D format string for the C-style sprintf() function.
bool m_hasHeadingBeenSet
Indicates if the heading line for the file has been set.
std::string m_7dFormat
Format string for 7D C-style sprintf() function.
std::string m_heading
Heading line for the outputfile.
void Set10dFormat(const std::string &format)
Sets the 10D format string for the C-style sprintf() function.
void Write6d(std::string context, double v1, double v2, double v3, double v4, double v5, double v6)
Writes 6 values to the file.
void Set5dFormat(const std::string &format)
Sets the 5D format string for the C-style sprintf() function.
std::string m_3dFormat
Format string for 3D C-style sprintf() function.
void SetHeading(const std::string &heading)
Sets the heading string that will be printed on the first line of the file.
std::string m_1dFormat
Format string for 1D C-style sprintf() function.
std::string m_outputFileName
The file name.
std::string m_6dFormat
Format string for 6D C-style sprintf() function.
std::string m_8dFormat
Format string for 8D C-style sprintf() function.
void Write8d(std::string context, double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8)
Writes 8 values to the file.
FileType
The type of file written by the aggregator.
std::string m_2dFormat
Format string for 2D C-style sprintf() function.
void Write10d(std::string context, double v1, double v2, double v3, double v4, double v5, double v6, double v7, double v8, double v9, double v10)
Writes 10 values to the file.
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.