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
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
pointer.h
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
*
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
* Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19
*/
20
#ifndef NS_POINTER_H
21
#define NS_POINTER_H
22
23
#include "
attribute.h
"
24
#include "
object.h
"
25
26
namespace
ns3 {
27
33
class
PointerValue
:
public
AttributeValue
34
{
35
public
:
36
PointerValue
();
37
38
PointerValue
(
Ptr<Object>
object
);
39
40
void
SetObject
(
Ptr<Object>
object
);
41
42
Ptr<Object>
GetObject
(
void
)
const
;
43
44
template
<
typename
T>
45
PointerValue
(
const
Ptr<T>
&
object
);
46
47
template
<
typename
T>
48
void
Set
(
const
Ptr<T>
&
object
);
49
50
template
<
typename
T>
51
Ptr<T>
Get
(
void
)
const
;
52
53
template
<
typename
T>
54
bool
GetAccessor
(
Ptr<T>
&v)
const
;
55
56
template
<
typename
T>
57
operator
Ptr<T>
()
const
;
58
59
virtual
Ptr<AttributeValue>
Copy
(
void
)
const
;
60
virtual
std::string
SerializeToString
(
Ptr<const AttributeChecker>
checker)
const
;
61
virtual
bool
DeserializeFromString
(std::string value,
Ptr<const AttributeChecker>
checker);
62
63
private
:
64
Ptr<Object>
m_value
;
65
};
66
67
68
class
PointerChecker
:
public
AttributeChecker
69
{
70
public
:
71
virtual
TypeId
GetPointeeTypeId
(
void
)
const
= 0;
72
};
73
template
<
typename
T>
74
Ptr<AttributeChecker>
MakePointerChecker
(
void
);
75
76
}
// namespace ns3
77
78
namespace
ns3 {
79
80
81
namespace
internal {
82
83
template
<
typename
T>
84
class
APointerChecker
:
public
PointerChecker
85
{
86
virtual
bool
Check
(
const
AttributeValue
&val)
const
{
87
const
PointerValue
*value =
dynamic_cast<
const
PointerValue
*
>
(&val);
88
if
(value == 0)
89
{
90
return
false
;
91
}
92
if
(value->
GetObject
() == 0)
93
{
94
return
true
;
95
}
96
T *ptr =
dynamic_cast<
T*
>
(
PeekPointer
(value->
GetObject
()));
97
if
(ptr == 0)
98
{
99
return
false
;
100
}
101
return
true
;
102
}
103
virtual
std::string
GetValueTypeName
(
void
)
const
{
104
return
"ns3::PointerValue"
;
105
}
106
virtual
bool
HasUnderlyingTypeInformation
(
void
)
const
{
107
return
true
;
108
}
109
virtual
std::string
GetUnderlyingTypeInformation
(
void
)
const
{
110
TypeId
tid = T::GetTypeId ();
111
return
"ns3::Ptr< "
+ tid.
GetName
() +
" >"
;
112
}
113
virtual
Ptr<AttributeValue>
Create
(
void
)
const
{
114
return
ns3::Create<PointerValue> ();
115
}
116
virtual
bool
Copy
(
const
AttributeValue
&source,
AttributeValue
&destination)
const
{
117
const
PointerValue
*src =
dynamic_cast<
const
PointerValue
*
>
(&source);
118
PointerValue
*dst =
dynamic_cast<
PointerValue
*
>
(&destination);
119
if
(src == 0 || dst == 0)
120
{
121
return
false
;
122
}
123
*dst = *src;
124
return
true
;
125
}
126
virtual
TypeId
GetPointeeTypeId
(
void
)
const
{
127
return
T::GetTypeId ();
128
}
129
};
130
131
}
// namespace internal
132
133
template
<
typename
T>
134
PointerValue::PointerValue
(
const
Ptr<T>
&
object
)
135
{
136
m_value
= object;
137
}
138
139
template
<
typename
T>
140
void
141
PointerValue::Set
(
const
Ptr<T>
&
object
)
142
{
143
m_value
= object;
144
}
145
146
template
<
typename
T>
147
Ptr<T>
148
PointerValue::Get
(
void
)
const
149
{
150
T *v =
dynamic_cast<
T *
>
(
PeekPointer
(
m_value
));
151
return
v;
152
}
153
154
template
<
typename
T>
155
PointerValue::operator
Ptr<T>
()
const
156
{
157
return
Get<T> ();
158
}
159
160
template
<
typename
T>
161
bool
162
PointerValue::GetAccessor
(
Ptr<T>
&v)
const
163
{
164
Ptr<T>
ptr =
dynamic_cast<
T*
>
(
PeekPointer
(
m_value
));
165
if
(ptr == 0)
166
{
167
return
false
;
168
}
169
v = ptr;
170
return
true
;
171
}
172
173
174
ATTRIBUTE_ACCESSOR_DEFINE
(Pointer);
175
176
template
<
typename
T>
177
Ptr<AttributeChecker>
178
MakePointerChecker
(
void
)
179
{
180
return
Create<internal::APointerChecker<T> > ();
181
}
182
183
184
}
// namespace ns3
185
186
#endif
/* NS_POINTER_H */
ns3::AttributeChecker
Represent the type of an attribute.
Definition:
attribute.h:154
ns3::internal::APointerChecker::HasUnderlyingTypeInformation
virtual bool HasUnderlyingTypeInformation(void) const
Definition:
pointer.h:106
ns3::PointerValue::Get
Ptr< T > Get(void) const
Definition:
pointer.h:148
ns3::Ptr< Object >
ns3::internal::APointerChecker
Definition:
pointer.h:84
ns3::AttributeValue
Hold a value for an Attribute.
Definition:
attribute.h:56
ns3::PointerValue::GetObject
Ptr< Object > GetObject(void) const
Definition:
pointer.cc:49
ns3::PointerChecker::GetPointeeTypeId
virtual TypeId GetPointeeTypeId(void) const =0
ns3::PointerValue::PointerValue
PointerValue()
Definition:
pointer.cc:29
ns3::MakePointerChecker
Ptr< AttributeChecker > MakePointerChecker(void)
Definition:
pointer.h:178
ns3::internal::APointerChecker::Create
virtual Ptr< AttributeValue > Create(void) const
Definition:
pointer.h:113
ns3::PointerValue::m_value
Ptr< Object > m_value
Definition:
pointer.h:64
attribute.h
ns3::PeekPointer
T * PeekPointer(const Ptr< T > &p)
Definition:
ptr.h:279
ns3::PointerValue::GetAccessor
bool GetAccessor(Ptr< T > &v) const
Definition:
pointer.h:162
ns3::ATTRIBUTE_ACCESSOR_DEFINE
ATTRIBUTE_ACCESSOR_DEFINE(Boolean)
ns3::PointerValue::Set
void Set(const Ptr< T > &object)
Definition:
pointer.h:141
ns3::internal::APointerChecker::GetUnderlyingTypeInformation
virtual std::string GetUnderlyingTypeInformation(void) const
Definition:
pointer.h:109
ns3::PointerValue
hold objects of type Ptr
Definition:
pointer.h:33
ns3::TypeId::GetName
std::string GetName(void) const
Definition:
type-id.cc:658
ns3::internal::APointerChecker::GetPointeeTypeId
virtual TypeId GetPointeeTypeId(void) const
Definition:
pointer.h:126
ns3::PointerValue::DeserializeFromString
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition:
pointer.cc:71
ns3::internal::APointerChecker::Copy
virtual bool Copy(const AttributeValue &source, AttributeValue &destination) const
Copy the source to the destination.
Definition:
pointer.h:116
ns3::PointerValue::SetObject
void SetObject(Ptr< Object > object)
Definition:
pointer.cc:42
object.h
ns3::PointerChecker
Definition:
pointer.h:68
ns3::PointerValue::Copy
virtual Ptr< AttributeValue > Copy(void) const
Definition:
pointer.cc:56
ns3::internal::APointerChecker::GetValueTypeName
virtual std::string GetValueTypeName(void) const
Definition:
pointer.h:103
ns3::internal::APointerChecker::Check
virtual bool Check(const AttributeValue &val) const
Definition:
pointer.h:86
ns3::PointerValue::SerializeToString
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition:
pointer.cc:62
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
src
core
model
pointer.h
Generated on Sat Apr 19 2014 14:06:52 for ns-3 by
1.8.6