A Discrete-Event Network Simulator
API
data-calculator.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008 Drexel University
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Joe Kopena (tjkopena@cs.drexel.edu)
18  */
19 
20 #ifndef DATA_CALCULATOR_H
21 #define DATA_CALCULATOR_H
22 
23 #include "ns3/nstime.h"
24 #include "ns3/object.h"
25 #include "ns3/simulator.h"
26 
27 namespace ns3
28 {
29 extern const double NaN;
30 
36 inline bool
37 isNaN(double x)
38 {
39  return x != x;
40 }
41 
42 class DataOutputCallback;
43 
51 {
52  public:
57  {
58  }
59 
64  virtual long getCount() const = 0;
65 
70  virtual double getSum() const = 0;
71 
76  virtual double getSqrSum() const = 0;
77 
82  virtual double getMin() const = 0;
83 
88  virtual double getMax() const = 0;
89 
94  virtual double getMean() const = 0;
95 
100  virtual double getStddev() const = 0;
101 
106  virtual double getVariance() const = 0;
107 };
108 
109 //------------------------------------------------------------
110 //--------------------------------------------
117 class DataCalculator : public Object
118 {
119  public:
120  DataCalculator();
121  ~DataCalculator() override;
122 
127  static TypeId GetTypeId();
128 
133  bool GetEnabled() const;
137  void Enable();
141  void Disable();
146  void SetKey(const std::string key);
151  std::string GetKey() const;
152 
157  void SetContext(const std::string context);
162  std::string GetContext() const;
163 
168  virtual void Start(const Time& startTime);
173  virtual void Stop(const Time& stopTime);
174 
179  virtual void Output(DataOutputCallback& callback) const = 0;
180 
181  protected:
182  bool m_enabled;
183 
184  std::string m_key;
185  std::string m_context;
186 
187  void DoDispose() override;
188 
189  private:
192 
193  // end class DataCalculator
194 };
195 
196 // end namespace ns3
197 }; // namespace ns3
198 
199 #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.
~DataCalculator() override
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:55
A base class which provides memory management and object aggregation.
Definition: object.h:89
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:105
a unique identifier for an interface.
Definition: type-id.h:59
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