A Discrete-Event Network Simulator
API
propagation-cache.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2012 Telum (www.telum.ru)
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  * Author: Kirill Andreev <andreev@telum.ru>
18  */
19 #ifndef PROPAGATION_CACHE_H_
20 #define PROPAGATION_CACHE_H_
21 
22 #include "ns3/mobility-model.h"
23 
24 #include <map>
25 
26 namespace ns3
27 {
34 template <class T>
36 {
37  public:
40 
49  {
51  auto it = m_pathCache.find(key);
52  if (it == m_pathCache.end())
53  {
54  return nullptr;
55  }
56  return it->second;
57  }
58 
69  uint32_t modelUid)
70  {
72  NS_ASSERT(m_pathCache.find(key) == m_pathCache.end());
73  m_pathCache.insert(std::make_pair(key, data));
74  }
75 
79  void Cleanup()
80  {
81  for (auto i : m_pathCache)
82  {
83  i.second->Dispose();
84  }
85  m_pathCache.clear();
86  }
87 
88  private:
91  {
100  uint32_t modelUid)
101  : m_srcMobility(a),
102  m_dstMobility(b),
103  m_spectrumModelUid(modelUid){};
107 
120  bool operator<(const PropagationPathIdentifier& other) const
121  {
123  {
124  return m_spectrumModelUid < other.m_spectrumModelUid;
125  }
128  std::min(other.m_dstMobility, other.m_srcMobility))
129  {
131  std::min(other.m_dstMobility, other.m_srcMobility);
132  }
134  std::max(other.m_dstMobility, other.m_srcMobility))
135  {
137  std::max(other.m_dstMobility, other.m_srcMobility);
138  }
139  return false;
140  }
141  };
142 
144  typedef std::map<PropagationPathIdentifier, Ptr<T>> PathCache;
145 
146  private:
148 };
149 } // namespace ns3
150 
151 #endif // PROPAGATION_CACHE_H_
#define min(a, b)
Definition: 80211b.c:41
#define max(a, b)
Definition: 80211b.c:42
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.
void AddPathData(Ptr< T > data, Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Add a model to the path.
Ptr< T > GetPathData(Ptr< const MobilityModel > a, Ptr< const MobilityModel > b, uint32_t modelUid)
Get the model associated with the path.
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
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.