A Discrete-Event Network Simulator
API
file-aggregator.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2011 Bucknell University
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: L. Felipe Perrone (perrone@bucknell.edu)
19  *
20  * Modified by: Mitch Watrous (watrous@u.washington.edu)
21  *
22  */
23 
24 #ifndef FILE_AGGREGATOR_H
25 #define FILE_AGGREGATOR_H
26 
27 #include <fstream>
28 #include <map>
29 #include <string>
30 #include "ns3/data-collection-object.h"
31 
32 namespace ns3 {
33 
40 {
41 public:
43  enum FileType
44  {
49  };
50 
55  static TypeId GetTypeId ();
56 
65  FileAggregator (const std::string &outputFileName,
66  enum FileType fileType = SPACE_SEPARATED);
67 
68  virtual ~FileAggregator ();
69 
77  void SetFileType (enum FileType fileType);
78 
88  void SetHeading (const std::string &heading);
89 
96  void Set1dFormat (const std::string &format);
97 
104  void Set2dFormat (const std::string &format);
105 
112  void Set3dFormat (const std::string &format);
113 
120  void Set4dFormat (const std::string &format);
121 
128  void Set5dFormat (const std::string &format);
129 
136  void Set6dFormat (const std::string &format);
137 
144  void Set7dFormat (const std::string &format);
145 
152  void Set8dFormat (const std::string &format);
153 
160  void Set9dFormat (const std::string &format);
161 
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 
180  void Write1d (std::string context,
181  double v1);
182 
190  void Write2d (std::string context,
191  double v1,
192  double v2);
193 
202  void Write3d (std::string context,
203  double v1,
204  double v2,
205  double v3);
206 
216  void Write4d (std::string context,
217  double v1,
218  double v2,
219  double v3,
220  double v4);
221 
232  void Write5d (std::string context,
233  double v1,
234  double v2,
235  double v3,
236  double v4,
237  double v5);
238 
250  void Write6d (std::string context,
251  double v1,
252  double v2,
253  double v3,
254  double v4,
255  double v5,
256  double v6);
257 
270  void Write7d (std::string context,
271  double v1,
272  double v2,
273  double v3,
274  double v4,
275  double v5,
276  double v6,
277  double v7);
278 
292  void Write8d (std::string context,
293  double v1,
294  double v2,
295  double v3,
296  double v4,
297  double v5,
298  double v6,
299  double v7,
300  double v8);
301 
316  void Write9d (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 
342  void Write10d (std::string context,
343  double v1,
344  double v2,
345  double v3,
346  double v4,
347  double v5,
348  double v6,
349  double v7,
350  double v8,
351  double v9,
352  double v10);
353 
354 private:
356  std::string m_outputFileName;
357 
359  std::ofstream m_file;
360 
363 
365  std::string m_separator;
366 
369 
371  std::string m_heading;
372 
373  std::string m_1dFormat;
374  std::string m_2dFormat;
375  std::string m_3dFormat;
376  std::string m_4dFormat;
377  std::string m_5dFormat;
378  std::string m_6dFormat;
379  std::string m_7dFormat;
380  std::string m_8dFormat;
381  std::string m_9dFormat;
382  std::string m_10dFormat;
383 
384 }; // class FileAggregator
385 
386 
387 } // namespace ns3
388 
389 #endif // FILE_AGGREGATOR_H
Base class for data collection framework objects.
std::string m_outputFileName
The file name.
void Set6dFormat(const std::string &format)
Sets the 6D format string for the C-style sprintf() function.
std::string m_8dFormat
Format string for 8D C-style sprintf() function.
void Set2dFormat(const std::string &format)
Sets the 2D 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_9dFormat
Format string for 9D C-style sprintf() function.
void Write1d(std::string context, double v1)
Writes 1 value 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 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.
void Set8dFormat(const std::string &format)
Sets the 8D 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.
This aggregator sends values it receives to a file.
std::string m_2dFormat
Format string for 2D C-style sprintf() function.
void Write2d(std::string context, double v1, double v2)
Writes 2 values to the file.
std::string m_5dFormat
Format string for 5D C-style sprintf() function.
void Set10dFormat(const std::string &format)
Sets the 10D format string for the C-style sprintf() function.
void Set7dFormat(const std::string &format)
Sets the 7D format string for the C-style sprintf() function.
void Write3d(std::string context, double v1, double v2, double v3)
Writes 3 values to the file.
std::string m_6dFormat
Format string for 6D C-style sprintf() function.
void Write4d(std::string context, double v1, double v2, double v3, double v4)
Writes 4 values to the file.
FileType
The type of file written by the aggregator.
void SetFileType(enum FileType fileType)
Set the file type to create, which determines the separator to use when printing values to the file...
std::string m_4dFormat
Format string for 4D C-style sprintf() function.
std::string m_heading
Heading line for the outputfile.
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.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
enum FileType m_fileType
Determines the kind of file written by the aggregator.
static TypeId GetTypeId()
Get the type ID.
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 Write5d(std::string context, double v1, double v2, double v3, double v4, double v5)
Writes 5 values to the file.
std::string m_1dFormat
Format string for 1D 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 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.
void Set9dFormat(const std::string &format)
Sets the 9D format string for the 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.
FileAggregator(const std::string &outputFileName, enum FileType fileType=SPACE_SEPARATED)
std::string m_separator
Printed between values in the file.
std::string m_7dFormat
Format string for 7D C-style sprintf() function.
void Set3dFormat(const std::string &format)
Sets the 3D format string for the C-style sprintf() function.
std::ofstream m_file
Used to write values to the file.
a unique identifier for an interface.
Definition: type-id.h:58
std::string m_10dFormat
Format string for 10D C-style sprintf() function.
void Set4dFormat(const std::string &format)
Sets the 4D format string for the C-style sprintf() function.