A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
23 NS_LOG_COMPONENT_DEFINE ("ObjectPtrContainer");
24 
25 namespace ns3 {
26 
28 {
29  NS_LOG_FUNCTION (this);
30 }
31 
34 {
35  NS_LOG_FUNCTION (this);
36  return m_objects.begin ();
37 }
40 {
41  NS_LOG_FUNCTION (this);
42  return m_objects.end ();
43 }
44 uint32_t
46 {
47  NS_LOG_FUNCTION (this);
48  return m_objects.size ();
49 }
51 ObjectPtrContainerValue::Get (uint32_t i) const
52 {
53  NS_LOG_FUNCTION (this << i);
54  Iterator it = m_objects.find (i);
55  Ptr<Object> value = 0;
56  if ( it != m_objects.end () )
57  {
58  value = m_objects.find (i)->second;
59  }
60  return value;
61 }
62 
65 {
66  NS_LOG_FUNCTION (this);
67  return ns3::Create<ObjectPtrContainerValue> (*this);
68 }
69 std::string
71 {
72  NS_LOG_FUNCTION (this << checker);
73  std::ostringstream oss;
74  Iterator it;
75  for (it = Begin (); it != End (); ++it)
76  {
77  oss << (*it).second;
78  if (it != End ())
79  {
80  oss << " ";
81  }
82  }
83  return oss.str ();
84 }
85 bool
87 {
88  NS_LOG_FUNCTION (this << value << checker);
89  NS_FATAL_ERROR ("cannot deserialize a set of object pointers.");
90  return true;
91 }
92 
93 bool
95 {
96  // not allowed.
97  NS_LOG_FUNCTION (this << object << &value);
98  return false;
99 }
100 bool
102 {
103  NS_LOG_FUNCTION (this << object << &value);
104  ObjectPtrContainerValue *v = dynamic_cast<ObjectPtrContainerValue *> (&value);
105  if (v == 0)
106  {
107  return false;
108  }
109  v->m_objects.clear ();
110  uint32_t n;
111  bool ok = DoGetN (object, &n);
112  if (!ok)
113  {
114  return false;
115  }
116  for (uint32_t i = 0; i < n; i++)
117  {
118  uint32_t index;
119  Ptr<Object> o = DoGet (object, i, &index);
120  v->m_objects.insert (std::pair <uint32_t, Ptr<Object> > (index, o));
121  }
122  return true;
123 }
124 bool
126 {
127  NS_LOG_FUNCTION (this);
128  return true;
129 }
130 bool
132 {
133  NS_LOG_FUNCTION (this);
134  return false;
135 }
136 
137 } // name
virtual Ptr< AttributeValue > Copy(void) const
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
virtual bool HasSetter(void) const
virtual Ptr< Object > DoGet(const ObjectBase *object, uint32_t i, uint32_t *index) const =0
Hold a value for an Attribute.
Definition: attribute.h:56
implement the ns-3 type and attribute system
Definition: object-base.h:70
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition: fatal-error.h:72
std::map< uint32_t, Ptr< Object > >::const_iterator Iterator
Ptr< Object > Get(uint32_t i) const
virtual bool Set(ObjectBase *object, const AttributeValue &value) const
virtual bool HasGetter(void) const
std::map< uint32_t, Ptr< Object > > m_objects
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
virtual bool DoGetN(const ObjectBase *object, uint32_t *n) const =0
contain a set of ns3::Object pointers.
virtual bool Get(const ObjectBase *object, AttributeValue &value) const
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
NS_LOG_COMPONENT_DEFINE("ObjectPtrContainer")