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 */
36// clang-format off
37// Clang-format guard needed for versions <= 18
38template <typename T, typename U>
40// clang-format on
41
42// Documentation generated by print-introspected-doxygen.cc
43template <typename T>
45
46/**
47 * @ingroup attribute_ObjectMap
48 * @copydoc ns3::MakeObjectPtrContainerAccessor()
49 */
50template <typename T, typename U, typename INDEX>
52 INDEX (T::*getN)() const);
53
54/**
55 * @ingroup attribute_ObjectMap
56 * @copydoc ns3::MakeObjectPtrContainerAccessor()
57 */
58template <typename T, typename U, typename INDEX>
60 Ptr<U> (T::*get)(INDEX) const);
61
62/***************************************************************
63 * Implementation of the templates declared above.
64 ***************************************************************/
65
66// clang-format off
67// Clang-format guard needed for versions <= 18
68template <typename T, typename U>
70MakeObjectMapAccessor(U T::* memberVector)
71// clang-format on
72{
73 struct MemberStdContainer : public ObjectPtrContainerAccessor
74 {
75 bool DoGetN(const ObjectBase* object, std::size_t* n) const override
76 {
77 const T* obj = dynamic_cast<const T*>(object);
78 if (obj == nullptr)
79 {
80 return false;
81 }
82 *n = (obj->*m_memberVector).size();
83 return true;
84 }
85
86 Ptr<Object> DoGet(const ObjectBase* object,
87 std::size_t i,
88 std::size_t* index) const override
89 {
90 const T* obj = static_cast<const T*>(object);
91 auto begin = (obj->*m_memberVector).begin();
92 auto end = (obj->*m_memberVector).end();
93 uint32_t k = 0;
94 for (auto j = begin; j != end; j++, k++)
95 {
96 if (k == i)
97 {
98 *index = (*j).first;
99 return (*j).second;
100 }
101 }
102 NS_ASSERT(false);
103 // quiet compiler.
104 return nullptr;
105 }
106
107 // clang-format off
108 // Clang-format guard needed for versions <= 18
109 U T::* m_memberVector;
110 // clang-format on
111 }* spec = new MemberStdContainer();
112
113 spec->m_memberVector = memberVector;
114 return Ptr<const AttributeAccessor>(spec, false);
115}
116
117template <typename T>
118Ptr<const AttributeChecker>
123
124template <typename T, typename U, typename INDEX>
125Ptr<const AttributeAccessor>
126MakeObjectMapAccessor(Ptr<U> (T::*get)(INDEX) const, INDEX (T::*getN)() const)
127{
129}
130
131template <typename T, typename U, typename INDEX>
132Ptr<const AttributeAccessor>
133MakeObjectMapAccessor(INDEX (T::*getN)() const, Ptr<U> (T::*get)(INDEX) const)
134{
136}
137
138} // namespace ns3
139
140#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:70
Ptr< const AttributeChecker > MakeObjectMapChecker()
Definition object-map.h:119
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.