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/deprecated.h"
13#include "ns3/nstime.h"
14#include "ns3/object.h"
15#include "ns3/simulator.h"
16
17namespace ns3
18{
19NS_DEPRECATED_3_44("Use std::nan(\"\") instead")
20extern const double NaN; //!< Stored representation of NaN
21
22/**
23 * @brief true if x is NaN
24 * @param x
25 * @return whether x is NaN
26 */
27NS_DEPRECATED_3_44("Use std::isnan() instead")
28
29inline bool
30isNaN(double x)
31{
32 return std::isnan(x);
33}
34
35class DataOutputCallback;
36
37/**
38 * @ingroup stats
39 * @class StatisticalSummary
40 * @brief Abstract class for calculating statistical data
41 *
42 */
44{
45 public:
46 /**
47 * Destructor
48 */
50 {
51 }
52
53 /**
54 * Returns the number of observations.
55 * @return Number of observations
56 */
57 virtual long getCount() const = 0;
58
59 /**
60 * @return Sum of values
61 * @see getWeightedSum()
62 */
63 virtual double getSum() const = 0;
64
65 /**
66 * @return Sum of squared values
67 * @see getWeightedSqrSum()
68 */
69 virtual double getSqrSum() const = 0;
70
71 /**
72 * Returns the minimum of the values.
73 * @return Minimum of values
74 */
75 virtual double getMin() const = 0;
76
77 /**
78 * Returns the maximum of the values.
79 * @return Maximum of values
80 */
81 virtual double getMax() const = 0;
82
83 /**
84 * Returns the mean of the (weighted) observations.
85 * @return Mean of (weighted) observations
86 */
87 virtual double getMean() const = 0;
88
89 /**
90 * Returns the standard deviation of the (weighted) observations.
91 * @return Standard deviation of (weighted) observations
92 */
93 virtual double getStddev() const = 0;
94
95 /**
96 * Returns the variance of the (weighted) observations.
97 * @return Variance of (weighted) observations
98 */
99 virtual double getVariance() const = 0;
100};
101
102//------------------------------------------------------------
103//--------------------------------------------
104/**
105 * @ingroup stats
106 * @class DataCalculator
107 * @brief Calculates data during a simulation
108 *
109 */
110class DataCalculator : public Object
111{
112 public:
114 ~DataCalculator() override;
115
116 /**
117 * Register this type.
118 * @return The TypeId.
119 */
120 static TypeId GetTypeId();
121
122 /**
123 * Returns whether the DataCalculator is enabled
124 * @return true if DataCalculator is enabled
125 */
126 bool GetEnabled() const;
127 /**
128 * Enables DataCalculator when simulation starts
129 */
130 void Enable();
131 /**
132 * Disables DataCalculator when simulation stops
133 */
134 void Disable();
135 /**
136 * Sets the DataCalculator key to the provided key
137 * @param key Key value as a string
138 */
139 void SetKey(const std::string key);
140 /**
141 * Gets the DataCalculator key
142 * @return Key value as a string
143 */
144 std::string GetKey() const;
145
146 /**
147 * Sets the DataCalculator context to the provided context
148 * @param context Context value as a string
149 */
150 void SetContext(const std::string context);
151 /**
152 * Gets the DataCalculator context
153 * @return Context value as a string
154 */
155 std::string GetContext() const;
156
157 /**
158 * Starts DataCalculator at a given time in the simulation
159 * @param startTime
160 */
161 virtual void Start(const Time& startTime);
162 /**
163 * Stops DataCalculator at a given time in the simulation
164 * @param stopTime
165 */
166 virtual void Stop(const Time& stopTime);
167
168 /**
169 * Outputs data based on the provided callback
170 * @param callback
171 */
172 virtual void Output(DataOutputCallback& callback) const = 0;
173
174 protected:
175 bool m_enabled; //!< Descendant classes *must* check & respect m_enabled!
176
177 std::string m_key; //!< Key value
178 std::string m_context; //!< Context value
179
180 void DoDispose() override;
181
182 private:
183 EventId m_startEvent; //!< Start event
184 EventId m_stopEvent; //!< Stop event
185
186 // end class DataCalculator
187};
188
189// end namespace ns3
190}; // namespace ns3
191
192#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
#define NS_DEPRECATED_3_44(msg)
Tag for things deprecated in version ns-3.44.
Definition deprecated.h:91
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
STL namespace.