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 
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 {
122  };
123 
127  enum ErrorBars {
129  X,
130  Y,
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;
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  void SetOutputFilename (const std::string& outputFilename);
360 
366  static std::string DetectTerminal (const std::string& filename);
367 
372  void SetTerminal (const std::string& terminal);
373 
377  void SetTitle (const std::string& title);
378 
383  void SetLegend (const std::string& xLegend, const std::string& yLegend);
384 
388  void SetExtra (const std::string& extra);
389 
393  void AppendExtra (const std::string& extra);
394 
398  void AddDataset (const GnuplotDataset& dataset);
399 
408  void GenerateOutput (std::ostream &os);
409 
422  void GenerateOutput (std::ostream &osControl,
423  std::ostream &osData,
424  std::string dataFileName);
425 
431  void SetDataFileDatasetIndex (unsigned int index);
432 
433 private:
434  typedef std::vector<GnuplotDataset> Datasets;
435 
436  std::string m_outputFilename;
437  std::string m_terminal;
438 
440 
441  std::string m_title;
442  std::string m_xLegend;
443  std::string m_yLegend;
444  std::string m_extra;
445 
447 
449 };
450 
456 {
457 public:
463  GnuplotCollection (const std::string& outputFilename);
464 
469  void SetTerminal (const std::string& terminal);
470 
474  void AddPlot (const Gnuplot& plot);
475 
481  Gnuplot& GetPlot (unsigned int id);
482 
487  void GenerateOutput (std::ostream &os);
488 
498  void GenerateOutput (std::ostream &osControl,
499  std::ostream &osData,
500  std::string dataFileName);
501 
502 private:
503  typedef std::vector<Gnuplot> Plots;
504 
505  std::string m_outputFilename;
506  std::string m_terminal;
507 
509 };
510 
511 } // namespace ns3
512 
513 #endif /* GNUPLOT_H */
void AppendExtra(const std::string &extra)
Definition: gnuplot.cc:705
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:125
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:650
Gnuplot2dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:309
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
Definition: gnuplot.cc:131
void Add(double x, double y, double z)
Definition: gnuplot.cc:557
GnuplotDataset & operator=(const GnuplotDataset &original)
Definition: gnuplot.cc:111
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:455
void AddDataset(const GnuplotDataset &dataset)
Definition: gnuplot.cc:712
Class to represent a 3D function expression plot.
Definition: gnuplot.h:313
std::vector< struct Point > PointSet
Definition: gnuplot.h:298
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition: gnuplot.cc:136
void SetErrorBars(enum ErrorBars errorBars)
Definition: gnuplot.cc:331
std::vector< GnuplotDataset > Datasets
Definition: gnuplot.h:434
std::string m_xLegend
Definition: gnuplot.h:442
std::string m_outputFilename
Definition: gnuplot.h:436
void SetOutputFilename(const std::string &outputFilename)
Definition: gnuplot.cc:659
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
a simple class to group together multiple gnuplots into one file, e.g. for PDF multi-page output term...
Definition: gnuplot.h:455
void SetTitle(const std::string &title)
Definition: gnuplot.cc:686
static std::string m_defaultStyle
Definition: gnuplot.h:300
uint8_t data[writeSize]
Gnuplot3dDataset(const std::string &title="Untitled")
Definition: gnuplot.cc:540
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition: gnuplot.cc:718
void Add(double x, double y)
Definition: gnuplot.cc:337
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:449
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
Definition: gnuplot.cc:637
void AddPlot(const Gnuplot &plot)
Definition: gnuplot.cc:824
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition: gnuplot.cc:692
static void SetDefaultErrorBars(enum ErrorBars errorBars)
Definition: gnuplot.cc:326
GnuplotCollection(const std::string &outputFilename)
Definition: gnuplot.cc:811
void GenerateOutput(std::ostream &os)
Definition: gnuplot.cc:839
static void SetDefaultStyle(enum Style style)
Definition: gnuplot.cc:315
Datasets m_datasets
Definition: gnuplot.h:439
std::vector< struct Point > PointSet
Definition: gnuplot.h:212
void SetStyle(enum Style style)
Definition: gnuplot.cc:320
void SetExtra(const std::string &extra)
Definition: gnuplot.cc:699
void SetStyle(const std::string &style)
Definition: gnuplot.cc:551
std::string m_outputFilename
Definition: gnuplot.h:505
std::string m_extra
Definition: gnuplot.h:444
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:818
std::vector< Gnuplot > Plots
Definition: gnuplot.h:503
unsigned int m_dataFileDatasetIndex
Definition: gnuplot.h:448
std::string m_terminal
Definition: gnuplot.h:506
void SetFunction(const std::string &function)
Definition: gnuplot.cc:643
std::string m_title
Definition: gnuplot.h:441
GnuplotDataset(const GnuplotDataset &original)
Definition: gnuplot.cc:99
bool m_generateOneOutputFile
Definition: gnuplot.h:446
Class to represent a 2D function expression plot.
Definition: gnuplot.h:227
static void SetDefaultStyle(const std::string &style)
Definition: gnuplot.cc:546
static std::string DetectTerminal(const std::string &filename)
Definition: gnuplot.cc:664
std::string m_yLegend
Definition: gnuplot.h:443
static enum Style m_defaultStyle
Definition: gnuplot.h:214
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
Definition: gnuplot.cc:804
std::string m_terminal
Definition: gnuplot.h:437
void SetTerminal(const std::string &terminal)
Definition: gnuplot.cc:680
Gnuplot & GetPlot(unsigned int id)
Definition: gnuplot.cc:830
static enum ErrorBars m_defaultErrorBars
Definition: gnuplot.h:215