A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
data-calculator.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 Drexel University
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Joe Kopena (tjkopena@cs.drexel.edu)
7 */
8
9#ifndef DATA_CALCULATOR_H
10#define DATA_CALCULATOR_H
11
12#include "ns3/nstime.h"
13#include "ns3/object.h"
14#include "ns3/simulator.h"
15
16namespace ns3
17{
18extern const double NaN; //!< Stored representation of NaN
19
20/**
21 * \brief true if x is NaN
22 * \param x
23 * \return whether x is NaN
24 */
25inline bool
26isNaN(double x)
27{
28 return x != x;
29}
30
31class DataOutputCallback;
32
33/**
34 * \ingroup stats
35 * \class StatisticalSummary
36 * \brief Abstract class for calculating statistical data
37 *
38 */
40{
41 public:
42 /**
43 * Destructor
44 */
46 {
47 }
48
49 /**
50 * Returns the number of observations.
51 * \return Number of observations
52 */
53 virtual long getCount() const = 0;
54
55 /**
56 * \return Sum of values
57 * @see getWeightedSum()
58 */
59 virtual double getSum() const = 0;
60
61 /**
62 * \return Sum of squared values
63 * @see getWeightedSqrSum()
64 */
65 virtual double getSqrSum() const = 0;
66
67 /**
68 * Returns the minimum of the values.
69 * \return Minimum of values
70 */
71 virtual double getMin() const = 0;
72
73 /**
74 * Returns the maximum of the values.
75 * \return Maximum of values
76 */
77 virtual double getMax() const = 0;
78
79 /**
80 * Returns the mean of the (weighted) observations.
81 * \return Mean of (weighted) observations
82 */
83 virtual double getMean() const = 0;
84
85 /**
86 * Returns the standard deviation of the (weighted) observations.
87 * \return Standard deviation of (weighted) observations
88 */
89 virtual double getStddev() const = 0;
90
91 /**
92 * Returns the variance of the (weighted) observations.
93 * \return Variance of (weighted) observations
94 */
95 virtual double getVariance() const = 0;
96};
97
98//------------------------------------------------------------
99//--------------------------------------------
100/**
101 * \ingroup stats
102 * \class DataCalculator
103 * \brief Calculates data during a simulation
104 *
105 */
106class DataCalculator : public Object
107{
108 public:
110 ~DataCalculator() override;
111
112 /**
113 * Register this type.
114 * \return The TypeId.
115 */
116 static TypeId GetTypeId();
117
118 /**
119 * Returns whether the DataCalculator is enabled
120 * \return true if DataCalculator is enabled
121 */
122 bool GetEnabled() const;
123 /**
124 * Enables DataCalculator when simulation starts
125 */
126 void Enable();
127 /**
128 * Disables DataCalculator when simulation stops
129 */
130 void Disable();
131 /**
132 * Sets the DataCalculator key to the provided key
133 * \param key Key value as a string
134 */
135 void SetKey(const std::string key);
136 /**
137 * Gets the DataCalculator key
138 * \return Key value as a string
139 */
140 std::string GetKey() const;
141
142 /**
143 * Sets the DataCalculator context to the provided context
144 * \param context Context value as a string
145 */
146 void SetContext(const std::string context);
147 /**
148 * Gets the DataCalculator context
149 * \return Context value as a string
150 */
151 std::string GetContext() const;
152
153 /**
154 * Starts DataCalculator at a given time in the simulation
155 * \param startTime
156 */
157 virtual void Start(const Time& startTime);
158 /**
159 * Stops DataCalculator at a given time in the simulation
160 * \param stopTime
161 */
162 virtual void Stop(const Time& stopTime);
163
164 /**
165 * Outputs data based on the provided callback
166 * \param callback
167 */
168 virtual void Output(DataOutputCallback& callback) const = 0;
169
170 protected:
171 bool m_enabled; //!< Descendant classes *must* check & respect m_enabled!
172
173 std::string m_key; //!< Key value
174 std::string m_context; //!< Context value
175
176 void DoDispose() override;
177
178 private:
179 EventId m_startEvent; //!< Start event
180 EventId m_stopEvent; //!< Stop event
181
182 // end class DataCalculator
183};
184
185// end namespace ns3
186}; // namespace ns3
187
188#endif /* DATA_CALCULATOR_H */
Calculates data during a simulation.
void SetContext(const std::string context)
Sets the DataCalculator context to the provided context.
virtual void Output(DataOutputCallback &callback) const =0
Outputs data based on the provided callback.
bool m_enabled
Descendant classes must check & respect m_enabled!
static TypeId GetTypeId()
Register this type.
virtual void Start(const Time &startTime)
Starts DataCalculator at a given time in the simulation.
virtual void Stop(const Time &stopTime)
Stops DataCalculator at a given time in the simulation.
bool GetEnabled() const
Returns whether the DataCalculator is enabled.
void Disable()
Disables DataCalculator when simulation stops.
std::string GetKey() const
Gets the DataCalculator key.
std::string m_context
Context value.
std::string m_key
Key value.
EventId m_stopEvent
Stop event.
void DoDispose() override
Destructor implementation.
void Enable()
Enables DataCalculator when simulation starts.
std::string GetContext() const
Gets the DataCalculator context.
void SetKey(const std::string key)
Sets the DataCalculator key to the provided key.
EventId m_startEvent
Start event.
Callback class for the DataOutput classes.
An identifier for simulation events.
Definition event-id.h:45
A base class which provides memory management and object aggregation.
Definition object.h:78
Abstract class for calculating statistical data.
virtual double getMax() const =0
Returns the maximum of the values.
virtual double getMean() const =0
Returns the mean of the (weighted) observations.
virtual double getStddev() const =0
Returns the standard deviation of the (weighted) observations.
virtual ~StatisticalSummary()
Destructor.
virtual double getVariance() const =0
Returns the variance of the (weighted) observations.
virtual long getCount() const =0
Returns the number of observations.
virtual double getMin() const =0
Returns the minimum of the values.
virtual double getSum() const =0
virtual double getSqrSum() const =0
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
a unique identifier for an interface.
Definition type-id.h:48
Time stopTime
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const double NaN
Stored representation of NaN.
bool isNaN(double x)
true if x is NaN