A Discrete-Event Network Simulator
API
data-calculator.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/simulator.h"
23 
24 #include "data-calculator.h"
25 
26 using namespace ns3;
27 
28 NS_LOG_COMPONENT_DEFINE ("DataCalculator");
29 
30 static double zero = 0;
31 const double ns3::NaN = zero / zero;
32 
33 //--------------------------------------------------------------
34 //----------------------------------------------
36  m_enabled (true)
37 {
38  NS_LOG_FUNCTION (this);
39 }
40 
42 {
43  NS_LOG_FUNCTION (this);
44 }
45 
46 /* static */
47 TypeId
49 {
50  static TypeId tid = TypeId ("ns3::DataCalculator")
51  .SetParent<Object> ()
52  .SetGroupName ("Stats")
53  // No AddConstructor because this is an abstract class.
54  ;
55  return tid;
56 }
57 
58 void
60 {
61  NS_LOG_FUNCTION (this);
62 
65 
67  // DataCalculator::DoDispose
68 }
69 
70 //----------------------------------------------
71 void
72 DataCalculator::SetKey (const std::string key)
73 {
74  NS_LOG_FUNCTION (this << key);
75 
76  m_key = key;
77  // end DataCalculator::SetKey
78 }
79 
80 std::string
82 {
83  NS_LOG_FUNCTION (this);
84 
85  return m_key;
86  // end DataCalculator::GetKey
87 }
88 
89 //----------------------------------------------
90 void
91 DataCalculator::SetContext (const std::string context)
92 {
93  NS_LOG_FUNCTION (this << context);
94 
95  m_context = context;
96  // end DataCalculator::SetContext
97 }
98 
99 std::string
101 {
102  NS_LOG_FUNCTION (this);
103 
104  return m_context;
105  // end DataCalculator::GetContext
106 }
107 //----------------------------------------------
108 void
110 {
111  NS_LOG_FUNCTION (this);
112 
113  m_enabled = true;
114  // end DataCalculator::Enable
115 }
116 
117 void
119 {
120  NS_LOG_FUNCTION (this);
121 
122  m_enabled = false;
123  // end DataCalculator::Disable
124 }
125 
126 bool
128 {
129  NS_LOG_FUNCTION (this);
130 
131  return m_enabled;
132  // end DataCalculator::GetEnabled
133 }
134 
135 //----------------------------------------------
136 void
138 {
139  NS_LOG_FUNCTION (this << startTime);
140 
141  m_startEvent = Simulator::Schedule (startTime,
142  &DataCalculator::Enable, this);
143 
144  // end DataCalculator::Start
145 }
146 
147 void
149 {
150  NS_LOG_FUNCTION (this << stopTime);
151 
152  m_stopEvent = Simulator::Schedule (stopTime,
153  &DataCalculator::Disable, this);
154  // end DataCalculator::Stop
155 }
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:102
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
void SetKey(const std::string key)
Sets the DataCalculator key to the provided key.
std::string GetKey() const
Gets the DataCalculator key.
static TypeId GetTypeId(void)
Register this type.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
bool m_enabled
Descendant classes must check & respect m_enabled!
static void Cancel(const EventId &id)
Set the cancel bit on this event: the event's associated function will not be invoked when it expires...
Definition: simulator.cc:321
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
static double zero
virtual void Stop(const Time &stopTime)
Stops DataCalculator at a given time in the simulation.
virtual void Start(const Time &startTime)
Starts DataCalculator at a given time in the simulation.
double stopTime
EventId m_startEvent
Start event.
std::string GetContext() const
Gets the DataCalculator context.
static EventId Schedule(Time const &delay, MEM mem_ptr, OBJ obj)
Schedule an event to expire after delay.
Definition: simulator.h:1238
void Enable()
Enables DataCalculator when simulation starts.
bool GetEnabled() const
Returns whether the DataCalculator is enabled.
double startTime
EventId m_stopEvent
Stop event.
virtual void DoDispose(void)
Destructor implementation.
const double NaN
Stored representation of NaN.
void Disable()
Disables DataCalculator when simulation stops.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string m_context
Context value.
void SetContext(const std::string context)
Sets the DataCalculator context to the provided context.
A base class which provides memory management and object aggregation.
Definition: object.h:87
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
std::string m_key
Key value.