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"
27
34namespace ns3 {
35
41
47template <typename T, typename U>
49MakeObjectVectorAccessor (U T::*memberVariable);
50
51// Documentation generated by print-introspected-doxygen.cc
52template <typename T>
55
60template <typename T, typename U, typename INDEX>
62MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
63 INDEX (T::*getN)(void) const);
64
69template <typename T, typename U, typename INDEX>
71MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
72 Ptr<U> (T::*get)(INDEX) const);
73
74
75/***************************************************************
76 * Implementation of the templates declared above.
77 ***************************************************************/
78
79template <typename T, typename U>
81MakeObjectVectorAccessor (U T::*memberVector)
82{
83 struct MemberStdContainer : public ObjectPtrContainerAccessor
84 {
85 virtual bool DoGetN (const ObjectBase *object, std::size_t *n) const
86 {
87 const T *obj = dynamic_cast<const T *> (object);
88 if (obj == 0)
89 {
90 return false;
91 }
92 *n = (obj->*m_memberVector).size ();
93 return true;
94 }
95 virtual Ptr<Object> DoGet (const ObjectBase *object, std::size_t i, std::size_t *index) const
96 {
97 const T *obj = static_cast<const T *> (object);
98 typename U::const_iterator begin = (obj->*m_memberVector).begin ();
99 typename U::const_iterator end = (obj->*m_memberVector).end ();
100 std::size_t k = 0;
101 for (typename U::const_iterator j = begin; j != end; j++, k++)
102 {
103 if (k == i)
104 {
105 *index = k;
106 return *j;
107 break;
108 }
109 }
110 NS_ASSERT (false);
111 // quiet compiler.
112 return 0;
113 }
114 U T::*m_memberVector;
115 } *spec = new MemberStdContainer ();
116 spec->m_memberVector = memberVector;
117 return Ptr<const AttributeAccessor> (spec, false);
118}
119
120template <typename T>
122{
123 return MakeObjectPtrContainerChecker<T> ();
124}
125
126template <typename T, typename U, typename INDEX>
127Ptr<const AttributeAccessor>
128MakeObjectVectorAccessor (Ptr<U> (T::*get)(INDEX) const,
129 INDEX (T::*getN)(void) const)
130{
131 return MakeObjectPtrContainerAccessor<T,U,INDEX> (get, getN);
132}
133
134template <typename T, typename U, typename INDEX>
135Ptr<const AttributeAccessor>
136MakeObjectVectorAccessor (INDEX (T::*getN)(void) const,
137 Ptr<U> (T::*get)(INDEX) const)
138{
139 return MakeObjectPtrContainerAccessor<T,U,INDEX> (get, getN);
140}
141
142
143
144} // namespace ns3
145
146#endif /* OBJECT_VECTOR_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
Ptr< const AttributeChecker > MakeObjectVectorChecker(void)
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Definition: object-vector.h:40
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:81
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.