A Discrete-Event Network Simulator
API
object-vector.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA, Mathieu Lacage
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Authors: Mathieu Lacage <mathieu.lacage@gmail.com>
18 */
19#ifndef OBJECT_VECTOR_H
20#define OBJECT_VECTOR_H
21
22#include "attribute.h"
24#include "object.h"
25#include "ptr.h"
26
33namespace ns3
34{
35
41
47template <typename T, typename U>
49
50// Documentation generated by print-introspected-doxygen.cc
51template <typename T>
53
58template <typename T, typename U, typename INDEX>
60 INDEX (T::*getN)() const);
61
66template <typename T, typename U, typename INDEX>
68 Ptr<U> (T::*get)(INDEX) const);
69
70/***************************************************************
71 * Implementation of the templates declared above.
72 ***************************************************************/
73
74template <typename T, typename U>
76MakeObjectVectorAccessor(U T::*memberVector)
77{
78 struct MemberStdContainer : public ObjectPtrContainerAccessor
79 {
80 bool DoGetN(const ObjectBase* object, std::size_t* n) const override
81 {
82 const T* obj = dynamic_cast<const T*>(object);
83 if (obj == nullptr)
84 {
85 return false;
86 }
87 *n = (obj->*m_memberVector).size();
88 return true;
89 }
90
91 Ptr<Object> DoGet(const ObjectBase* object,
92 std::size_t i,
93 std::size_t* index) const override
94 {
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 nullptr;
111 }
112
113 U T::*m_memberVector;
114 }* spec = new MemberStdContainer();
115
116 spec->m_memberVector = memberVector;
117 return Ptr<const AttributeAccessor>(spec, false);
118}
119
120template <typename T>
121Ptr<const AttributeChecker>
123{
124 return MakeObjectPtrContainerChecker<T>();
125}
126
127template <typename T, typename U, typename INDEX>
128Ptr<const AttributeAccessor>
129MakeObjectVectorAccessor(Ptr<U> (T::*get)(INDEX) const, INDEX (T::*getN)() 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)() const, Ptr<U> (T::*get)(INDEX) const)
137{
138 return MakeObjectPtrContainerAccessor<T, U, INDEX>(get, getN);
139}
140
141} // namespace ns3
142
143#endif /* OBJECT_VECTOR_H */
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Anchor the ns-3 type and attribute system.
Definition: object-base.h:170
AttributeAccessor implementation for ObjectPtrContainerValue.
Container for a set of ns3::Object pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
ObjectPtrContainerValue ObjectVectorValue
ObjectVectorValue is an alias for ObjectPtrContainerValue.
Definition: object-vector.h:40
Ptr< const AttributeChecker > MakeObjectVectorChecker()
Ptr< const AttributeAccessor > MakeObjectVectorAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition: object-vector.h:76
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.