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 
22 namespace ns3 {
23 
25 {
26 }
27 
30 {
31  return m_objects.begin ();
32 }
35 {
36  return m_objects.end ();
37 }
38 uint32_t
40 {
41  return m_objects.size ();
42 }
44 ObjectPtrContainerValue::Get (uint32_t i) const
45 {
46  Iterator it = m_objects.find (i);
47  Ptr<Object> value = 0;
48  if ( it != m_objects.end () )
49  {
50  value = m_objects.find (i)->second;
51  }
52  return value;
53 }
54 
57 {
58  return ns3::Create<ObjectPtrContainerValue> (*this);
59 }
60 std::string
62 {
63  std::ostringstream oss;
64  Iterator it;
65  for (it = Begin (); it != End (); ++it)
66  {
67  oss << (*it).second;
68  if (it != End ())
69  {
70  oss << " ";
71  }
72  }
73  return oss.str ();
74 }
75 bool
77 {
78  NS_FATAL_ERROR ("cannot deserialize a set of object pointers.");
79  return true;
80 }
81 
82 bool
84 {
85  // not allowed.
86  return false;
87 }
88 bool
90 {
91  ObjectPtrContainerValue *v = dynamic_cast<ObjectPtrContainerValue *> (&value);
92  if (v == 0)
93  {
94  return false;
95  }
96  v->m_objects.clear ();
97  uint32_t n;
98  bool ok = DoGetN (object, &n);
99  if (!ok)
100  {
101  return false;
102  }
103  for (uint32_t i = 0; i < n; i++)
104  {
105  uint32_t index;
106  Ptr<Object> o = DoGet (object, i, &index);
107  v->m_objects.insert (std::pair <uint32_t, Ptr<Object> > (index, o));
108  }
109  return true;
110 }
111 bool
113 {
114  return true;
115 }
116 bool
118 {
119  return false;
120 }
121 
122 } // name