A Discrete-Event Network Simulator
API
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 
36  : m_value ()
37 {
38  NS_LOG_FUNCTION (this);
39 }
40 
42  : m_value (object)
43 {
44  NS_LOG_FUNCTION (object);
45 }
46 
47 void
49 {
50  NS_LOG_FUNCTION (object);
51  m_value = object;
52 }
53 
56 {
57  NS_LOG_FUNCTION (this);
58  return m_value;
59 }
60 
62 PointerValue::Copy (void) const
63 {
64  NS_LOG_FUNCTION (this);
65  return Create<PointerValue> (*this);
66 }
67 std::string
69 {
70  NS_LOG_FUNCTION (this << checker);
71  std::ostringstream oss;
72  oss << m_value;
73  return oss.str ();
74 }
75 
76 bool
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
Instantiate subclasses of ns3::Object.
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
A base class which provides memory management and object aggregation.
Definition: object.h:88
Ptr< Object > m_value
The stored Pointer instance.
Definition: pointer.h:93
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition: pointer.cc:68
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition: pointer.cc:77
virtual Ptr< AttributeValue > Copy(void) const
Definition: pointer.cc:62
void SetObject(Ptr< Object > object)
Set the value from by reference an Object.
Definition: pointer.cc:48
Ptr< Object > GetObject(void) const
Get the Object referenced by the PointerValue.
Definition: pointer.cc:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#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.