A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
object-map.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA, Mathieu Lacage
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Mathieu Lacage <mathieu.lacage@gmail.com>
7 */
8#ifndef OBJECT_MAP_H
9#define OBJECT_MAP_H
10
11#include "attribute.h"
13#include "object.h"
14#include "ptr.h"
15
16/**
17 * @file
18 * @ingroup attribute_ObjectMap
19 * ns3::ObjectMap attribute value declarations and template implementations.
20 */
21
22namespace ns3
23{
24
25/**
26 * @ingroup attribute_ObjectMap
27 * ObjectMapValue is an alias for ObjectPtrContainerValue
28 */
30
31/**
32 * @ingroup attribute_ObjectMap
33 * MakeAccessorHelper implementation for ObjectVector.
34 * @copydetails ns3::DoMakeAccessorHelperOne(U T::*)
35 */
36template <typename T, typename U>
38
39// Documentation generated by print-introspected-doxygen.cc
40template <typename T>
42
43/**
44 * @ingroup attribute_ObjectMap
45 * @copydoc ns3::MakeObjectPtrContainerAccessor()
46 */
47template <typename T, typename U, typename INDEX>
49 INDEX (T::*getN)() const);
50
51/**
52 * @ingroup attribute_ObjectMap
53 * @copydoc ns3::MakeObjectPtrContainerAccessor()
54 */
55template <typename T, typename U, typename INDEX>
57 Ptr<U> (T::*get)(INDEX) const);
58
59/***************************************************************
60 * Implementation of the templates declared above.
61 ***************************************************************/
62
63template <typename T, typename U>
65MakeObjectMapAccessor(U T::*memberVector)
66{
67 struct MemberStdContainer : public ObjectPtrContainerAccessor
68 {
69 bool DoGetN(const ObjectBase* object, std::size_t* n) const override
70 {
71 const T* obj = dynamic_cast<const T*>(object);
72 if (obj == nullptr)
73 {
74 return false;
75 }
76 *n = (obj->*m_memberVector).size();
77 return true;
78 }
79
80 Ptr<Object> DoGet(const ObjectBase* object,
81 std::size_t i,
82 std::size_t* index) const override
83 {
84 const T* obj = static_cast<const T*>(object);
85 auto begin = (obj->*m_memberVector).begin();
86 auto end = (obj->*m_memberVector).end();
87 uint32_t k = 0;
88 for (auto j = begin; j != end; j++, k++)
89 {
90 if (k == i)
91 {
92 *index = (*j).first;
93 return (*j).second;
94 }
95 }
96 NS_ASSERT(false);
97 // quiet compiler.
98 return nullptr;
99 }
100
101 U T::*m_memberVector;
102 }* spec = new MemberStdContainer();
103
104 spec->m_memberVector = memberVector;
105 return Ptr<const AttributeAccessor>(spec, false);
106}
107
108template <typename T>
109Ptr<const AttributeChecker>
114
115template <typename T, typename U, typename INDEX>
116Ptr<const AttributeAccessor>
117MakeObjectMapAccessor(Ptr<U> (T::*get)(INDEX) const, INDEX (T::*getN)() const)
118{
120}
121
122template <typename T, typename U, typename INDEX>
123Ptr<const AttributeAccessor>
124MakeObjectMapAccessor(INDEX (T::*getN)() const, Ptr<U> (T::*get)(INDEX) const)
125{
127}
128
129} // namespace ns3
130
131#endif /* OBJECT_MAP_H */
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Anchor the ns-3 type and attribute system.
AttributeAccessor implementation for ObjectPtrContainerValue.
Container for a set of ns3::Object pointers.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
ObjectPtrContainerValue ObjectMapValue
ObjectMapValue is an alias for ObjectPtrContainerValue.
Definition object-map.h:29
Ptr< const AttributeAccessor > MakeObjectMapAccessor(U T::*memberVariable)
MakeAccessorHelper implementation for ObjectVector.
Definition object-map.h:65
Ptr< const AttributeChecker > MakeObjectMapChecker()
Definition object-map.h:110
Ptr< const AttributeAccessor > MakeObjectPtrContainerAccessor(Ptr< U >(T::*get)(INDEX) const, INDEX(T::*getN)() const)
Create an AttributeAccessor using a container class indexed get method.
Ptr< const AttributeChecker > MakeObjectPtrContainerChecker()
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.