A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
src
core
model
pointer.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
*
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
#include "
pointer.h
"
21
#include "
object-factory.h
"
22
#include "
log.h
"
23
#include <sstream>
24
31
namespace
ns3
{
32
33
NS_LOG_COMPONENT_DEFINE
(
"Pointer"
);
34
35
PointerValue::PointerValue
()
36
: m_value ()
37
{
38
NS_LOG_FUNCTION
(
this
);
39
}
40
41
PointerValue::PointerValue
(
Ptr<Object>
object
)
42
: m_value (object)
43
{
44
NS_LOG_FUNCTION
(
object
);
45
}
46
47
void
48
PointerValue::SetObject
(
Ptr<Object>
object
)
49
{
50
NS_LOG_FUNCTION
(
object
);
51
m_value
= object;
52
}
53
54
Ptr<Object>
55
PointerValue::GetObject
(
void
)
const
56
{
57
NS_LOG_FUNCTION
(
this
);
58
return
m_value
;
59
}
60
61
Ptr<AttributeValue>
62
PointerValue::Copy
(
void
)
const
63
{
64
NS_LOG_FUNCTION
(
this
);
65
return
Create<PointerValue> (*this);
66
}
67
std::string
68
PointerValue::SerializeToString
(
Ptr<const AttributeChecker>
checker)
const
69
{
70
NS_LOG_FUNCTION
(
this
<< checker);
71
std::ostringstream oss;
72
oss <<
m_value
;
73
return
oss.str ();
74
}
75
76
bool
77
PointerValue::DeserializeFromString
(std::string value,
Ptr<const AttributeChecker>
checker)
78
{
79
// We assume that the string you want to deserialize contains
80
// a description for an ObjectFactory to create an object and then assign it to the
81
// member variable.
82
NS_LOG_FUNCTION
(
this
<< value << checker);
83
ObjectFactory
factory;
84
std::istringstream iss;
85
iss.str(value);
86
iss >> factory;
87
if
(iss.fail())
88
{
89
return
false
;
90
}
91
m_value
= factory.Create<
Object
> ();
92
return
true
;
93
}
94
95
}
// namespace ns3
ns3::Ptr< Object >
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Definition:
log-macros-enabled.h:213
ns3::PointerValue::GetObject
Ptr< Object > GetObject(void) const
Get the Object referenced by the PointerValue.
Definition:
pointer.cc:55
object-factory.h
ns3::ObjectFactory class declaration.
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:202
ns3::PointerValue::PointerValue
PointerValue()
Definition:
pointer.cc:35
ns3::PointerValue::m_value
Ptr< Object > m_value
The stored Pointer instance.
Definition:
pointer.h:93
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::PointerValue::DeserializeFromString
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition:
pointer.cc:77
ns3::PointerValue::SetObject
void SetObject(Ptr< Object > object)
Set the value from by reference an Object.
Definition:
pointer.cc:48
ns3::ObjectFactory
Instantiate subclasses of ns3::Object.
Definition:
object-factory.h:47
ns3::PointerValue::SerializeToString
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition:
pointer.cc:68
ns3::Object
A base class which provides memory management and object aggregation.
Definition:
object.h:87
log.h
Debug message logging.
pointer.h
ns3::PointerValue attribute value declarations and template implementations.
ns3::PointerValue::Copy
virtual Ptr< AttributeValue > Copy(void) const
Definition:
pointer.cc:62
Generated on Wed Nov 7 2018 10:01:49 for ns-3 by
1.8.14