A Discrete-Event Network Simulator
API
time-data-calculators.cc
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 #include "time-data-calculators.h"
21 
22 #include "ns3/log.h"
23 #include "ns3/nstime.h"
24 
25 using namespace ns3;
26 
27 NS_LOG_COMPONENT_DEFINE("TimeDataCalculators");
28 
29 //--------------------------------------------------------------
30 //----------------------------------------------
32 {
33  NS_LOG_FUNCTION(this);
34 
35  m_count = 0;
36 }
37 
39 {
40  NS_LOG_FUNCTION(this);
41 }
42 
43 /* static */
44 TypeId
46 {
47  static TypeId tid = TypeId("ns3::TimeMinMaxAvgTotalCalculator")
49  .SetGroupName("Stats")
50  .AddConstructor<TimeMinMaxAvgTotalCalculator>();
51  return tid;
52 }
53 
54 void
56 {
57  NS_LOG_FUNCTION(this);
58 
60  // TimeMinMaxAvgTotalCalculator::DoDispose
61 }
62 
63 void
65 {
66  NS_LOG_FUNCTION(this << i);
67 
68  if (m_enabled)
69  {
70  if (m_count)
71  {
72  m_total += i;
73 
74  if (i < m_min)
75  {
76  m_min = i;
77  }
78 
79  if (i > m_max)
80  {
81  m_max = i;
82  }
83  }
84  else
85  {
86  m_min = i;
87  m_max = i;
88  m_total = i;
89  }
90  m_count++;
91  }
92  // end TimeMinMaxAvgTotalCalculator::Update
93 }
94 
95 void
97 {
98  NS_LOG_FUNCTION(this << &callback);
99 
100  callback.OutputSingleton(m_context, m_key + "-count", m_count);
101  if (m_count > 0)
102  {
103  callback.OutputSingleton(m_context, m_key + "-total", m_total);
104  callback.OutputSingleton(m_context, m_key + "-average", Time(m_total / m_count));
105  callback.OutputSingleton(m_context, m_key + "-max", m_max);
106  callback.OutputSingleton(m_context, m_key + "-min", m_min);
107  }
108  // end TimeMinMaxAvgTotalCalculator::Output
109 }
Calculates data during a simulation.
bool m_enabled
Descendant classes must check & respect m_enabled!
std::string m_context
Context value.
std::string m_key
Key value.
void DoDispose() override
Destructor implementation.
Callback class for the DataOutput classes.
virtual void OutputSingleton(std::string key, std::string variable, int val)=0
Associates the integer value with the variable name for a specific output format.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Unfortunately, templating the base MinMaxAvgTotalCalculator to operate over Time values isn't straigh...
Time m_total
Total value of TimeMinMaxAvgTotalCalculator.
void Update(const Time i)
Updates all variables of TimeMinMaxAvgTotalCalculator.
void DoDispose() override
Destructor implementation.
void Output(DataOutputCallback &callback) const override
Outputs data based on the provided callback.
static TypeId GetTypeId()
Register this type.
uint32_t m_count
Count value of TimeMinMaxAvgTotalCalculator.
Time m_min
Minimum value of TimeMinMaxAvgTotalCalculator.
Time m_max
Maximum value of TimeMinMaxAvgTotalCalculator.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
void(* Time)(Time oldValue, Time newValue)
TracedValue callback signature for Time.
Definition: nstime.h:839
Every class exported by the ns3 library is enclosed in the ns3 namespace.