A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
25 NS_LOG_COMPONENT_DEFINE ("Pointer");
26 
27 namespace ns3 {
28 
30  : m_value ()
31 {
32  NS_LOG_FUNCTION (this);
33 }
34 
36  : m_value (object)
37 {
38  NS_LOG_FUNCTION (object);
39 }
40 
41 void
43 {
44  NS_LOG_FUNCTION (object);
45  m_value = object;
46 }
47 
50 {
51  NS_LOG_FUNCTION (this);
52  return m_value;
53 }
54 
56 PointerValue::Copy (void) const
57 {
58  NS_LOG_FUNCTION (this);
59  return Create<PointerValue> (*this);
60 }
61 std::string
63 {
64  NS_LOG_FUNCTION (this << checker);
65  std::ostringstream oss;
66  oss << m_value;
67  return oss.str ();
68 }
69 
70 bool
72 {
73  // We assume that the string you want to deserialize contains
74  // a description for an ObjectFactory to create an object and then assign it to the
75  // member variable.
76  NS_LOG_FUNCTION (this << value << checker);
77  ObjectFactory factory;
78  std::istringstream iss;
79  iss.str(value);
80  iss >> factory;
81  if (iss.fail())
82  {
83  return false;
84  }
85  m_value = factory.Create<Object> ();
86  return true;
87 }
88 
89 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Ptr< Object > GetObject(void) const
Definition: pointer.cc:49
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
Ptr< Object > m_value
Definition: pointer.h:64
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Definition: pointer.cc:71
void SetObject(Ptr< Object > object)
Definition: pointer.cc:42
instantiate subclasses of ns3::Object.
virtual Ptr< AttributeValue > Copy(void) const
Definition: pointer.cc:56
a base class which provides memory management and object aggregation
Definition: object.h:64
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Definition: pointer.cc:62