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:
28 {
29 }
30
32 {
33 }
34
35 /**
36 * Get the model associated with the path
37 * @param a 1st node mobility model
38 * @param b 2nd node mobility model
39 * @param modelUid model UID
40 * @return the model
41 */
43 {
45 auto it = m_pathCache.find(key);
46 if (it == m_pathCache.end())
47 {
48 return nullptr;
49 }
50 return it->second;
51 }
52
53 /**
54 * Add a model to the path
55 * @param data the model to associate to the path
56 * @param a 1st node mobility model
57 * @param b 2nd node mobility model
58 * @param modelUid model UID
59 */
63 uint32_t modelUid)
64 {
66 NS_ASSERT(m_pathCache.find(key) == m_pathCache.end());
67 m_pathCache.insert(std::make_pair(key, data));
68 }
69
70 /**
71 * Clean the cache
72 */
73 void Cleanup()
74 {
75 for (auto i : m_pathCache)
76 {
77 i.second->Dispose();
78 }
79 m_pathCache.clear();
80 }
81
82 private:
83 /// Each path is identified by
85 {
86 /**
87 * Constructor
88 * @param a 1st node mobility model
89 * @param b 2nd node mobility model
90 * @param modelUid model UID
91 */
100
101 Ptr<const MobilityModel> m_srcMobility; //!< 1st node mobility model
102 Ptr<const MobilityModel> m_dstMobility; //!< 2nd node mobility model
104
105 /**
106 * Less-than operator.
107 *
108 * The goal of this operator is just to provide a stable comparison
109 * to be used in containers requiring a order (of any kind).
110 *
111 * If the models are different, the comparison is based on their Uid.
112 * Otherwise, the comparison is based on the pointers of the Mobility models.
113 *
114 * @param other Right value of the operator.
115 * @returns True if the Left value is less than the Right value.
116 */
117 bool operator<(const PropagationPathIdentifier& other) const
118 {
120 {
122 }
123 /// Links are supposed to be symmetrical!
124 if (std::min(m_dstMobility, m_srcMobility) !=
125 std::min(other.m_dstMobility, other.m_srcMobility))
126 {
127 return std::min(m_dstMobility, m_srcMobility) <
128 std::min(other.m_dstMobility, other.m_srcMobility);
129 }
130 if (std::max(m_dstMobility, m_srcMobility) !=
131 std::max(other.m_dstMobility, other.m_srcMobility))
132 {
133 return std::max(m_dstMobility, m_srcMobility) <
134 std::max(other.m_dstMobility, other.m_srcMobility);
135 }
136 return false;
137 }
138 };
139
140 /// Typedef: PropagationPathIdentifier, Ptr<T>
141 typedef std::map<PropagationPathIdentifier, Ptr<T>> PathCache;
142
143 private:
144 PathCache m_pathCache; //!< Path cache
145};
146} // namespace ns3
147
148#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.