A Discrete-Event Network Simulator
API
object-map.h
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#ifndef OBJECT_MAP_H
21#define OBJECT_MAP_H
22
23#include "object.h"
24#include "ptr.h"
25#include "attribute.h"
27
34namespace ns3 {
35
41
47template <typename T, typename U>
49MakeObjectMapAccessor (U T::*memberVariable);
50
51// Documentation generated by print-introspected-doxygen.cc
52template <typename T>
54
59template <typename T, typename U, typename INDEX>
61MakeObjectMapAccessor (Ptr<U> (T::*get)(INDEX) const,
62 INDEX (T::*getN)(void) const);
63
68template <typename T, typename U, typename INDEX>
70MakeObjectMapAccessor (INDEX (T::*getN)(void) const,
71 Ptr<U> (T::*get)(INDEX) const);
72
73
74/***************************************************************
75 * Implementation of the templates declared above.
76 ***************************************************************/
77
78template <typename T, typename U>
80MakeObjectMapAccessor (U T::*memberVector)
81{
82 struct MemberStdContainer : public ObjectPtrContainerAccessor
83 {
84 virtual bool DoGetN (const ObjectBase *object, std::size_t *n) const
85 {
86 const T *obj = dynamic_cast<const T *> (object);
87 if (obj == 0)
88 {
89 return false;
90 }
91 *n = (obj->*m_memberVector).size ();
92 return true;
93 }
94 virtual Ptr<Object> DoGet (const ObjectBase *object, std::size_t i, std::size_t *index) const
95 {
96 const T *obj = static_cast<const T *> (object);
97 typename U::const_iterator begin = (obj->*m_memberVector).begin ();
98 typename U::const_iterator end = (obj->*m_memberVector).end ();
99 uint32_t k = 0;
100 for (typename U::const_iterator j = begin; j != end; j++, k++)
101 {
102 if (k == i)
103 {
104 *index = (*j).first;
105 return (*j).second;
106 break;
107 }
108 }
109 NS_ASSERT (false);
110 // quiet compiler.
111 return 0;
112 }
113 U T::*m_memberVector;
114 } *spec = new MemberStdContainer ();
115 spec->m_memberVector = memberVector;
116 return Ptr<const AttributeAccessor> (spec, false);
117}
118
119template <typename T>
121{
122 return MakeObjectPtrContainerChecker<T> ();
123}
124
125template <typename T, typename U, typename INDEX>
126Ptr<const AttributeAccessor>
127MakeObjectMapAccessor (Ptr<U> (T::*get)(INDEX) const,
128 INDEX (T::*getN)(void) const)
129{
130 return MakeObjectPtrContainerAccessor<T,U,INDEX> (get, getN);
131}
132
133template <typename T, typename U, typename INDEX>
134Ptr<const AttributeAccessor>
135MakeObjectMapAccessor (INDEX (T::*getN)(void) const,
136 Ptr<U> (T::*get)(INDEX) const)
137{
138 return MakeObjectPtrContainerAccessor<T,U,INDEX> (get, getN);
139}
140
141} // namespace ns3
142
143#endif /* OBJECT_MAP_H */
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Anchor the ns-3 type and attribute system.
Definition: object-base.h:120
AttributeAccessor implementation for ObjectPtrContainerValue.
Container for a set of ns3::Object pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
ObjectPtrContainerValue ObjectMapValue
ObjectMapValue is an alias for ObjectPtrContainerValue.
Definition: object-map.h:40
Ptr< const AttributeChecker > MakeObjectMapChecker(void)
Definition: object-map.h:120
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-map.h:80
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::ObjectPtrContainerValue attribute value declarations and template implementations.
ns3::Object class declaration, which is the root of the Object hierarchy and Aggregation.
ns3::Ptr smart pointer declaration and implementation.