A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
time-data-calculators.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 Drexel University
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Joe Kopena (tjkopena@cs.drexel.edu)
19  */
20 
21 #include "ns3/log.h"
22 #include "ns3/nstime.h"
23 
24 #include "time-data-calculators.h"
25 
26 using namespace ns3;
27 
28 NS_LOG_COMPONENT_DEFINE ("TimeDataCalculators");
29 
30 
31 //--------------------------------------------------------------
32 //----------------------------------------------
34 {
35  NS_LOG_FUNCTION (this);
36 
37  m_count = 0;
38 }
40 {
41  NS_LOG_FUNCTION (this);
42 }
43 void
45 {
46  NS_LOG_FUNCTION (this);
47 
49  // TimeMinMaxAvgTotalCalculator::DoDispose
50 }
51 
52 void
54 {
55  NS_LOG_FUNCTION (this << i);
56 
57  if (m_enabled) {
58  if (m_count) {
59  m_total += i;
60 
61  if (i < m_min)
62  m_min = i;
63 
64  if (i > m_max)
65  m_max = i;
66 
67  } else {
68  m_min = i;
69  m_max = i;
70  m_total = i;
71  }
72  m_count++;
73 
74  }
75  // end TimeMinMaxAvgTotalCalculator::Update
76 }
77 void
79 {
80  NS_LOG_FUNCTION (this << &callback);
81 
82  callback.OutputSingleton (m_context, m_key + "-count", m_count);
83  if (m_count > 0) {
84  callback.OutputSingleton (m_context, m_key + "-total", m_total);
85  callback.OutputSingleton (m_context, m_key + "-average", Time (m_total / m_count));
86  callback.OutputSingleton (m_context, m_key + "-max", m_max);
87  callback.OutputSingleton (m_context, m_key + "-min", m_min);
88  }
89  // end TimeMinMaxAvgTotalCalculator::Output
90 }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
bool m_enabled
Descendant classes must check & respect m_enabled!
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
virtual void Output(DataOutputCallback &callback) const
Outputs data based on the provided callback.
virtual void DoDispose(void)
This method is called by Object::Dispose or by the object's destructor, whichever comes first...
uint32_t m_count
Count value of TimeMinMaxAvgTotalCalculator.
Callback class for the DataOutput classes.
std::string m_context
Context value.
Time m_min
Minimum value of TimeMinMaxAvgTotalCalculator.
Time m_total
Total value of TimeMinMaxAvgTotalCalculator.
void Update(const Time i)
Updates all variables of TimeMinMaxAvgTotalCalculator.
Time m_max
Maximum value of TimeMinMaxAvgTotalCalculator.
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. ...
std::string m_key
Key value.