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 <sstream>
23 
24 namespace ns3 {
25 
27  : m_value ()
28 {
29 }
30 
32  : m_value (object)
33 {
34 }
35 
36 void
38 {
39  m_value = object;
40 }
41 
44 {
45  return m_value;
46 }
47 
49 PointerValue::Copy (void) const
50 {
51  return Create<PointerValue> (*this);
52 }
53 std::string
55 {
56  std::ostringstream oss;
57  oss << m_value;
58  return oss.str ();
59 }
60 
61 bool
63 {
64  // We assume that the string you want to deserialize contains
65  // a description for an ObjectFactory to create an object and then assign it to the
66  // member variable.
67  ObjectFactory factory;
68  std::istringstream iss;
69  iss.str(value);
70  iss >> factory;
71  if (iss.fail())
72  {
73  return false;
74  }
75  m_value = factory.Create<Object> ();
76  return true;
77 }
78 
79 } // namespace ns3