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 */
21#include "log.h"
22
29namespace ns3 {
30
31NS_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}
50std::size_t
52{
53 NS_LOG_FUNCTION (this);
54 return m_objects.size ();
55}
57ObjectPtrContainerValue::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}
75std::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}
91bool
93{
94 NS_LOG_FUNCTION (this << value << checker);
95 NS_FATAL_ERROR ("cannot deserialize a set of object pointers.");
96 return true;
97}
98
99bool
101{
102 // not allowed.
103 NS_LOG_FUNCTION (this << object << &value);
104 return false;
105}
106bool
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}
130bool
132{
133 NS_LOG_FUNCTION (this);
134 return true;
135}
136bool
138{
139 NS_LOG_FUNCTION (this);
140 return false;
141}
142
143} // name
Hold a value for an Attribute.
Definition: attribute.h:69
Anchor the ns-3 type and attribute system.
Definition: object-base.h:120
virtual bool Set(ObjectBase *object, const AttributeValue &value) const
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
virtual bool DoGetN(const ObjectBase *object, std::size_t *n) const =0
Get the number of instances in the container.
virtual bool HasGetter(void) const
virtual bool Get(const ObjectBase *object, AttributeValue &value) const
Container for a set of ns3::Object pointers.
virtual std::string SerializeToString(Ptr< const AttributeChecker > checker) const
Serialize each of the Object pointers to a string.
virtual Ptr< AttributeValue > Copy(void) const
Get a copy of this container.
std::map< std::size_t, Ptr< Object > > m_objects
The container implementation.
std::size_t GetN(void) const
Get the number of Objects.
Iterator Begin(void) const
Get an iterator to the first Object.
ObjectPtrContainerValue()
Default constructor.
virtual bool DeserializeFromString(std::string value, Ptr< const AttributeChecker > checker)
Deserialize from a string.
std::map< std::size_t, Ptr< Object > >::const_iterator Iterator
Iterator type for traversing this container.
Ptr< Object > Get(std::size_t i) const
Get a specific Object.
Iterator End(void) const
Get an iterator to the past-the-end Object.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
Definition: fatal-error.h:165
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Debug message logging.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ObjectPtrContainerValue attribute value declarations and template implementations.