A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
28 namespace ns3 {
29 
31 
32 template <typename T, typename U>
34 MakeObjectVectorAccessor (U T::*memberContainer);
35 
36 template <typename T>
38 
39 template <typename T, typename U, typename INDEX>
41 MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
42  INDEX (T::*getN)(void) const);
43 
44 template <typename T, typename U, typename INDEX>
46 MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
47  Ptr<U> (T::*get)(INDEX) const);
48 
49 template <typename T, typename U>
51 MakeObjectVectorAccessor (U T::*memberVector)
52 {
53  struct MemberStdContainer : public ObjectPtrContainerAccessor
54  {
55  virtual bool DoGetN (const ObjectBase *object, uint32_t *n) const {
56  const T *obj = dynamic_cast<const T *> (object);
57  if (obj == 0)
58  {
59  return false;
60  }
61  *n = (obj->*m_memberVector).size ();
62  return true;
63  }
64  virtual Ptr<Object> DoGet (const ObjectBase *object, uint32_t i, uint32_t *index) const {
65  const T *obj = static_cast<const T *> (object);
66  typename U::const_iterator begin = (obj->*m_memberVector).begin ();
67  typename U::const_iterator end = (obj->*m_memberVector).end ();
68  uint32_t k = 0;
69  for (typename U::const_iterator j = begin; j != end; j++, k++)
70  {
71  if (k == i)
72  {
73  *index = k;
74  return *j;
75  break;
76  }
77  }
78  NS_ASSERT (false);
79  // quiet compiler.
80  return 0;
81  }
82  U T::*m_memberVector;
83  } *spec = new MemberStdContainer ();
84  spec->m_memberVector = memberVector;
85  return Ptr<const AttributeAccessor> (spec, false);
86 }
87 
88 template <typename T>
90 {
91  return MakeObjectPtrContainerChecker<T> ();
92 }
93 
94 template <typename T, typename U, typename INDEX>
95 Ptr<const AttributeAccessor>
96 MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
97  INDEX (T::*getN)(void) const)
98 {
99  return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
100 }
101 
102 template <typename T, typename U, typename INDEX>
103 Ptr<const AttributeAccessor>
104 MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
105  Ptr<U> (T::*get)(INDEX) const)
106 {
107  return MakeObjectPtrContainerAccessor<T,U,INDEX>(get, getN);
108 }
109 
110 
111 
112 } // namespace ns3
113 
114 #endif /* OBJECT_VECTOR_H */
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberContainer)
Definition: object-vector.h:51
smart pointer class similar to boost::intrusive_ptr
Definition: ptr.h:60
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:61
implement the ns-3 type and attribute system
Definition: object-base.h:61
Ptr< const AttributeChecker > MakeObjectVectorChecker(void)
Definition: object-vector.h:89
ObjectPtrContainerValue ObjectVectorValue
Definition: object-vector.h:30
contain a set of ns3::Object pointers.