A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
pointer.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#include "pointer.h"
20
21#include "log.h"
22#include "object-factory.h"
23
24#include <sstream>
25
32namespace ns3
33{
34
36
38 : m_value()
39{
40 NS_LOG_FUNCTION(this);
41}
42
44 : m_value(object)
45{
46 NS_LOG_FUNCTION(object);
47}
48
49void
51{
52 NS_LOG_FUNCTION(object);
54}
55
58{
59 NS_LOG_FUNCTION(this);
60 return m_value;
61}
62
65{
66 NS_LOG_FUNCTION(this);
67 return Create<PointerValue>(*this);
68}
69
70std::string
72{
73 NS_LOG_FUNCTION(this << checker);
74 std::ostringstream oss;
75 oss << m_value;
76 return oss.str();
77}
78
79bool
81{
82 // We assume that the string you want to deserialize contains
83 // a description for an ObjectFactory to create an object and then assign it to the
84 // member variable.
85 NS_LOG_FUNCTION(this << value << checker);
86 ObjectFactory factory;
87 std::istringstream iss;
88 iss.str(value);
89 iss >> factory;
90 if (iss.fail())
91 {
92 return false;
93 }
94 m_value = factory.Create<Object>();
95 return true;
96}
97
98} // namespace ns3
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
A base class which provides memory management and object aggregation.
Definition: object.h:89
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Definition: pointer.cc:71
Ptr< Object > m_value
The stored Pointer instance.
Definition: pointer.h:93
Ptr< AttributeValue > Copy() const override
Definition: pointer.cc:64
Ptr< Object > GetObject() const
Get the Object referenced by the PointerValue.
Definition: pointer.cc:57
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Definition: pointer.cc:80
void SetObject(Ptr< Object > object)
Set the value from by reference an Object.
Definition: pointer.cc:50
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ObjectFactory class declaration.
ns3::PointerValue attribute value declarations and template implementations.