A Discrete-Event Network Simulator
API
object-vector.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_VECTOR_H
21 #define OBJECT_VECTOR_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 MakeObjectVectorAccessor (U T::*memberVariable);
50 
51 // Documentation generated by print-introspected-doxygen.cc
52 template <typename T>
55 
60 template <typename T, typename U, typename INDEX>
62 MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
63  INDEX (T::*getN)(void) const);
64 
69 template <typename T, typename U, typename INDEX>
71 MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
72  Ptr<U> (T::*get)(INDEX) const);
73 
74 
75 /***************************************************************
76  * Implementation of the templates declared above.
77  ***************************************************************/
78 
79 template <typename T, typename U>
81 MakeObjectVectorAccessor (U T::*memberVector)
82 {
83  struct MemberStdContainer : public ObjectPtrContainerAccessor
84  {
85  virtual bool DoGetN(const ObjectBase *object, std::size_t *n) const {
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  const T *obj = static_cast<const T *> (object);
96  typename U::const_iterator begin = (obj->*m_memberVector).begin ();
97  typename U::const_iterator end = (obj->*m_memberVector).end ();
98  std::size_t k = 0;
99  for (typename U::const_iterator j = begin; j != end; j++, k++)
100  {
101  if (k == i)
102  {
103  *index = k;
104  return *j;
105  break;
106  }
107  }
108  NS_ASSERT (false);
109  // quiet compiler.
110  return 0;
111  }
112  U T::*m_memberVector;
113  } *spec = new MemberStdContainer ();
114  spec->m_memberVector = memberVector;
115  return Ptr<const AttributeAccessor> (spec, false);
116 }
117 
118 template <typename T>
120 {
121  return MakeObjectPtrContainerChecker<T> ();
122 }
123 
124 template <typename T, typename U, typename INDEX>
125 Ptr<const AttributeAccessor>
126 MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
127  INDEX (T::*getN)(void) const)
128 {
129  return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
130 }
131 
132 template <typename T, typename U, typename INDEX>
133 Ptr<const AttributeAccessor>
134 MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
135  Ptr<U> (T::*get)(INDEX) const)
136 {
137  return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
138 }
139 
140 
141 
142 } // namespace ns3
143 
144 #endif /* OBJECT_VECTOR_H */
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
ns3::Ptr smart pointer declaration and implementation.
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
#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
Ptr< const AttributeChecker > MakeObjectVectorChecker(void)
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.
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Definition: object-vector.h:40
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.
Container for a set of ns3::Object pointers.