A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
gnuplot.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA, 2008 Timo Bingmann
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  * Original Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  * Enhancements: Timo Bingmann <timo.bingmann@student.kit.edu>
20  */
21 #ifndef GNUPLOT_H
22 #define GNUPLOT_H
23 
24 #include <string>
25 #include <vector>
26 #include <utility>
27 
28 namespace ns3 {
29 
39 {
40 public:
41 
46  GnuplotDataset (const GnuplotDataset& original);
47 
52 
58  GnuplotDataset& operator= (const GnuplotDataset& original);
59 
64  void SetTitle (const std::string& title);
65 
70  static void SetDefaultExtra (const std::string& extra);
71 
76  void SetExtra (const std::string& extra);
77 
78 protected:
79 
82  friend class Gnuplot;
83 
87  static std::string m_defaultExtra;
88 
92  struct Data;
93 
98  GnuplotDataset (struct Data* data);
99 
103  struct Data* m_data;
104 };
105 
114 {
115 public:
119  enum Style {
128  };
129 
133  enum ErrorBars {
135  X,
136  Y,
138  };
139 
146  Gnuplot2dDataset (const std::string& title = "Untitled");
147 
152  static void SetDefaultStyle (enum Style style);
153 
157  void SetStyle (enum Style style);
158 
163  static void SetDefaultErrorBars (enum ErrorBars errorBars);
164 
173  void SetErrorBars (enum ErrorBars errorBars);
174 
181  void Add (double x, double y);
182 
190  void Add (double x, double y, double errorDelta);
191 
200  void Add (double x, double y, double xErrorDelta, double yErrorDelta);
201 
206  void AddEmptyLine ();
207 
208 private:
209 
213  struct Point {
214  bool empty;
215  double x;
216  double y;
217  double dx;
218  double dy;
219  };
220 
222  typedef std::vector<struct Point> PointSet;
223 
224  static enum Style m_defaultStyle;
226 
228  struct Data2d;
229 };
230 
240 {
241 public:
249  Gnuplot2dFunction (const std::string& title = "Untitled", const std::string& function = "");
250 
254  void SetFunction (const std::string& function);
255 
256 private:
257 
259  struct Function2d;
260 };
261 
269 {
270 public:
277  Gnuplot3dDataset (const std::string& title = "Untitled");
278 
283  static void SetDefaultStyle (const std::string& style);
284 
288  void SetStyle (const std::string& style);
289 
297  void Add (double x, double y, double z);
298 
303  void AddEmptyLine ();
304 
305 private:
306 
310  struct Point {
311  bool empty;
312  double x;
313  double y;
314  double z;
315  };
316 
318  typedef std::vector<struct Point> PointSet;
319 
320  static std::string m_defaultStyle;
321 
323  struct Data3d;
324 };
325 
336 {
337 public:
345  Gnuplot3dFunction (const std::string& title = "Untitled", const std::string& function = "");
346 
350  void SetFunction (const std::string& function);
351 
352 private:
353 
355  struct Function3d;
356 };
357 
367 class Gnuplot
368 {
369 public:
376  Gnuplot (const std::string& outputFilename="", const std::string& title = "");
377 
383  void SetOutputFilename (const std::string& outputFilename);
384 
391  static std::string DetectTerminal (const std::string& filename);
392 
397  void SetTerminal (const std::string& terminal);
398 
402  void SetTitle (const std::string& title);
403 
408  void SetLegend (const std::string& xLegend, const std::string& yLegend);
409 
413  void SetExtra (const std::string& extra);
414 
418  void AppendExtra (const std::string& extra);
419 
423  void AddDataset (const GnuplotDataset& dataset);
424 
433  void GenerateOutput (std::ostream &os);
434 
447  void GenerateOutput (std::ostream &osControl,
448  std::ostream &osData,
449  std::string dataFileName);
450 
456  void SetDataFileDatasetIndex (unsigned int index);
457 
458 private:
460  typedef std::vector<GnuplotDataset> Datasets;
461 
462  std::string m_outputFilename;
463  std::string m_terminal;
464 
466 
467  std::string m_title;
468  std::string m_xLegend;
469  std::string m_yLegend;
470  std::string m_extra;
471 
473 
474  unsigned int m_dataFileDatasetIndex;
475 };
476 
484 {
485 public:
491  GnuplotCollection (const std::string& outputFilename);
492 
497  void SetTerminal (const std::string& terminal);
498 
502  void AddPlot (const Gnuplot& plot);
503 
509  Gnuplot& GetPlot (unsigned int id);
510 
515  void GenerateOutput (std::ostream &os);
516 
526  void GenerateOutput (std::ostream &osControl,
527  std::ostream &osData,
528  std::string dataFileName);
529 
530 private:
532  typedef std::vector<Gnuplot> Plots;
533 
534  std::string m_outputFilename;
535  std::string m_terminal;
536 
538 };
539 
540 } // namespace ns3
541 
542 #endif /* GNUPLOT_H */
Structure storing the function to be used for a 3D plot.
Definition: gnuplot.cc:618
Plots m_plots
Plots in the collection.
Definition: gnuplot.h:537
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:749
A point in a 2D plot.
Definition: gnuplot.h:213
Class to represent a 3D points plot.
Definition: gnuplot.h:268
Class to represent a 2D points plot.
Definition: gnuplot.h:113
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:141
Abstract class to store a plot line to be used by ns3::Gnuplot.
Definition: gnuplot.h:38
Gnuplot(const std::string &outputFilename="", const std::string &title="")
Definition: gnuplot.cc:694
Gnuplot2dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:331
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
Definition: gnuplot.cc:147
void Add(double x, double y, double z)
Definition: gnuplot.cc:593
GnuplotDataset & operator=(const GnuplotDataset &original)
Reference-counting assignment operator.
Definition: gnuplot.cc:127
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
Definition: gnuplot.h:87
void SetFunction(const std::string &function)
Definition: gnuplot.cc:485
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:756
Class to represent a 3D function expression plot.
Definition: gnuplot.h:335
double y
Y coordinate.
Definition: gnuplot.h:313
std::vector< struct Point > PointSet
The set of points in the dataset.
Definition: gnuplot.h:318
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition: gnuplot.cc:152
void SetErrorBars(enum ErrorBars errorBars)
Definition: gnuplot.cc:353
double x
X coordinate.
Definition: gnuplot.h:215
~GnuplotDataset()
Reference-counting destructor.
Definition: gnuplot.cc:121
std::vector< GnuplotDataset > Datasets
Type for Datasets to be used in plots.
Definition: gnuplot.h:460
std::string m_xLegend
X axis legend.
Definition: gnuplot.h:468
std::string m_outputFilename
Output file name.
Definition: gnuplot.h:462
void SetOutputFilename(const std::string &outputFilename)
Definition: gnuplot.cc:703
struct Data * m_data
Reference counted data object.
Definition: gnuplot.h:103
Structure storing the data to for a 2D plot.
Definition: gnuplot.cc:164
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:367
a simple class to group together multiple gnuplots into one file, e.g.
Definition: gnuplot.h:483
void SetTitle(const std::string &title)
Definition: gnuplot.cc:730
static std::string m_defaultStyle
default plot style
Definition: gnuplot.h:320
double x
X coordinate.
Definition: gnuplot.h:312
uint8_t data[writeSize]
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition: gnuplot.cc:604
Gnuplot3dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:576
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:762
void Add(double x, double y)
Definition: gnuplot.cc:359
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:479
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:681
void AddPlot(const Gnuplot &plot)
Definition: gnuplot.cc:868
A point in a 3D plot.
Definition: gnuplot.h:310
bool empty
the point is empty
Definition: gnuplot.h:214
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:736
static void SetDefaultErrorBars(enum ErrorBars errorBars)
Change default errorbars style for all newly created objects.
Definition: gnuplot.cc:348
GnuplotCollection(const std::string &outputFilename)
Definition: gnuplot.cc:855
void GenerateOutput(std::ostream &os)
Definition: gnuplot.cc:883
static void SetDefaultStyle(enum Style style)
Change default style for all newly created objects.
Definition: gnuplot.cc:337
double z
Z coordinate.
Definition: gnuplot.h:314
Style
The plotting style to use for this dataset.
Definition: gnuplot.h:119
ErrorBars
Whether errorbars should be used for this dataset.
Definition: gnuplot.h:133
Structure storing the data to plot.
Definition: gnuplot.cc:36
Datasets m_datasets
Data sets.
Definition: gnuplot.h:465
std::vector< struct Point > PointSet
The set of points in the dataset.
Definition: gnuplot.h:222
void SetStyle(enum Style style)
Definition: gnuplot.cc:342
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:743
void SetStyle(const std::string &style)
Definition: gnuplot.cc:587
std::string m_outputFilename
Output file name.
Definition: gnuplot.h:534
std::string m_extra
extra parameters for the plot
Definition: gnuplot.h:470
bool empty
the point is empty
Definition: gnuplot.h:311
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:862
std::vector< Gnuplot > Plots
Type of the Gnuplot collection.
Definition: gnuplot.h:532
unsigned int m_dataFileDatasetIndex
Data set index to plot.
Definition: gnuplot.h:474
std::string m_terminal
Gnuplot "terminal" to use.
Definition: gnuplot.h:535
void SetFunction(const std::string &function)
Definition: gnuplot.cc:687
std::string m_title
Plot title.
Definition: gnuplot.h:467
GnuplotDataset(const GnuplotDataset &original)
Reference-counting copy constructor.
Definition: gnuplot.cc:115
bool m_generateOneOutputFile
true if only one plot will be generated
Definition: gnuplot.h:472
Class to represent a 2D function expression plot.
Definition: gnuplot.h:239
Structure storing the data for a 3D plot.
Definition: gnuplot.cc:497
double dx
X error delta.
Definition: gnuplot.h:217
static void SetDefaultStyle(const std::string &style)
Change default style for all newly created objects.
Definition: gnuplot.cc:582
static std::string DetectTerminal(const std::string &filename)
Crude attempt to auto-detect the correct terminal setting by inspecting the filename's extension...
Definition: gnuplot.cc:708
std::string m_yLegend
Y axis legend.
Definition: gnuplot.h:469
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition: gnuplot.cc:402
static enum Style m_defaultStyle
default plot style
Definition: gnuplot.h:224
double dy
Y error delta.
Definition: gnuplot.h:218
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
Definition: gnuplot.cc:848
std::string m_terminal
Gnuplot "terminal" to use.
Definition: gnuplot.h:463
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:724
Structure storing the function to be used for a 2D plot.
Definition: gnuplot.cc:416
double y
Y coordinate.
Definition: gnuplot.h:216
Gnuplot & GetPlot(unsigned int id)
Return a pointer to one of the added plots.
Definition: gnuplot.cc:874
static enum ErrorBars m_defaultErrorBars
default error bars type
Definition: gnuplot.h:225