A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
gnuplot.h
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 
45  GnuplotDataset (const GnuplotDataset& original);
46 
51 
55  GnuplotDataset& operator= (const GnuplotDataset& original);
56 
61  void SetTitle (const std::string& title);
62 
67  static void SetDefaultExtra (const std::string& extra);
68 
73  void SetExtra (const std::string& extra);
74 
75 protected:
76 
79  friend class Gnuplot;
80 
84  static std::string m_defaultExtra;
85 
89  struct Data;
90 
95  GnuplotDataset (struct Data* data);
96 
100  struct Data* m_data;
101 };
102 
108 {
109 public:
113  enum Style {
114  LINES,
115  POINTS,
116  LINES_POINTS,
117  DOTS,
118  IMPULSES,
119  STEPS,
120  FSTEPS,
121  HISTEPS,
122  };
123 
127  enum ErrorBars {
128  NONE,
129  X,
130  Y,
131  XY
132  };
133 
140  Gnuplot2dDataset (const std::string& title = "Untitled");
141 
146  static void SetDefaultStyle (enum Style style);
147 
151  void SetStyle (enum Style style);
152 
157  static void SetDefaultErrorBars (enum ErrorBars errorBars);
158 
167  void SetErrorBars (enum ErrorBars errorBars);
168 
175  void Add (double x, double y);
176 
184  void Add (double x, double y, double errorDelta);
185 
194  void Add (double x, double y, double xErrorDelta, double yErrorDelta);
195 
200  void AddEmptyLine ();
201 
202 private:
203 
204  struct Point {
205  bool empty;
206  double x;
207  double y;
208  double dx;
209  double dy;
210  };
211 
212  typedef std::vector<struct Point> PointSet;
213 
214  static enum Style m_defaultStyle;
215  static enum ErrorBars m_defaultErrorBars;
216 
218  struct Data2d;
219 };
220 
228 {
229 public:
237  Gnuplot2dFunction (const std::string& title = "Untitled", const std::string& function = "");
238 
242  void SetFunction (const std::string& function);
243 
244 private:
245 
247  struct Function2d;
248 };
249 
255 {
256 public:
263  Gnuplot3dDataset (const std::string& title = "Untitled");
264 
269  static void SetDefaultStyle (const std::string& style);
270 
274  void SetStyle (const std::string& style);
275 
283  void Add (double x, double y, double z);
284 
289  void AddEmptyLine ();
290 
291 private:
292 
293  struct Point {
294  bool empty;
295  double x, y, z;
296  };
297 
298  typedef std::vector<struct Point> PointSet;
299 
300  static std::string m_defaultStyle;
301 
303  struct Data3d;
304 };
305 
314 {
315 public:
323  Gnuplot3dFunction (const std::string& title = "Untitled", const std::string& function = "");
324 
328  void SetFunction (const std::string& function);
329 
330 private:
331 
333  struct Function3d;
334 };
335 
343 class Gnuplot
344 {
345 public:
352  Gnuplot (const std::string& outputFilename="", const std::string& title = "");
353 
359  static std::string DetectTerminal (const std::string& filename);
360 
365  void SetTerminal (const std::string& terminal);
366 
370  void SetTitle (const std::string& title);
371 
376  void SetLegend (const std::string& xLegend, const std::string& yLegend);
377 
381  void SetExtra (const std::string& extra);
382 
386  void AppendExtra (const std::string& extra);
387 
391  void AddDataset (const GnuplotDataset& dataset);
392 
397  void GenerateOutput (std::ostream &os) const;
398 
399 private:
400  typedef std::vector<GnuplotDataset> Datasets;
401 
402  std::string m_outputFilename;
403  std::string m_terminal;
404 
405  Datasets m_datasets;
406 
407  std::string m_title;
408  std::string m_xLegend;
409  std::string m_yLegend;
410  std::string m_extra;
411 };
412 
418 {
419 public:
425  GnuplotCollection (const std::string& outputFilename);
426 
431  void SetTerminal (const std::string& terminal);
432 
436  void AddPlot (const Gnuplot& plot);
437 
443  Gnuplot& GetPlot (unsigned int id);
444 
449  void GenerateOutput (std::ostream &os) const;
450 
451 private:
452  typedef std::vector<Gnuplot> Plots;
453 
454  std::string m_outputFilename;
455  std::string m_terminal;
456 
457  Plots m_plots;
458 };
459 
460 } // namespace ns3
461 
462 #endif /* GNUPLOT_H */
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:613
Class to represent a 3D points plot. Set the line or points style using SetStyle() and set points usi...
Definition: gnuplot.h:254
Class to represent a 2D points plot. Set the line or points style using SetStyle() and set points usi...
Definition: gnuplot.h:107
void SetTitle(const std::string &title)
Change line title.
Definition: gnuplot.cc:112
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:565
Gnuplot2dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:263
void GenerateOutput(std::ostream &os) const
Definition: gnuplot.cc:626
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
Definition: gnuplot.cc:118
void Add(double x, double y, double z)
Definition: gnuplot.cc:485
GnuplotDataset & operator=(const GnuplotDataset &original)
Definition: gnuplot.cc:98
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
Definition: gnuplot.h:84
void SetFunction(const std::string &function)
Definition: gnuplot.cc:396
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:620
Class to represent a 3D function expression plot.
Definition: gnuplot.h:313
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition: gnuplot.cc:123
void SetErrorBars(enum ErrorBars errorBars)
Definition: gnuplot.cc:285
struct Data * m_data
Definition: gnuplot.h:100
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
Definition: gnuplot.h:343
make Callback use a separate empty type
Definition: empty.h:8
a simple class to group together multiple gnuplots into one file, e.g. for PDF multi-page output term...
Definition: gnuplot.h:417
void SetTitle(const std::string &title)
Definition: gnuplot.cc:594
Gnuplot3dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:468
void Add(double x, double y)
Definition: gnuplot.cc:291
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:390
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:552
void AddPlot(const Gnuplot &plot)
Definition: gnuplot.cc:701
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:600
static void SetDefaultErrorBars(enum ErrorBars errorBars)
Definition: gnuplot.cc:280
GnuplotCollection(const std::string &outputFilename)
Definition: gnuplot.cc:688
static void SetDefaultStyle(enum Style style)
Definition: gnuplot.cc:269
void SetStyle(enum Style style)
Definition: gnuplot.cc:274
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:607
void SetStyle(const std::string &style)
Definition: gnuplot.cc:479
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:695
void SetFunction(const std::string &function)
Definition: gnuplot.cc:558
GnuplotDataset(const GnuplotDataset &original)
Definition: gnuplot.cc:86
Class to represent a 2D function expression plot.
Definition: gnuplot.h:227
static void SetDefaultStyle(const std::string &style)
Definition: gnuplot.cc:474
static std::string DetectTerminal(const std::string &filename)
Definition: gnuplot.cc:572
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:588
void GenerateOutput(std::ostream &os) const
Definition: gnuplot.cc:716
Gnuplot & GetPlot(unsigned int id)
Definition: gnuplot.cc:707