A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
propagation-cache.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2012 Telum (www.telum.ru)
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Kirill Andreev <andreev@telum.ru>
7 */
8#ifndef PROPAGATION_CACHE_H_
9#define PROPAGATION_CACHE_H_
10
11#include "ns3/mobility-model.h"
12
13#include <map>
14
15namespace ns3
16{
17/**
18 * \ingroup propagation
19 * \brief Constructs a cache of objects, where each object is responsible for a single propagation
20 * path loss calculations. Propagation path a-->b and b-->a is the same thing. Propagation path is
21 * identified by a couple of MobilityModels and a spectrum model UID
22 */
23template <class T>
25{
26 public:
29
30 /**
31 * Get the model associated with the path
32 * \param a 1st node mobility model
33 * \param b 2nd node mobility model
34 * \param modelUid model UID
35 * \return the model
36 */
38 {
40 auto it = m_pathCache.find(key);
41 if (it == m_pathCache.end())
42 {
43 return nullptr;
44 }
45 return it->second;
46 }
47
48 /**
49 * Add a model to the path
50 * \param data the model to associate to the path
51 * \param a 1st node mobility model
52 * \param b 2nd node mobility model
53 * \param modelUid model UID
54 */
58 uint32_t modelUid)
59 {
61 NS_ASSERT(m_pathCache.find(key) == m_pathCache.end());
62 m_pathCache.insert(std::make_pair(key, data));
63 }
64
65 /**
66 * Clean the cache
67 */
68 void Cleanup()
69 {
70 for (auto i : m_pathCache)
71 {
72 i.second->Dispose();
73 }
74 m_pathCache.clear();
75 }
76
77 private:
78 /// Each path is identified by
80 {
81 /**
82 * Constructor
83 * @param a 1st node mobility model
84 * @param b 2nd node mobility model
85 * @param modelUid model UID
86 */
93 Ptr<const MobilityModel> m_srcMobility; //!< 1st node mobility model
94 Ptr<const MobilityModel> m_dstMobility; //!< 2nd node mobility model
96
97 /**
98 * Less-than operator.
99 *
100 * The goal of this operator is just to provide a stable comparison
101 * to be used in containers requiring a order (of any kind).
102 *
103 * If the models are different, the comparison is based on their Uid.
104 * Otherwise, the comparison is based on the pointers of the Mobility models.
105 *
106 * \param other Right value of the operator.
107 * \returns True if the Left value is less than the Right value.
108 */
109 bool operator<(const PropagationPathIdentifier& other) const
110 {
112 {
114 }
115 /// Links are supposed to be symmetrical!
116 if (std::min(m_dstMobility, m_srcMobility) !=
117 std::min(other.m_dstMobility, other.m_srcMobility))
118 {
119 return std::min(m_dstMobility, m_srcMobility) <
120 std::min(other.m_dstMobility, other.m_srcMobility);
121 }
122 if (std::max(m_dstMobility, m_srcMobility) !=
123 std::max(other.m_dstMobility, other.m_srcMobility))
124 {
125 return std::max(m_dstMobility, m_srcMobility) <
126 std::max(other.m_dstMobility, other.m_srcMobility);
127 }
128 return false;
129 }
130 };
131
132 /// Typedef: PropagationPathIdentifier, Ptr<T>
133 typedef std::map<PropagationPathIdentifier, Ptr<T>> PathCache;
134
135 private:
136 PathCache m_pathCache; //!< Path cache
137};
138} // namespace ns3
139
140#endif // PROPAGATION_CACHE_H_
Constructs a cache of objects, where each object is responsible for a single propagation path loss ca...
PathCache m_pathCache
Path cache.
std::map< PropagationPathIdentifier, Ptr< T > > PathCache
Typedef: PropagationPathIdentifier, Ptr<T>
void Cleanup()
Clean the cache.
Ptr< T > GetPathData(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Get the model associated with the path.
void AddPathData(Ptr< T > data, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Add a model to the path.
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
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]
PropagationPathIdentifier(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Constructor.
Ptr< const MobilityModel > m_srcMobility
1st node mobility model
Ptr< const MobilityModel > m_dstMobility
2nd node mobility model
bool operator<(const PropagationPathIdentifier &other) const
Less-than operator.