A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
energy-source-container.cc
Go to the documentation of this file.
1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2
/*
3
* Copyright (c) 2008 INRIA
4
* Copyright (c) 2010 Network Security Lab, University of Washington, Seattle.
5
*
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License version 2 as
8
* published by the Free Software Foundation;
9
*
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
14
*
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
*
19
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
* Sidharth Nabar <snabar@uw.edu>, He Wu <mdzz@u.washington.edu>
21
*/
22
23
#include "
energy-source-container.h
"
24
#include "ns3/names.h"
25
26
namespace
ns3
{
27
28
NS_OBJECT_ENSURE_REGISTERED
(EnergySourceContainer);
29
30
TypeId
31
EnergySourceContainer::GetTypeId
(
void
)
32
{
33
static
TypeId
tid =
TypeId
(
"ns3::EnergySourceContainer"
)
34
.
SetParent
<
Object
> ()
35
.AddConstructor<EnergySourceContainer> ()
36
;
37
return
tid;
38
}
39
40
EnergySourceContainer::EnergySourceContainer
()
41
{
42
}
43
44
EnergySourceContainer::~EnergySourceContainer
()
45
{
46
}
47
48
EnergySourceContainer::EnergySourceContainer
(
Ptr<EnergySource>
source)
49
{
50
NS_ASSERT
(source != NULL);
51
m_sources
.push_back (source);
52
}
53
54
EnergySourceContainer::EnergySourceContainer
(std::string sourceName)
55
{
56
Ptr<EnergySource>
source = Names::Find<EnergySource> (sourceName);
57
NS_ASSERT
(source != NULL);
58
m_sources
.push_back (source);
59
}
60
61
EnergySourceContainer::EnergySourceContainer
(
const
EnergySourceContainer
&a,
62
const
EnergySourceContainer
&b)
63
{
64
*
this
= a;
65
Add
(b);
66
}
67
68
EnergySourceContainer::Iterator
69
EnergySourceContainer::Begin
(
void
)
const
70
{
71
return
m_sources
.begin ();
72
}
73
74
EnergySourceContainer::Iterator
75
EnergySourceContainer::End
(
void
)
const
76
{
77
return
m_sources
.end ();
78
}
79
80
uint32_t
81
EnergySourceContainer::GetN
(
void
)
const
82
{
83
return
m_sources
.size ();
84
}
85
86
Ptr<EnergySource>
87
EnergySourceContainer::Get
(uint32_t i)
const
88
{
89
return
m_sources
[i];
90
}
91
92
void
93
EnergySourceContainer::Add
(
EnergySourceContainer
container)
94
{
95
for
(
Iterator
i = container.
Begin
(); i != container.
End
(); i++)
96
{
97
m_sources
.push_back (*i);
98
}
99
}
100
101
void
102
EnergySourceContainer::Add
(
Ptr<EnergySource>
source)
103
{
104
NS_ASSERT
(source != NULL);
105
m_sources
.push_back (source);
106
}
107
108
void
109
EnergySourceContainer::Add
(std::string sourceName)
110
{
111
Ptr<EnergySource>
source = Names::Find<EnergySource> (sourceName);
112
NS_ASSERT
(source != NULL);
113
m_sources
.push_back (source);
114
}
115
116
/*
117
* Private functions start here.
118
*/
119
120
void
121
EnergySourceContainer::DoDispose
(
void
)
122
{
123
// call Object::Dispose for all EnergySource objects
124
for
(std::vector<
Ptr<EnergySource>
>::iterator i =
m_sources
.begin ();
125
i !=
m_sources
.end (); i++)
126
{
127
(*i)->DisposeDeviceModels ();
128
(*i)->Dispose ();
129
}
130
m_sources
.clear ();
131
}
132
133
void
134
EnergySourceContainer::DoInitialize
(
void
)
135
{
136
// call Object::Start for all EnergySource objects
137
for
(std::vector<
Ptr<EnergySource>
>::iterator i =
m_sources
.begin ();
138
i !=
m_sources
.end (); i++)
139
{
140
(*i)->Initialize ();
141
(*i)->InitializeDeviceModels ();
142
}
143
}
144
145
}
// namespace ns3
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:73
ns3::EnergySourceContainer
Holds a vector of ns3::EnergySource pointers.
Definition:
energy-source-container.h:44
ns3::EnergySourceContainer::Add
void Add(EnergySourceContainer container)
Definition:
energy-source-container.cc:93
ns3::EnergySourceContainer::GetTypeId
static TypeId GetTypeId(void)
Definition:
energy-source-container.cc:31
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition:
object-base.h:44
ns3::EnergySourceContainer::GetN
uint32_t GetN(void) const
Get the number of Ptr
stored in this container.
Definition:
energy-source-container.cc:81
ns3::EnergySourceContainer::Iterator
std::vector< Ptr< EnergySource > >::const_iterator Iterator
Definition:
energy-source-container.h:47
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition:
assert.h:61
ns3::EnergySourceContainer::m_sources
std::vector< Ptr< EnergySource > > m_sources
Definition:
energy-source-container.h:176
energy-source-container.h
ns3::EnergySourceContainer::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition:
energy-source-container.cc:121
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::EnergySourceContainer::End
Iterator End(void) const
Get an iterator which refers to the last EnergySource pointer in the container.
Definition:
energy-source-container.cc:75
ns3::EnergySourceContainer::Get
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr
stored in this container.
Definition:
energy-source-container.cc:87
ns3::EnergySourceContainer::~EnergySourceContainer
~EnergySourceContainer()
Definition:
energy-source-container.cc:44
ns3::Object
A base class which provides memory management and object aggregation.
Definition:
object.h:87
ns3::EnergySourceContainer::EnergySourceContainer
EnergySourceContainer()
Creates an empty EnergySourceContainer.
Definition:
energy-source-container.cc:40
ns3::EnergySourceContainer::Begin
Iterator Begin(void) const
Get an iterator which refers to the first EnergySource pointer in the container.
Definition:
energy-source-container.cc:69
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:51
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Definition:
type-id.cc:631
ns3::EnergySourceContainer::DoInitialize
virtual void DoInitialize(void)
Calls Object::Start () for all EnergySource objects.
Definition:
energy-source-container.cc:134
src
energy
helper
energy-source-container.cc
Generated on Thu Feb 5 2015 18:33:37 for ns-3 by
1.8.9.1