22 #include "ns3/assert.h" 49 Data(
const std::string& title);
75 bool generateOneOutputFile,
76 unsigned int dataFileDatasetIndex,
77 std::string &dataFileName)
const = 0;
86 virtual void PrintDataFile (std::ostream &os,
bool generateOneOutputFile)
const = 0;
92 virtual bool IsEmpty ()
const = 0;
98 m_extra (m_defaultExtra)
116 : m_data (original.m_data)
129 if (
this != &original)
177 Data2d(
const std::string& title);
181 bool generateOneOutputFile,
182 unsigned int dataFileDatasetIndex,
183 std::string &dataFileName)
const;
184 virtual void PrintDataFile (std::ostream &os,
bool generateOneOutputFile)
const;
190 m_style (m_defaultStyle),
191 m_errorBars (m_defaultErrorBars)
203 bool generateOneOutputFile,
204 unsigned int dataFileDatasetIndex,
205 std::string &dataFileName)
const 209 if (generateOneOutputFile)
215 os <<
"\"" << dataFileName <<
"\" index " << dataFileDatasetIndex;
219 os <<
" title \"" << m_title <<
"\"";
229 os <<
" with points";
232 os <<
" with xerrorbars";
235 os <<
" with yerrorbars";
238 os <<
" with xyerrorbars";
246 os <<
" with linespoints";
249 os <<
" with errorlines";
252 os <<
" with yerrorlines";
255 os <<
" with xyerrorlines";
263 os <<
" with impulses";
269 os <<
" with fsteps";
272 os <<
" with histeps";
277 os <<
" " << m_extra;
283 for (PointSet::const_iterator i = m_pointset.begin ();
284 i != m_pointset.end (); ++i)
291 switch (m_errorBars) {
293 os << i->x <<
" " << i->y << std::endl;
296 os << i->x <<
" " << i->y <<
" " << i->dx << std::endl;
299 os << i->x <<
" " << i->y <<
" " << i->dy << std::endl;
302 os << i->x <<
" " << i->y <<
" " << i->dx <<
" " << i->dy << std::endl;
309 if (generateOneOutputFile)
311 os <<
"e" << std::endl;
323 return (m_pointset.size () == 0);
355 reinterpret_cast<Data2d*
>(
m_data)->m_errorBars = errorBars;
376 reinterpret_cast<Data2d*>(
m_data)->m_errorBars ==
Y );
382 data.dx = errorDelta;
383 data.dy = errorDelta;
396 data.dx = xErrorDelta;
397 data.dy = yErrorDelta;
428 Function2d(
const std::string& title,
const std::string&
function);
432 bool generateOneOutputFile,
433 unsigned int dataFileDatasetIndex,
434 std::string &dataFileName)
const;
435 virtual void PrintDataFile (std::ostream &os,
bool generateOneOutputFile)
const;
441 m_function (function)
453 bool generateOneOutputFile,
454 unsigned int dataFileDatasetIndex,
455 std::string &dataFileName)
const 460 os <<
" title \"" << m_title <<
"\"";
463 os <<
" " << m_extra;
509 Data3d(
const std::string& title);
513 bool generateOneOutputFile,
514 unsigned int dataFileDatasetIndex,
515 std::string &dataFileName)
const;
516 virtual void PrintDataFile (std::ostream &os,
bool generateOneOutputFile)
const;
522 m_style (m_defaultStyle)
534 bool generateOneOutputFile,
535 unsigned int dataFileDatasetIndex,
536 std::string &dataFileName)
const 541 os <<
" " << m_style;
544 os <<
" title \"" << m_title <<
"\"";
547 os <<
" " << m_extra;
553 for (PointSet::const_iterator i = m_pointset.begin ();
554 i != m_pointset.end (); ++i)
561 os << i->x <<
" " << i->y <<
" " << i->z << std::endl;
563 os <<
"e" << std::endl;
569 return (m_pointset.size () == 0);
630 Function3d(
const std::string& title,
const std::string&
function);
634 bool generateOneOutputFile,
635 unsigned int dataFileDatasetIndex,
636 std::string &dataFileName)
const;
637 virtual void PrintDataFile (std::ostream &os,
bool generateOneOutputFile)
const;
643 m_function (function)
655 bool generateOneOutputFile,
656 unsigned int dataFileDatasetIndex,
657 std::string &dataFileName)
const 662 os <<
" title \"" << m_title <<
"\"";
665 os <<
" " << m_extra;
695 : m_outputFilename (outputFilename),
696 m_terminal ( DetectTerminal (outputFilename) ),
698 m_generateOneOutputFile (false),
699 m_dataFileDatasetIndex (0)
710 std::string::size_type dotpos = filename.rfind (
'.');
711 if (dotpos == std::string::npos)
return "";
713 if (filename.substr (dotpos) ==
".png") {
716 else if (filename.substr (dotpos) ==
".pdf") {
774 std::ostream &osData,
775 std::string dataFileName)
778 osControl <<
"set terminal " <<
m_terminal << std::endl;
784 osControl <<
"set title \"" <<
m_title <<
"\"" << std::endl;
787 osControl <<
"set xlabel \"" <<
m_xLegend <<
"\"" << std::endl;
790 osControl <<
"set ylabel \"" <<
m_yLegend <<
"\"" << std::endl;
793 osControl <<
m_extra << std::endl;
801 std::string command =
m_datasets.begin ()->m_data->GetCommand ();
803 for (Datasets::const_iterator i =
m_datasets.begin () + 1;
807 "Cannot mix 'plot' and 'splot' GnuplotDatasets.");
810 osControl << command <<
" ";
818 isDataEmpty = i->m_data->IsEmpty ();
823 i->m_data->PrintExpression (osControl,
837 osControl << std::endl;
856 : m_outputFilename (outputFilename),
857 m_terminal (
Gnuplot::DetectTerminal (outputFilename) )
877 throw(std::range_error (
"Gnuplot id is out of range"));
889 os <<
"set terminal " <<
m_terminal << std::endl;
894 for (Plots::iterator i =
m_plots.begin (); i !=
m_plots.end (); ++i)
896 i->GenerateOutput (os);
902 std::string dataFileName)
908 osControl <<
"set terminal " <<
m_terminal << std::endl;
913 for (Plots::iterator i =
m_plots.begin (); i !=
m_plots.end (); ++i)
915 i->GenerateOutput (osControl, osData, dataFileName);
Structure storing the function to be used for a 3D plot.
Plots m_plots
Plots in the collection.
void AppendExtra(const std::string &extra)
Function3d(const std::string &title, const std::string &function)
Initializes with the function and title.
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
void SetTitle(const std::string &title)
Change line title.
NS_ASSERT_MSG(false, "Ipv4AddressGenerator::MaskToIndex(): Impossible")
Abstract class to store a plot line to be used by ns3::Gnuplot.
Gnuplot(const std::string &outputFilename="", const std::string &title="")
Gnuplot2dDataset(const std::string &title="Untitled")
static void SetDefaultExtra(const std::string &extra)
Change extra formatting style parameters for newly created objects.
void Add(double x, double y, double z)
enum ErrorBars m_errorBars
Whether errorbars should be used for this dataset.
unsigned int m_references
ref/unref counter for garbage collection
std::string m_style
The plotting style to use for this dataset.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
GnuplotDataset & operator=(const GnuplotDataset &original)
Reference-counting assignment operator.
static std::string m_defaultExtra
Extra gnuplot parameters set on every newly created dataset.
void SetFunction(const std::string &function)
void AddDataset(const GnuplotDataset &dataset)
virtual bool IsEmpty() const =0
Checks to see if this GnuplotDataset is empty.
Data3d(const std::string &title)
Initializes with value from m_defaultStyle.
std::vector< struct Point > PointSet
The set of points in the dataset.
void SetExtra(const std::string &extra)
Add extra formatting parameters to this dataset.
void SetErrorBars(enum ErrorBars errorBars)
~GnuplotDataset()
Reference-counting destructor.
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 void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const
Prints the plot description used as argument to (s)plot.
std::string m_xLegend
X axis legend.
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
std::string m_outputFilename
Output file name.
void SetOutputFilename(const std::string &outputFilename)
struct Data * m_data
Reference counted data object.
Structure storing the data to for a 2D plot.
Data2d(const std::string &title)
Initializes with the values from m_defaultStyle and m_defaultErrorBars.
a simple class to generate gnuplot-ready plotting commands from a set of datasets.
void SetTitle(const std::string &title)
static std::string m_defaultStyle
default plot style
void AddEmptyLine()
Add an empty line in the data output sequence.
std::string m_title
Dataset title.
Gnuplot3dDataset(const std::string &title="Untitled")
Function2d(const std::string &title, const std::string &function)
Initializes with the function and title.
void GenerateOutput(std::ostream &os)
Writes gnuplot commands and data values to a single output stream.
void Add(double x, double y)
Gnuplot2dFunction(const std::string &title="Untitled", const std::string &function="")
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
std::string m_extra
Extra parameters for the plot.
Gnuplot3dFunction(const std::string &title="Untitled", const std::string &function="")
void AddPlot(const Gnuplot &plot)
void SetLegend(const std::string &xLegend, const std::string &yLegend)
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
static void SetDefaultErrorBars(enum ErrorBars errorBars)
Change default errorbars style for all newly created objects.
virtual std::string GetCommand() const =0
Returns the plot type ("plot" or "splot").
GnuplotCollection(const std::string &outputFilename)
void GenerateOutput(std::ostream &os)
static void SetDefaultStyle(enum Style style)
Change default style for all newly created objects.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Style
The plotting style to use for this dataset.
ErrorBars
Whether errorbars should be used for this dataset.
Structure storing the data to plot.
Datasets m_datasets
Data sets.
std::vector< struct Point > PointSet
The set of points in the dataset.
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const =0
Print the inline data file contents trailing the plot command.
void SetStyle(enum Style style)
void SetExtra(const std::string &extra)
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.
void SetStyle(const std::string &style)
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
PointSet m_pointset
The set of points in this data set.
std::string m_outputFilename
Output file name.
std::string m_extra
extra parameters for the plot
void SetTerminal(const std::string &terminal)
unsigned int m_dataFileDatasetIndex
Data set index to plot.
std::string m_terminal
Gnuplot "terminal" to use.
void SetFunction(const std::string &function)
std::string m_title
Plot title.
GnuplotDataset(const GnuplotDataset &original)
Reference-counting copy constructor.
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const
Prints the plot description used as argument to (s)plot.
bool m_generateOneOutputFile
true if only one plot will be generated
Structure storing the data for a 3D plot.
std::string m_function
Function to use.
static void SetDefaultStyle(const std::string &style)
Change default style for all newly created objects.
virtual std::string GetCommand() const
Returns the plot type ("plot" or "splot").
static std::string DetectTerminal(const std::string &filename)
Crude attempt to auto-detect the correct terminal setting by inspecting the filename's extension...
std::string m_function
Function to use.
std::string m_yLegend
Y axis legend.
PointSet m_pointset
The set of points in this data set.
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const
Prints the plot description used as argument to (s)plot.
void AddEmptyLine()
Add an empty line in the data output sequence.
static enum Style m_defaultStyle
default plot style
void SetDataFileDatasetIndex(unsigned int index)
Sets the current data stream index in the data file.
std::string m_terminal
Gnuplot "terminal" to use.
virtual void PrintExpression(std::ostream &os, bool generateOneOutputFile, unsigned int dataFileDatasetIndex, std::string &dataFileName) const
Prints the plot description used as argument to (s)plot.
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
void SetTerminal(const std::string &terminal)
Structure storing the function to be used for a 2D plot.
Data(const std::string &title)
Initializes the reference counter to 1 and sets m_title and m_extra.
enum Style m_style
The plotting style to use for this dataset.
virtual void PrintDataFile(std::ostream &os, bool generateOneOutputFile) const
Print the inline data file contents trailing the plot command.
Gnuplot & GetPlot(unsigned int id)
Return a pointer to one of the added plots.
static enum ErrorBars m_defaultErrorBars
default error bars type
virtual bool IsEmpty() const
Checks to see if this GnuplotDataset is empty.