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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#include "pointer.h"
9
10#include "log.h"
11#include "object-factory.h"
12
13#include <sstream>
14
15/**
16 * @file
17 * @ingroup attribute_Pointer
18 * ns3::PointerValue attribute value implementations.
19 */
20
21namespace ns3
22{
23
25
27 : m_value()
28{
29 NS_LOG_FUNCTION(this);
30}
31
33 : m_value(object)
34{
35 NS_LOG_FUNCTION(object);
36}
37
38void
44
47{
48 NS_LOG_FUNCTION(this);
49 return m_value;
50}
51
54{
55 NS_LOG_FUNCTION(this);
56 return Create<PointerValue>(*this);
57}
58
59std::string
61{
62 NS_LOG_FUNCTION(this << checker);
63 std::ostringstream oss;
64 oss << m_value;
65 return oss.str();
66}
67
68bool
70{
71 // We assume that the string you want to deserialize contains
72 // a description for an ObjectFactory to create an object and then assign it to the
73 // member variable.
74 NS_LOG_FUNCTION(this << value << checker);
75 ObjectFactory factory;
76 std::istringstream iss;
77 iss.str(value);
78 iss >> factory;
79 if (iss.fail())
80 {
81 return false;
82 }
83 m_value = factory.Create<Object>();
84 return true;
85}
86
87} // 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:78
std::string SerializeToString(Ptr< const AttributeChecker > checker) const override
Definition pointer.cc:60
Ptr< AttributeValue > Copy() const override
Definition pointer.cc:53
Ptr< Object > GetObject() const
Get the Object referenced by the PointerValue.
Definition pointer.cc:46
Ptr< Object > m_value
The stored Pointer instance.
Definition pointer.h:105
bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker) override
Definition pointer.cc:69
void SetObject(Ptr< Object > object)
Set the value from by reference an Object.
Definition pointer.cc:39
Smart pointer class similar to boost::intrusive_ptr.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
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.