A Discrete-Event Network Simulator
API
object-ptr-container.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 INRIA, Mathieu Lacage
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@gmail.com>
19  */
20 #include "object-ptr-container.h"
21 #include "log.h"
22 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("ObjectPtrContainer");
32 
34 {
35  NS_LOG_FUNCTION (this);
36 }
37 
40 {
41  NS_LOG_FUNCTION (this);
42  return m_objects.begin ();
43 }
46 {
47  NS_LOG_FUNCTION (this);
48  return m_objects.end ();
49 }
50 std::size_t
52 {
53  NS_LOG_FUNCTION (this);
54  return m_objects.size ();
55 }
57 ObjectPtrContainerValue::Get (std::size_t i) const
58 {
59  NS_LOG_FUNCTION (this << i);
60  Iterator it = m_objects.find (i);
61  Ptr<Object> value = 0;
62  if ( it != m_objects.end () )
63  {
64  value = m_objects.find (i)->second;
65  }
66  return value;
67 }
68 
71 {
72  NS_LOG_FUNCTION (this);
73  return ns3::Create<ObjectPtrContainerValue> (*this);
74 }
75 std::string
77 {
78  NS_LOG_FUNCTION (this << checker);
79  std::ostringstream oss;
80  Iterator it;
81  for (it = Begin (); it != End (); ++it)
82  {
83  oss << (*it).second;
84  if (it != End ())
85  {
86  oss << " ";
87  }
88  }
89  return oss.str ();
90 }
91 bool
93 {
94  NS_LOG_FUNCTION (this << value << checker);
95  NS_FATAL_ERROR ("cannot deserialize a set of object pointers.");
96  return true;
97 }
98 
99 bool
101 {
102  // not allowed.
103  NS_LOG_FUNCTION (this << object << &value);
104  return false;
105 }
106 bool
108 {
109  NS_LOG_FUNCTION (this << object << &value);
110  ObjectPtrContainerValue *v = dynamic_cast<ObjectPtrContainerValue *> (&value);
111  if (v == 0)
112  {
113  return false;
114  }
115  v->m_objects.clear ();
116  std::size_t n;
117  bool ok = DoGetN (object, &n);
118  if (!ok)
119  {
120  return false;
121  }
122  for (std::size_t i = 0; i < n; i++)
123  {
124  std::size_t index;
125  Ptr<Object> o = DoGet (object, i, &index);
126  v->m_objects[index] = o;
127  }
128  return true;
129 }
130 bool
132 {
133  NS_LOG_FUNCTION (this);
134  return true;
135 }
136 bool
138 {
139  NS_LOG_FUNCTION (this);
140  return false;
141 }
142 
143 } // name
ObjectPtrContainerValue()
Default constructor.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Hold a value for an Attribute.
Definition: attribute.h:68
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:162
Anchor the ns-3 type and attribute system.
Definition: object-base.h:119
ns3::ObjectPtrContainerValue attribute value declarations and template implementations.
Iterator Begin(void) const
Get an iterator to the first Object.
std::map< std::size_t, Ptr< Object > >::const_iterator Iterator
Iterator type for traversing this container.
std::map< std::size_t, Ptr< Object > > m_objects
The container implementation.
Iterator End(void) const
Get an iterator to the past-the-end Object.
std::size_t GetN(void) const
Get the number of Objects.
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Serialize each of the Object pointers to a string.
virtual bool DoGetN(const ObjectBase *object, std::size_t *n) const =0
Get the number of instances in the container.
virtual bool Get(const ObjectBase *object, AttributeValue &value) const
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Deserialize from a string.
virtual Ptr< Object > DoGet(const ObjectBase *object, std::size_t i, std::size_t *index) const =0
Get an instance from the container, identified by index.
virtual bool HasSetter(void) const
Container for a set of ns3::Object pointers.
Debug message logging.
Ptr< Object > Get(std::size_t i) const
Get a specific Object.
virtual bool Set(ObjectBase *object, const AttributeValue &value) const
virtual bool HasGetter(void) const
virtual Ptr< AttributeValue > Copy(void) const
Get a copy of this container.