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