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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Groups
Pages
energy-source-container.cc
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
TypeId
29
EnergySourceContainer::GetTypeId (
void
)
30
{
31
static
TypeId tid = TypeId (
"ns3::EnergySourceContainer"
)
32
.SetParent<Object> ()
33
.AddConstructor<EnergySourceContainer> ()
34
;
35
return
tid;
36
}
37
38
EnergySourceContainer::EnergySourceContainer
()
39
{
40
}
41
42
EnergySourceContainer::~EnergySourceContainer ()
43
{
44
}
45
46
EnergySourceContainer::EnergySourceContainer
(
Ptr<EnergySource>
source)
47
{
48
NS_ASSERT
(source != NULL);
49
m_sources.push_back (source);
50
}
51
52
EnergySourceContainer::EnergySourceContainer
(std::string sourceName)
53
{
54
Ptr<EnergySource>
source = Names::Find<EnergySource> (sourceName);
55
NS_ASSERT
(source != NULL);
56
m_sources.push_back (source);
57
}
58
59
EnergySourceContainer::EnergySourceContainer
(
const
EnergySourceContainer
&a,
60
const
EnergySourceContainer
&b)
61
{
62
*
this
= a;
63
Add
(b);
64
}
65
66
EnergySourceContainer::Iterator
67
EnergySourceContainer::Begin
(
void
)
const
68
{
69
return
m_sources.begin ();
70
}
71
72
EnergySourceContainer::Iterator
73
EnergySourceContainer::End
(
void
)
const
74
{
75
return
m_sources.end ();
76
}
77
78
uint32_t
79
EnergySourceContainer::GetN
(
void
)
const
80
{
81
return
m_sources.size ();
82
}
83
84
Ptr<EnergySource>
85
EnergySourceContainer::Get
(uint32_t i)
const
86
{
87
return
m_sources[i];
88
}
89
90
void
91
EnergySourceContainer::Add
(
EnergySourceContainer
container)
92
{
93
for
(Iterator i = container.
Begin
(); i != container.
End
(); i++)
94
{
95
m_sources.push_back (*i);
96
}
97
}
98
99
void
100
EnergySourceContainer::Add
(
Ptr<EnergySource>
source)
101
{
102
NS_ASSERT
(source != NULL);
103
m_sources.push_back (source);
104
}
105
106
void
107
EnergySourceContainer::Add
(std::string sourceName)
108
{
109
Ptr<EnergySource>
source = Names::Find<EnergySource> (sourceName);
110
NS_ASSERT
(source != NULL);
111
m_sources.push_back (source);
112
}
113
114
/*
115
* Private functions start here.
116
*/
117
118
void
119
EnergySourceContainer::DoDispose
(
void
)
120
{
121
// call Object::Dispose for all EnergySource objects
122
for
(std::vector<
Ptr<EnergySource>
>::iterator i = m_sources.begin ();
123
i != m_sources.end (); i++)
124
{
125
(*i)->DisposeDeviceModels ();
126
(*i)->Dispose ();
127
}
128
m_sources.clear ();
129
}
130
131
void
132
EnergySourceContainer::DoInitialize
(
void
)
133
{
134
// call Object::Start for all EnergySource objects
135
for
(std::vector<
Ptr<EnergySource>
>::iterator i = m_sources.begin ();
136
i != m_sources.end (); i++)
137
{
138
(*i)->Initialize ();
139
(*i)->InitializeDeviceModels ();
140
}
141
}
142
143
}
// namespace ns3
ns3::Ptr
smart pointer class similar to boost::intrusive_ptr
Definition:
ptr.h:59
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:91
ns3::EnergySourceContainer::GetN
uint32_t GetN(void) const
Get the number of Ptr<EnergySource> stored in this container.
Definition:
energy-source-container.cc:79
NS_ASSERT
#define NS_ASSERT(condition)
Definition:
assert.h:64
ns3::EnergySourceContainer::DoDispose
virtual void DoDispose(void)
Definition:
energy-source-container.cc:119
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:73
ns3::EnergySourceContainer::Get
Ptr< EnergySource > Get(uint32_t i) const
Get the i-th Ptr<EnergySource> stored in this container.
Definition:
energy-source-container.cc:85
ns3::EnergySourceContainer::EnergySourceContainer
EnergySourceContainer()
Definition:
energy-source-container.cc:38
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:67
ns3::EnergySourceContainer::DoInitialize
virtual void DoInitialize(void)
Calls Object::Start () for all EnergySource objects.
Definition:
energy-source-container.cc:132
src
energy
helper
energy-source-container.cc
Generated on Sun Mar 16 2014 11:25:03 for ns-3 by
1.8.6