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