/usr/include/ns3.27/ns3/gnuplot.h is in libns3-dev 3.27+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2007 INRIA, 2008 Timo Bingmann
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Original Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
* Enhancements: Timo Bingmann <timo.bingmann@student.kit.edu>
*/
#ifndef GNUPLOT_H
#define GNUPLOT_H
#include <string>
#include <vector>
#include <utility>
namespace ns3 {
/**
* \ingroup gnuplot
*
* \brief Abstract class to store a plot line to be used by ns3::Gnuplot.
*
* This class contains a reference counted data object in m_data. The data
* object contains different structs derived from struct Data by subclasses.
*/
class GnuplotDataset
{
public:
/**
* Reference-counting copy constructor.
* \param original Original GnuPlotDataset
*/
GnuplotDataset (const GnuplotDataset& original);
/**
* Reference-counting destructor.
*/
~GnuplotDataset();
/**
* Reference-counting assignment operator.
* \param original Right-hand side of assignment operator
* \return Copy of original GnuplotDataset
*/
GnuplotDataset& operator= (const GnuplotDataset& original);
/**
* \brief Change line title.
* \param title the new title string to use for this dataset.
*
* \note If you want your title to contain a newline character,
* escape it like this: "First line\\nSecond line" so that
* it is converted to "First line\nSecond line" in the plot file.
*/
void SetTitle (const std::string& title);
/**
* \brief Change extra formatting style parameters for newly created objects.
* \param extra extra formatting
*/
static void SetDefaultExtra (const std::string& extra);
/**
* \brief Add extra formatting parameters to this dataset.
* \param extra extra formatting
*/
void SetExtra (const std::string& extra);
protected:
/// Friend because it accesses m_data and it's virtual functions directly in
/// GenerateOutput().
friend class Gnuplot;
/**
* \brief Extra gnuplot parameters set on every newly created dataset.
*/
static std::string m_defaultExtra;
/**
* \brief Derived classes subclass this struct and add their own data fields.
*/
struct Data;
/**
* Called by constructors of derived classes.
* \param data the reference counted data object representing this dataset.
*/
GnuplotDataset (struct Data* data);
/**
* Reference counted data object.
*/
struct Data* m_data;
};
/**
* \ingroup gnuplot
*
* \class Gnuplot2dDataset
* \brief Class to represent a 2D points plot. Set the line or points style
* using SetStyle() and set points using Add().
*/
class Gnuplot2dDataset : public GnuplotDataset
{
public:
/**
* The plotting style to use for this dataset.
*/
enum Style {
LINES,
POINTS,
LINES_POINTS,
DOTS,
IMPULSES,
STEPS,
FSTEPS,
HISTEPS,
};
/**
* Whether errorbars should be used for this dataset.
*/
enum ErrorBars {
NONE,
X,
Y,
XY
};
/**
* \param title the title to be associated to this dataset.
*
* Create an empty dataset. Usually, the dataset's title is
* displayed in the legend box.
*/
Gnuplot2dDataset (const std::string& title = "Untitled");
/**
* Change default style for all newly created objects.
* \param style the style of plotting to use for newly created datasets.
*/
static void SetDefaultStyle (enum Style style);
/**
* \param style the style of plotting to use for this dataset.
*/
void SetStyle (enum Style style);
/**
* Change default errorbars style for all newly created objects.
* \param errorBars the style of errorbars to use for newly created datasets.
*/
static void SetDefaultErrorBars (enum ErrorBars errorBars);
/**
* \param errorBars the style of errorbars to display.
*
* If you use any style other than none, you need
* to make sure you store the delta information in
* this dataset with the right GnuplotDataset::Add
* method.
*/
void SetErrorBars (enum ErrorBars errorBars);
/**
* \param x x coord to new data point
* \param y y coord to new data point
*
* Use this method with error bar style NONE.
*/
void Add (double x, double y);
/**
* \param x x coord to new data point
* \param y y coord to new data point
* \param errorDelta x and y data point uncertainty
*
* Use this method with error bar style X or Y.
*/
void Add (double x, double y, double errorDelta);
/**
* \param x x coord to new data point
* \param y y coord to new data point
* \param xErrorDelta x data point uncertainty
* \param yErrorDelta y data point uncertainty
*
* Use this method with error bar style XY.
*/
void Add (double x, double y, double xErrorDelta, double yErrorDelta);
/**
* Add an empty line in the data output sequence. Empty lines in the plot
* data break continuous lines and do other things in the output.
*/
void AddEmptyLine ();
private:
/**
* A point in a 2D plot
*/
struct Point {
bool empty; //!< the point is empty
double x; //!< X coordinate
double y; //!< Y coordinate
double dx; //!< X error delta
double dy; //!< Y error delta
};
/// The set of points in the dataset
typedef std::vector<struct Point> PointSet;
static enum Style m_defaultStyle; //!< default plot style
static enum ErrorBars m_defaultErrorBars; //!< default error bars type
/// Forward declaration of the internal data class.
struct Data2d;
};
/**
* \ingroup gnuplot
*
* \brief Class to represent a 2D function expression plot.
*
* Since the function expression is not escaped, styles and extras could just
* as well be included in the expression string.
*/
class Gnuplot2dFunction : public GnuplotDataset
{
public:
/**
* \param title the title to be associated to this dataset.
* \param function function to plot
*
* Create an function dataset. Usually, the dataset's title is displayed in
* the legend box.
*/
Gnuplot2dFunction (const std::string& title = "Untitled", const std::string& function = "");
/**
* \param function new function string to set
*/
void SetFunction (const std::string& function);
private:
/// Forward declaration of the internal data class.
struct Function2d;
};
/**
* \ingroup gnuplot
*
* \brief Class to represent a 3D points plot. Set the line or points style
* using SetStyle() and set points using Add().
*/
class Gnuplot3dDataset : public GnuplotDataset
{
public:
/**
* \param title the title to be associated to this dataset.
*
* Create an empty dataset. Usually, the dataset's title is
* displayed in the legend box.
*/
Gnuplot3dDataset (const std::string& title = "Untitled");
/**
* Change default style for all newly created objects.
* \param style the style of plotting to use for newly created datasets.
*/
static void SetDefaultStyle (const std::string& style);
/**
* \param style the style of plotting to use for this dataset.
*/
void SetStyle (const std::string& style);
/**
* \param x x coord to new data point
* \param y y coord to new data point
* \param z z coord to new data point
*
* Use this method to add a new 3D point
*/
void Add (double x, double y, double z);
/**
* Add an empty line in the data output sequence. Empty lines in the plot
* data break continuous lines and do other things in the output.
*/
void AddEmptyLine ();
private:
/**
* A point in a 3D plot
*/
struct Point {
bool empty; //!< the point is empty
double x; //!< X coordinate
double y; //!< Y coordinate
double z; //!< Z coordinate
};
/// The set of points in the dataset
typedef std::vector<struct Point> PointSet;
static std::string m_defaultStyle; //!< default plot style
/// Forward declaration of the internal data class.
struct Data3d;
};
/**
* \ingroup gnuplot
*
* \brief Class to represent a 3D function expression plot.
*
* Since the function expression is not escaped, styles and extras could just as
* well be included in the expression string. The only difference to
* Gnuplot2dFunction is the splot command string.
*/
class Gnuplot3dFunction : public GnuplotDataset
{
public:
/**
* \param title the title to be associated to this dataset.
* \param function function to plot
*
* Create an function dataset. Usually, the dataset's title is displayed in
* the legend box.
*/
Gnuplot3dFunction (const std::string& title = "Untitled", const std::string& function = "");
/**
* \param function new function string to set
*/
void SetFunction (const std::string& function);
private:
/// Forward declaration of the internal data class.
struct Function3d;
};
/**
* \ingroup gnuplot
*
* \brief a simple class to generate gnuplot-ready plotting commands
* from a set of datasets.
*
* This class really represents a single graph on which multiple datasets
* can be plotted.
*/
class Gnuplot
{
public:
/**
* \param outputFilename the name of the file where the rendering of the
* graph will be generated if you feed the command stream output by
* Gnuplot::GenerateOutput to the gnuplot program.
* \param title title line of the plot page
*/
Gnuplot (const std::string& outputFilename="", const std::string& title = "");
/**
* \param outputFilename the name of the file where the rendering of the
* graph will be generated if you feed the command stream output by
* Gnuplot::GenerateOutput to the gnuplot program.
*/
void SetOutputFilename (const std::string& outputFilename);
/**
* Crude attempt to auto-detect the correct terminal setting by inspecting
* the filename's extension.
* \param filename output filename
* \return File extension of the provided filename
*/
static std::string DetectTerminal (const std::string& filename);
/**
* \param terminal terminal setting string for output. The default terminal
* string is "png"
*/
void SetTerminal (const std::string& terminal);
/**
* \param title set new plot title string to use for this plot.
*/
void SetTitle (const std::string& title);
/**
* \param xLegend the legend for the x horizontal axis
* \param yLegend the legend for the y vertical axis
*/
void SetLegend (const std::string& xLegend, const std::string& yLegend);
/**
* \param extra set extra gnuplot directive for output.
*/
void SetExtra (const std::string& extra);
/**
* \param extra append extra gnuplot directive for output.
*/
void AppendExtra (const std::string& extra);
/**
* \param dataset add a dataset to the graph to be plotted.
*/
void AddDataset (const GnuplotDataset& dataset);
/**
* \param os the output stream on which the relevant gnuplot
* commands should be generated. Including output file and terminal
* headers.
*
* \brief Writes gnuplot commands and data values to a single
* output stream.
*/
void GenerateOutput (std::ostream &os);
/**
* \param osControl the output stream on which the relevant gnuplot
* contol commands should be generated. Including output file and
* terminal headers.
* \param osData the output stream on which the relevant gnuplot
* data values should be generated.
* \param dataFileName the name for the data file that will be
* written.
*
* \brief Writes gnuplot commands and data values to two
* different outputs streams.
*/
void GenerateOutput (std::ostream &osControl,
std::ostream &osData,
std::string dataFileName);
/**
* \param index the index for the data stream in the data file.
*
* \brief Sets the current data stream index in the data file.
*/
void SetDataFileDatasetIndex (unsigned int index);
private:
/// Type for Datasets to be used in plots
typedef std::vector<GnuplotDataset> Datasets;
std::string m_outputFilename; //!< Output file name
std::string m_terminal; //!< Gnuplot "terminal" to use
Datasets m_datasets; //!< Data sets
std::string m_title; //!< Plot title
std::string m_xLegend; //!< X axis legend
std::string m_yLegend; //!< Y axis legend
std::string m_extra; //!< extra parameters for the plot
bool m_generateOneOutputFile; //!< true if only one plot will be generated
unsigned int m_dataFileDatasetIndex; //!< Data set index to plot
};
/**
* \ingroup gnuplot
*
* \brief a simple class to group together multiple gnuplots into one file,
* e.g. for PDF multi-page output terminals.
*/
class GnuplotCollection
{
public:
/**
* \param outputFilename the name of the file where the rendering of the
* graph will be generated if you feed the command stream output by
* GnuplotCollection::GenerateOutput to the gnuplot program.
*/
GnuplotCollection (const std::string& outputFilename);
/**
* \param terminal terminal setting string for output. The default terminal
* string is guessed from the output filename's extension.
*/
void SetTerminal (const std::string& terminal);
/**
* \param plot add a plot to the collection to be plotted.
*/
void AddPlot (const Gnuplot& plot);
/**
* Return a pointer to one of the added plots.
* \param id index of plot to return
* \return reference to plot, throws std::range_error if it does not exist.
*/
Gnuplot& GetPlot (unsigned int id);
/**
* \param os the output stream on which the relevant gnuplot commands should
* be generated.
*/
void GenerateOutput (std::ostream &os);
/**
* \param osControl the output stream on which the relevant gnuplot
* contol commands should be generated. Including output file and
* terminal headers.
* \param osData the output stream on which the relevant gnuplot
* data values should be generated.
* \param dataFileName the name for the data file that will be
* written.
*/
void GenerateOutput (std::ostream &osControl,
std::ostream &osData,
std::string dataFileName);
private:
/// Type of the Gnuplot collection
typedef std::vector<Gnuplot> Plots;
std::string m_outputFilename; //!< Output file name
std::string m_terminal; //!< Gnuplot "terminal" to use
Plots m_plots; //!< Plots in the collection
};
} // namespace ns3
#endif /* GNUPLOT_H */
|