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  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 
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 
458 };
459 
460 } // namespace ns3
461 
462 #endif /* GNUPLOT_H */