A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
gnuplot_new.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA, 2008 Timo Bingmann
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Original Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 * Enhancements: Timo Bingmann <timo.bingmann@student.kit.edu>
8 */
9#include "gnuplot.h"
10
11#include "ns3/assert.h"
12
13#include <ostream>
14#include <stdexcept>
15
16namespace ns3
17{
18
19// --- GnuplotDataset::Data ------------------------------------------------ //
20
21/**
22 * @ingroup gnuplot
23 *
24 * Structure storing the data to plot.
25 * Derived classes subclass this struct and add their own data fields.
26 */
27struct GnuplotDataset::Data
28{
29 // *** Data Variables ***
30
31 unsigned int m_references; //!< ref/unref counter for garbage collection
32
33 std::string m_title; //!< Dataset title
34 std::string m_extra; //!< Extra parameters for the plot
35
36 /**
37 * Initializes the reference counter to 1 and sets m_title and m_extra.
38 * @param title Dataset title
39 */
40 Data(const std::string& title);
41
42 /// Required.
43 virtual ~Data();
44
45 /**
46 * @brief Returns the plot type ("plot" or "splot").
47 * @returns the plot type ("plot" or "splot").
48 */
49 virtual std::string GetCommand() const = 0;
50
51 /**
52 * Prints the plot description used as argument to (s)plot. Either
53 * the function expression or a datafile description. Should include
54 * m_title and m_extra in the output.
55 *
56 * If more than one output file is being generated, i.e. separate
57 * data and control files, then the index for the current dataset
58 * and the name for the data file are also included.
59 *
60 * @param os Output stream
61 * @param generateOneOutputFile If true, generate only one output file.
62 * @param dataFileDatasetIndex Dataset Index
63 * @param dataFileName Dataset file name
64 */
65 virtual void PrintExpression(std::ostream& os,
67 unsigned int dataFileDatasetIndex,
68 std::string& dataFileName) const = 0;
69
70 /**
71 * Print the inline data file contents trailing the plot command. Empty for
72 * functions.
73 *
74 * @param os Output stream
75 * @param generateOneOutputFile If true, generate only one output file.
76 */
77 virtual void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const = 0;
78
79 /**
80 * Checks to see if this GnuplotDataset is empty.
81 * @return indicates if this GnuplotDataset is empty.
82 */
83 virtual bool IsEmpty() const = 0;
84};
85
86GnuplotDataset::Data::Data(const std::string& title)
87 : m_references(1),
88 m_title(title),
89 m_extra(m_defaultExtra)
90{
91}
92
94{
95}
96
97// --- GnuplotDataset ------------------------------------------------------ //
98
99std::string GnuplotDataset::m_defaultExtra = "";
100
102 : m_data(data)
103{
104}
105
106GnuplotDataset::GnuplotDataset(const GnuplotDataset& original)
108{
110}
111
113{
114 if (--m_data->m_references == 0)
115 {
116 delete m_data;
117 }
118}
119
121GnuplotDataset::operator=(const GnuplotDataset& original)
122{
123 if (this != &original)
124 {
125 if (--m_data->m_references == 0)
126 {
127 delete m_data;
128 }
129
130 m_data = original.m_data;
132 }
133 return *this;
134}
135
136void
137GnuplotDataset::SetTitle(const std::string& title)
138{
139 m_data->m_title = title;
140}
141
142void
143GnuplotDataset::SetDefaultExtra(const std::string& extra)
144{
146}
147
148void
149GnuplotDataset::SetExtra(const std::string& extra)
150{
152}
153
154// --- Gnuplot2dDataset::Data2d -------------------------------------------- //
155
156/**
157 * @ingroup gnuplot
158 *
159 * Structure storing the data to for a 2D plot.
160 */
161struct Gnuplot2dDataset::Data2d : public GnuplotDataset::Data
162{
163 // *** Data Variables ***
164
165 Style m_style; //!< The plotting style to use for this dataset.
166 ErrorBars m_errorBars; //!< Whether errorbars should be used for this dataset.
167
168 PointSet m_pointset; //!< The set of points in this data set
169
170 /**
171 * Initializes with the values from m_defaultStyle and m_defaultErrorBars.
172 * @param title Dataset title
173 */
174 Data2d(const std::string& title);
175
176 std::string GetCommand() const override;
177 void PrintExpression(std::ostream& os,
178 bool generateOneOutputFile,
179 unsigned int dataFileDatasetIndex,
180 std::string& dataFileName) const override;
181 void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const override;
182 bool IsEmpty() const override;
183};
184
185Gnuplot2dDataset::Data2d::Data2d(const std::string& title)
186 : Data(title),
187 m_style(m_defaultStyle),
188 m_errorBars(m_defaultErrorBars)
189{
190}
191
192std::string
194{
195 return "plot";
196}
197
198void
201 unsigned int dataFileDatasetIndex,
202 std::string& dataFileName) const
203{
204 // Print the appropriate thing based on whether separate output and
205 // date files are being generated.
207 {
208 os << "\"-\" ";
209 }
210 else
211 {
212 os << "\"" << dataFileName << "\" index " << dataFileDatasetIndex;
213 }
214
215 if (!m_title.empty())
216 {
217 os << " title \"" << m_title << "\"";
218 }
219
220 switch (m_style)
221 {
222 case LINES:
223 os << " with lines";
224 break;
225 case POINTS:
226 switch (m_errorBars)
227 {
228 case NONE:
229 os << " with points";
230 break;
231 case X:
232 os << " with xerrorbars";
233 break;
234 case Y:
235 os << " with yerrorbars";
236 break;
237 case XY:
238 os << " with xyerrorbars";
239 break;
240 }
241 break;
242 case LINES_POINTS:
243 switch (m_errorBars)
244 {
245 case NONE:
246 os << " with linespoints";
247 break;
248 case X:
249 os << " with errorlines";
250 break;
251 case Y:
252 os << " with yerrorlines";
253 break;
254 case XY:
255 os << " with xyerrorlines";
256 break;
257 }
258 break;
259 case DOTS:
260 os << " with dots";
261 break;
262 case IMPULSES:
263 os << " with impulses";
264 break;
265 case STEPS:
266 os << " with steps";
267 break;
268 case FSTEPS:
269 os << " with fsteps";
270 break;
271 case HISTEPS:
272 os << " with histeps";
273 break;
274 case FILLEDCURVE:
275 os << " with filledcurve";
276 break;
277 }
278
279 if (!m_extra.empty())
280 {
281 os << " " << m_extra;
282 }
283}
284
285void
287{
288 for (auto i = m_pointset.begin(); i != m_pointset.end(); ++i)
289 {
290 if (i->empty)
291 {
292 os << std::endl;
293 continue;
294 }
295
296 switch (m_errorBars)
297 {
298 case NONE:
299 os << i->x << " " << i->y << std::endl;
300 break;
301 case X:
302 os << i->x << " " << i->y << " " << i->dx << std::endl;
303 break;
304 case Y:
305 os << i->x << " " << i->y << " " << i->dy << std::endl;
306 break;
307 case XY:
308 os << i->x << " " << i->y << " " << i->dx << " " << i->dy << std::endl;
309 break;
310 }
311 }
312
313 // Print the appropriate thing based on whether separate output and
314 // date files are being generated.
316 {
317 os << "e" << std::endl;
318 }
319 else
320 {
321 os << std::endl;
322 os << std::endl;
323 }
324}
325
326bool
328{
329 return m_pointset.empty();
330}
331
332// --- Gnuplot2dDataset ---------------------------------------------------- //
333
334/// Default plot style static instance
336/// Default error bars type static instance
338
339Gnuplot2dDataset::Gnuplot2dDataset(const std::string& title)
340 : GnuplotDataset(new Data2d(title))
341{
342}
343
344void
346{
348}
349
350void
352{
353 reinterpret_cast<Data2d*>(m_data)->m_style = style;
354}
355
356void
358{
360}
361
362void
364{
365 reinterpret_cast<Data2d*>(m_data)->m_errorBars = errorBars;
366}
367
368void
369Gnuplot2dDataset::Add(double x, double y)
370{
371 NS_ASSERT(reinterpret_cast<Data2d*>(m_data)->m_errorBars == NONE);
372
373 Point data;
374 data.empty = false;
375 data.x = x;
376 data.y = y;
377 data.dx = 0.0;
378 data.dy = 0.0;
379 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back(data);
380}
381
382void
383Gnuplot2dDataset::Add(double x, double y, double errorDelta)
384{
385 NS_ASSERT(reinterpret_cast<Data2d*>(m_data)->m_errorBars == X ||
386 reinterpret_cast<Data2d*>(m_data)->m_errorBars == Y);
387
388 Point data;
389 data.empty = false;
390 data.x = x;
391 data.y = y;
392 data.dx = errorDelta;
393 data.dy = errorDelta;
394 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back(data);
395}
396
397void
398Gnuplot2dDataset::Add(double x, double y, double xErrorDelta, double yErrorDelta)
399{
400 NS_ASSERT(reinterpret_cast<Data2d*>(m_data)->m_errorBars == XY);
401
402 Point data;
403 data.empty = false;
404 data.x = x;
405 data.y = y;
406 data.dx = xErrorDelta;
407 data.dy = yErrorDelta;
408 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back(data);
409}
410
411void
413{
414 Point data;
415 data.empty = true;
416 reinterpret_cast<Data2d*>(m_data)->m_pointset.push_back(data);
417}
418
419// --- Gnuplot2dFunction::Function2d --------------------------------------- //
420
421/**
422 * @ingroup gnuplot
423 *
424 * Structure storing the function to be used for a 2D plot.
425 */
426struct Gnuplot2dFunction::Function2d : public GnuplotDataset::Data
427{
428 // *** Data Variables ***
429
430 std::string m_function; //!< Function to use
431
432 /**
433 * Initializes with the function and title.
434 *
435 * @param title Title of the plot
436 * @param function Function to plot
437 */
438 Function2d(const std::string& title, const std::string& function);
439
440 std::string GetCommand() const override;
441 void PrintExpression(std::ostream& os,
442 bool generateOneOutputFile,
443 unsigned int dataFileDatasetIndex,
444 std::string& dataFileName) const override;
445 void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const override;
446 bool IsEmpty() const override;
447};
448
449Gnuplot2dFunction::Function2d::Function2d(const std::string& title, const std::string& function)
450 : Data(title),
451 m_function(function)
452{
453}
454
455std::string
457{
458 return "plot";
459}
460
461void
464 unsigned int dataFileDatasetIndex,
465 std::string& dataFileName) const
466{
467 os << m_function;
468
469 if (!m_title.empty())
470 {
471 os << " title \"" << m_title << "\"";
472 }
473
474 if (!m_extra.empty())
475 {
476 os << " " << m_extra;
477 }
478}
479
480void
482{
483}
484
485bool
487{
488 return false;
489}
490
491// --- Gnuplot2dFunction --------------------------------------------------- //
492
493Gnuplot2dFunction::Gnuplot2dFunction(const std::string& title, const std::string& function)
494 : GnuplotDataset(new Function2d(title, function))
495{
496}
497
498void
500{
501 reinterpret_cast<Function2d*>(m_data)->m_function = function;
502}
503
504// --- Gnuplot3dDataset::Data3d -------------------------------------------- //
505
506/**
507 * @ingroup gnuplot
508 *
509 * Structure storing the data for a 3D plot.
510 */
511struct Gnuplot3dDataset::Data3d : public GnuplotDataset::Data
512{
513 // *** Data Variables ***
514
515 std::string m_style; //!< The plotting style to use for this dataset.
516
517 PointSet m_pointset; //!< The set of points in this data set
518
519 /**
520 * Initializes with value from m_defaultStyle.
521 * @param title Dataset title
522 */
523 Data3d(const std::string& title);
524
525 std::string GetCommand() const override;
526 void PrintExpression(std::ostream& os,
527 bool generateOneOutputFile,
528 unsigned int dataFileDatasetIndex,
529 std::string& dataFileName) const override;
530 void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const override;
531 bool IsEmpty() const override;
532};
533
534Gnuplot3dDataset::Data3d::Data3d(const std::string& title)
535 : Data(title),
536 m_style(m_defaultStyle)
537{
538}
539
540std::string
542{
543 return "splot";
544}
545
546void
549 unsigned int dataFileDatasetIndex,
550 std::string& dataFileName) const
551{
552 os << "\"-\" ";
553
554 if (!m_style.empty())
555 {
556 os << " " << m_style;
557 }
558
559 if (!m_title.empty())
560 {
561 os << " title \"" << m_title << "\"";
562 }
563
564 if (!m_extra.empty())
565 {
566 os << " " << m_extra;
567 }
568}
569
570void
572{
573 for (auto i = m_pointset.begin(); i != m_pointset.end(); ++i)
574 {
575 if (i->empty)
576 {
577 os << std::endl;
578 continue;
579 }
580
581 os << i->x << " " << i->y << " " << i->z << std::endl;
582 }
583 os << "e" << std::endl;
584}
585
586bool
588{
589 return m_pointset.empty();
590}
591
592// --- Gnuplot3dDataset ---------------------------------------------------- //
593
594std::string Gnuplot3dDataset::m_defaultStyle = "";
595
596Gnuplot3dDataset::Gnuplot3dDataset(const std::string& title)
597 : GnuplotDataset(new Data3d(title))
598{
599}
600
601void
603{
605}
606
607void
608Gnuplot3dDataset::SetStyle(const std::string& style)
609{
610 reinterpret_cast<Data3d*>(m_data)->m_style = style;
611}
612
613void
614Gnuplot3dDataset::Add(double x, double y, double z)
615{
616 Point data;
617 data.empty = false;
618 data.x = x;
619 data.y = y;
620 data.z = z;
621 reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back(data);
622}
623
624void
626{
627 Point data;
628 data.empty = true;
629 reinterpret_cast<Data3d*>(m_data)->m_pointset.push_back(data);
630}
631
632// --- Gnuplot3dFunction::Function3d --------------------------------------- //
633
634/**
635 * @ingroup gnuplot
636 *
637 * Structure storing the function to be used for a 3D plot.
638 */
639struct Gnuplot3dFunction::Function3d : public GnuplotDataset::Data
640{
641 // *** Data Variables ***
642
643 std::string m_function; //!< Function to use
644
645 /**
646 * Initializes with the function and title.
647 *
648 * @param title Title of the plot
649 * @param function Function to plot
650 */
651 Function3d(const std::string& title, const std::string& function);
652
653 std::string GetCommand() const override;
654 void PrintExpression(std::ostream& os,
655 bool generateOneOutputFile,
656 unsigned int dataFileDatasetIndex,
657 std::string& dataFileName) const override;
658 void PrintDataFile(std::ostream& os, bool generateOneOutputFile) const override;
659 bool IsEmpty() const override;
660};
661
662Gnuplot3dFunction::Function3d::Function3d(const std::string& title, const std::string& function)
663 : Data(title),
664 m_function(function)
665{
666}
667
668std::string
670{
671 return "splot";
672}
673
674void
677 unsigned int dataFileDatasetIndex,
678 std::string& dataFileName) const
679{
680 os << m_function;
681
682 if (!m_title.empty())
683 {
684 os << " title \"" << m_title << "\"";
685 }
686
687 if (!m_extra.empty())
688 {
689 os << " " << m_extra;
690 }
691}
692
693void
695{
696}
697
698bool
700{
701 return false;
702}
703
704// --- Gnuplot3dFunction --------------------------------------------------- //
705
706Gnuplot3dFunction::Gnuplot3dFunction(const std::string& title, const std::string& function)
707 : GnuplotDataset(new Function3d(title, function))
708{
709}
710
711void
713{
714 reinterpret_cast<Function3d*>(m_data)->m_function = function;
715}
716
717// ------------------------------------------------------------------------- //
718
719Gnuplot::Gnuplot(const std::string& outputFilename, const std::string& title)
720 : m_outputFilename(outputFilename),
721 m_terminal(DetectTerminal(outputFilename)),
722 m_title(title),
723 m_generateOneOutputFile(false),
724 m_dataFileDatasetIndex(0)
725{
726}
727
728void
730{
731 m_outputFilename = outputFilename;
732}
733
734std::string
735Gnuplot::DetectTerminal(const std::string& filename)
736{
737 std::string::size_type dotpos = filename.rfind('.');
738 if (dotpos == std::string::npos)
739 {
740 return "";
741 }
742
743 if (filename.substr(dotpos) == ".png")
744 {
745 return "png";
746 }
747 else if (filename.substr(dotpos) == ".pdf")
748 {
749 return "pdf";
750 }
751
752 return "";
753}
754
755void
756Gnuplot::SetTerminal(const std::string& terminal)
757{
758 m_terminal = terminal;
759}
760
761void
762Gnuplot::SetTitle(const std::string& title)
763{
764 m_title = title;
765}
766
767void
768Gnuplot::SetLegend(const std::string& xLegend, const std::string& yLegend)
769{
770 m_xLegend = xLegend;
771 m_yLegend = yLegend;
772}
773
774void
775Gnuplot::SetExtra(const std::string& extra)
776{
777 m_extra = extra;
778}
779
780void
781Gnuplot::AppendExtra(const std::string& extra)
782{
783 m_extra += "\n";
784 m_extra += extra;
785}
786
787void
788Gnuplot::AddDataset(const GnuplotDataset& dataset)
789{
790 m_datasets.push_back(dataset);
791}
792
793void
794Gnuplot::GenerateOutput(std::ostream& os)
795{
796 // If this version of this function is called, it is assumed that a
797 // single output file is being generated.
798 m_generateOneOutputFile = true;
799
800 // Send the gnuplot metadata to the same stream as the data stream.
801 GenerateOutput(os, os, "");
802}
803
804void
805Gnuplot::GenerateOutput(std::ostream& osControl, std::ostream& osData, std::string dataFileName)
806{
807 if (!m_terminal.empty())
808 {
809 osControl << "set terminal " << m_terminal << std::endl;
810 }
811
812 if (!m_outputFilename.empty())
813 {
814 osControl << "set output \"" << m_outputFilename << "\"" << std::endl;
815 }
816
817 if (!m_title.empty())
818 {
819 osControl << "set title \"" << m_title << "\"" << std::endl;
820 }
821
822 if (!m_xLegend.empty())
823 {
824 osControl << "set xlabel \"" << m_xLegend << "\"" << std::endl;
825 }
826
827 if (!m_yLegend.empty())
828 {
829 osControl << "set ylabel \"" << m_yLegend << "\"" << std::endl;
830 }
831
832 if (!m_extra.empty())
833 {
834 osControl << m_extra << std::endl;
835 }
836
837 if (m_datasets.empty())
838 {
839 return;
840 }
841
842 // Determine the GetCommand() values of all datasets included. Check that all
843 // are equal and print the command.
844
845 std::string command = m_datasets.begin()->m_data->GetCommand();
846
847 for (auto i = m_datasets.begin() + 1; i != m_datasets.end(); ++i)
848 {
849 NS_ASSERT_MSG(command == i->m_data->GetCommand(),
850 "Cannot mix 'plot' and 'splot' GnuplotDatasets.");
851 }
852
853 osControl << command << " ";
854
855 // Print all dataset expressions
856
857 bool isDataEmpty;
858 for (auto i = m_datasets.begin(); i != m_datasets.end();)
859 {
860 // Only print the dataset if it's not empty.
861 isDataEmpty = i->m_data->IsEmpty();
862 if (!isDataEmpty)
863 {
864 // Print the appropriate expression based on whether we are
865 // generating separate output and date files.
866 i->m_data->PrintExpression(osControl,
867 m_generateOneOutputFile,
868 m_dataFileDatasetIndex,
870
871 m_dataFileDatasetIndex++;
872 }
873
874 i++;
875 if (i != m_datasets.end() && !isDataEmpty)
876 {
877 osControl << ", ";
878 }
879 }
880 osControl << std::endl;
881
882 // followed by the inline datafile.
883
884 for (auto i = m_datasets.begin(); i != m_datasets.end(); i++)
885 {
886 i->m_data->PrintDataFile(osData, m_generateOneOutputFile);
887 }
888}
889
890void
891Gnuplot::SetDataFileDatasetIndex(unsigned int index)
892{
893 m_dataFileDatasetIndex = index;
894}
895
896// ------------------------------------------------------------------------- //
897
899 : m_outputFilename(outputFilename),
900 m_terminal(Gnuplot::DetectTerminal(outputFilename))
901{
902}
903
904void
906{
907 m_terminal = terminal;
908}
909
910void
912{
913 m_plots.push_back(plot);
914}
915
916Gnuplot&
917GnuplotCollection::GetPlot(unsigned int id)
918{
919 if (id >= m_plots.size())
920 {
921 throw(std::range_error("Gnuplot id is out of range"));
922 }
923 else
924 {
925 return m_plots[id];
926 }
927}
928
929void
930GnuplotCollection::GenerateOutput(std::ostream& os)
931{
932 // If this version of this function is called, it is assumed that a
933 // single output file is being generated.
934
935 if (!m_terminal.empty())
936 {
937 os << "set terminal " << m_terminal << std::endl;
938 }
939
940 if (!m_outputFilename.empty())
941 {
942 os << "set output \"" << m_outputFilename << "\"" << std::endl;
943 }
944
945 for (auto i = m_plots.begin(); i != m_plots.end(); ++i)
946 {
947 i->GenerateOutput(os);
948 }
949}
950
951void
953 std::ostream& osData,
954 std::string dataFileName)
955{
956 // If this version of this function is called, it is assumed that
957 // separate output and date files are being generated.
958
959 if (!m_terminal.empty())
960 {
961 osControl << "set terminal " << m_terminal << std::endl;
962 }
963
964 if (!m_outputFilename.empty())
965 {
966 osControl << "set output \"" << m_outputFilename << "\"" << std::endl;
967 }
968
969 for (auto i = m_plots.begin(); i != m_plots.end(); ++i)
970 {
971 i->GenerateOutput(osControl, osData, dataFileName);
972 }
973}
974
975// ------------------------------------------------------------------------- //
976
977} // namespace ns3
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition gnuplot.cc:412
static void SetDefaultStyle(Style style)
Change default style for all newly created objects.
Definition gnuplot.cc:345
static Style m_defaultStyle
default plot style
Definition gnuplot.h:218
ErrorBars
Whether errorbars should be used for this dataset.
Definition gnuplot.h:127
static void SetDefaultErrorBars(ErrorBars errorBars)
Change default errorbars style for all newly created objects.
Definition gnuplot.cc:357
void SetErrorBars(ErrorBars errorBars)
Definition gnuplot.cc:363
static ErrorBars m_defaultErrorBars
default error bars type
Definition gnuplot.h:219
void SetStyle(Style style)
Definition gnuplot.cc:351
void Add(double x, double y)
Definition gnuplot.cc:369
Style
The plotting style to use for this dataset.
Definition gnuplot.h:111
Gnuplot2dDataset(const std::string &title="Untitled")
Definition gnuplot.cc:339
void SetFunction(const std::string &function)
Definition gnuplot.cc:499
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
Definition gnuplot.cc:493
void AddEmptyLine()
Add an empty line in the data output sequence.
Definition gnuplot.cc:625
Gnuplot3dDataset(const std::string &title="Untitled")
Definition gnuplot.cc:596
void Add(double x, double y, double z)
Definition gnuplot.cc:614
static void SetDefaultStyle(const std::string &style)
Change default style for all newly created objects.
Definition gnuplot.cc:602
void SetStyle(const std::string &style)
Definition gnuplot.cc:608
static std::string m_defaultStyle
default plot style
Definition gnuplot.h:313
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
Definition gnuplot.cc:706
void SetFunction(const std::string &function)
Definition gnuplot.cc:712
GnuplotCollection(const std::string &outputFilename)
Definition gnuplot.cc:898
void AddPlot(const Gnuplot &plot)
Definition gnuplot.cc:911
void SetTerminal(const std::string &terminal)
Definition gnuplot.cc:905
Gnuplot & GetPlot(unsigned int id)
Return a pointer to one of the added plots.
Definition gnuplot.cc:917
void GenerateOutput(std::ostream &os)
Definition gnuplot.cc:930
GnuplotDataset(const GnuplotDataset &original)
Reference-counting copy constructor.
Definition gnuplot.cc:106
friend class Gnuplot
Friend because it accesses m_data and it's virtual functions directly in GenerateOutput().
Definition gnuplot.h:73
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
Definition gnuplot.h:78
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
Definition gnuplot.cc:143
GnuplotDataset & operator=(const GnuplotDataset &original)
Reference-counting assignment operator.
Definition gnuplot.cc:121
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
Definition gnuplot.cc:149
Data * m_data
Reference counted data object.
Definition gnuplot.h:94
void SetTitle(const std::string &title)
Change line title.
Definition gnuplot.cc:137
~GnuplotDataset()
Reference-counting destructor.
Definition gnuplot.cc:112
void AddDataset(const GnuplotDataset &dataset)
Definition gnuplot.cc:788
void SetLegend(const std::string &xLegend, const std::string &yLegend)
Definition gnuplot.cc:768
void SetTerminal(const std::string &terminal)
Definition gnuplot.cc:756
void AppendExtra(const std::string &extra)
Definition gnuplot.cc:781
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
Definition gnuplot.cc:794
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
Definition gnuplot.cc:891
Gnuplot(const std::string &outputFilename="", const std::string &title="")
Definition gnuplot.cc:719
void SetExtra(const std::string &extra)
Definition gnuplot.cc:775
void SetTitle(const std::string &title)
Definition gnuplot.cc:762
void SetOutputFilename(const std::string &outputFilename)
Definition gnuplot.cc:729
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:735
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition assert.h:75
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
Data2d(const std::string &title)
Initializes with the values from m_defaultStyle and m_defaultErrorBars.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
Function2d(const std::string &title, const std::string &function)
Initializes with the function and title.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
Data3d(const std::string &title)
Initializes with value from m_defaultStyle.
bool IsEmpty() const override
Checks to see if this GnuplotDataset is empty.
void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const override
Prints the plot description used as argument to (s)plot.
Function3d(const std::string &title, const std::string &function)
Initializes with the function and title.
void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const override
Print the inline data file contents trailing the plot command.
std::string GetCommand() const override
Returns the plot type ("plot" or "splot").
Structure storing the data to plot.
Definition gnuplot.cc:28
unsigned int m_references
ref/unref counter for garbage collection
Definition gnuplot.cc:31
std::string m_extra
Extra parameters for the plot.
Definition gnuplot.cc:34
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const =0
Prints the plot description used as argument to (s)plot.
virtual ~Data()
Required.
Definition gnuplot.cc:93
virtual ~Data()
Required.
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const =0
Print the inline data file contents trailing the plot command.
virtual bool IsEmpty() const =0
Checks to see if this GnuplotDataset is empty.
Data(const std::string &title)
Initializes the reference counter to 1 and sets m_title and m_extra.
std::string m_title
Dataset title.
Definition gnuplot.cc:33
virtual std::string GetCommand() const =0
Returns the plot type ("plot" or "splot").