A Discrete-Event Network Simulator
API
object-map.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_MAP_H
20 #define OBJECT_MAP_H
21 
22 #include "attribute.h"
23 #include "object-ptr-container.h"
24 #include "object.h"
25 #include "ptr.h"
26 
33 namespace ns3
34 {
35 
41 
47 template <typename T, typename U>
49 
50 // Documentation generated by print-introspected-doxygen.cc
51 template <typename T>
53 
58 template <typename T, typename U, typename INDEX>
60  INDEX (T::*getN)() const);
61 
66 template <typename T, typename U, typename INDEX>
68  Ptr<U> (T::*get)(INDEX) const);
69 
70 /***************************************************************
71  * Implementation of the templates declared above.
72  ***************************************************************/
73 
74 template <typename T, typename U>
76 MakeObjectMapAccessor(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  auto begin = (obj->*m_memberVector).begin();
97  auto end = (obj->*m_memberVector).end();
98  uint32_t k = 0;
99  for (auto j = begin; j != end; j++, k++)
100  {
101  if (k == i)
102  {
103  *index = (*j).first;
104  return (*j).second;
105  }
106  }
107  NS_ASSERT(false);
108  // quiet compiler.
109  return nullptr;
110  }
111 
112  U T::*m_memberVector;
113  }* spec = new MemberStdContainer();
114 
115  spec->m_memberVector = memberVector;
116  return Ptr<const AttributeAccessor>(spec, false);
117 }
118 
119 template <typename T>
120 Ptr<const AttributeChecker>
122 {
123  return MakeObjectPtrContainerChecker<T>();
124 }
125 
126 template <typename T, typename U, typename INDEX>
127 Ptr<const AttributeAccessor>
128 MakeObjectMapAccessor(Ptr<U> (T::*get)(INDEX) const, INDEX (T::*getN)() const)
129 {
130  return MakeObjectPtrContainerAccessor<T, U, INDEX>(get, getN);
131 }
132 
133 template <typename T, typename U, typename INDEX>
134 Ptr<const AttributeAccessor>
135 MakeObjectMapAccessor(INDEX (T::*getN)() const, Ptr<U> (T::*get)(INDEX) const)
136 {
137  return MakeObjectPtrContainerAccessor<T, U, INDEX>(get, getN);
138 }
139 
140 } // namespace ns3
141 
142 #endif /* OBJECT_MAP_H */
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Anchor the ns-3 type and attribute system.
Definition: object-base.h:173
AttributeAccessor implementation for ObjectPtrContainerValue.
Container for a set of ns3::Object pointers.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#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
auto get(const nlohmann::detail::iteration_proxy_value< IteratorType > &i) -> decltype(i.key())
Definition: json.h:4023
Every class exported by the ns3 library is enclosed in the ns3 namespace.
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:76
Ptr< const AttributeChecker > MakeObjectMapChecker()
Definition: object-map.h:121
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.